-
Notifications
You must be signed in to change notification settings - Fork 0
/
headers.c
7085 lines (6379 loc) · 245 KB
/
headers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* readers/writers for various sound file headers
*
* Currently supported read/write (in standard sample types):
* NeXT/Sun/DEC/AFsp
* AIFF/AIFC
* RIFF (microsoft wave)
* RF64 (EBU)
* IRCAM (old style)
* NIST-sphere
* CAFF
* no header
*
* Currently supported read-only (in selected sample types):
* 8SVX (IFF), EBICSF, INRS, ESPS, SPPACK, ADC (OGI), AVR, VOC, CSL, snack "SMP", PVF,
* Sound Tools, Turtle Beach SMP, SoundFont 2.0, Sound Designer I, PSION alaw, MAUD,
* Gravis Ultrasound, Comdisco SPW, Goldwave sample, OMF, quicktime, sox,
* Sonic Foundry (w64), SBStudio II, Delusion digital, Digiplayer ST3, Farandole Composer WaveSample,
* Ultratracker WaveSample, Sample Dump exchange, Yamaha SY85 and SY99 (buggy), Yamaha TX16W,
* Covox v8, AVI, Kurzweil 2000, Paris Ensoniq, Impulse tracker, Korg, Akai type 4, Maui,
*
* for a few of these I'm still trying to get documentation -- best sources of info are:
* ftp.cwi.nl:pub/audio (info files)
* the AFsp sources http://www.TSP.ECE.McGill.CA/MMSP/Documents/AudioFormats/index.html
* the SOX sources
* svr-ftp.eng.cam.ac.uk:/comp.speech/tools
* http://www.wotsit.org
* CAFF: http://developer.apple.com/documentation/MusicAudio/Reference/CAFSpec/
* and afconvert can be found in /Developer/Examples/CoreAudio/Services/AudioFileTools/
* RIFF: Microsoft Multimedia Programmer's Reference Manual at ftp.microsoft.com:/SoftLib/MSLFILES/MDRK.EXE
* AVI: http://www.rahul.net/jfm/avi.html
* EBU RF64: http://www.ebu.ch/CMSimages/en/tec_doc_t3306_tcm6-42570.pdf
* Sound Designer: "Developer Documentation" from Digidesign
*
* test cases (sample files): ccrma-ftp.stanford.edu:/pub/Lisp/sf.tar.gz
*/
#include "mus-config.h"
#if USE_SND
#include "snd.h"
#endif
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifndef _MSC_VER
#include <unistd.h>
#else
#include <io.h>
#pragma warning(disable: 4244)
#endif
#include "_sndlib.h"
#include "sndlib-strings.h"
/* can't use LONG_MAX here because we want a 4-byte max even on 64-bit machines */
#define BIGGEST_4_BYTE_SIGNED_INT 2147483647L
#define BIGGEST_4_BYTE_UNSIGNED_INT 4294967295UL
static const unsigned char I_DSND[4] = {'.','s','n','d'}; /* NeXT/Sun/Dec/SGI/AFsp first word */
static const unsigned char I_FORM[4] = {'F','O','R','M'}; /* AIFF first word */
static const unsigned char I_AIFF[4] = {'A','I','F','F'}; /* AIFF second word */
static const unsigned char I_AIFC[4] = {'A','I','F','C'}; /* ditto but might be compressed data */
static const unsigned char I_COMM[4] = {'C','O','M','M'};
static const unsigned char I_COMT[4] = {'C','O','M','T'};
static const unsigned char I_INFO[4] = {'I','N','F','O'};
static const unsigned char I_INST[4] = {'I','N','S','T'};
static const unsigned char I_MARK[4] = {'M','A','R','K'};
static const unsigned char I_SSND[4] = {'S','S','N','D'};
static const unsigned char I_NONE[4] = {'N','O','N','E'};
static const unsigned char I_ULAW[4] = {'U','L','A','W'}; /* AIFC compression types that we can handle */
static const unsigned char I_ulaw[4] = {'u','l','a','w'}; /* or maybe it's lowercase (Apple) ... */
static const unsigned char I_raw_[4] = {'r','a','w',' '}; /* AIFC offset binary OS 8.5 (others are 'MAC3' 'MAC6' 'cdx4' 'cdx2' 'str4') */
static const unsigned char I_sowt[4] = {'s','o','w','t'}; /* AIFC 16-bit little endian -- used by Mac when extracting CD tracks */
static const unsigned char I_fl32[4] = {'f','l','3','2'}; /* AIFC 32-bit float */
static const unsigned char I_fl64[4] = {'f','l','6','4'}; /* AIFC 64-bit float */
static const unsigned char I_alaw[4] = {'a','l','a','w'}; /* apple */
static const unsigned char I_APPL[4] = {'A','P','P','L'};
static const unsigned char I_MUS_[4] = {'C','L','M',' '}; /* I hereby claim this AIFF chunk name */
static const unsigned char I_RIFF[4] = {'R','I','F','F'}; /* RIFF first word */
static const unsigned char I_RIFX[4] = {'R','I','F','X'}; /* RIFX first word (big-endian RIFF file) */
static const unsigned char I_WAVE[4] = {'W','A','V','E'};
static const unsigned char I_fmt_[4] = {'f','m','t',' '};
static const unsigned char I_data[4] = {'d','a','t','a'};
static const unsigned char I_fact[4] = {'f','a','c','t'}; /* used by compressed RIFF files */
static const unsigned char I_clm_[4] = {'c','l','m',' '};
static const unsigned char I_NIST[4] = {'N','I','S','T'}; /* first word of NIST SPHERE files */
static const unsigned char I_VOC0[4] = {'C','r','e','a'}; /* Actual text is "Creative Voice File" */
static const unsigned char I_SOUN[4] = {'S','O','U','N'}; /* Sound Tools first word="SOUND" -- not unique as SMP files start with "SOUND SAMPLE" */
static const unsigned char I_ANNO[4] = {'A','N','N','O'};
static const unsigned char I_NAME[4] = {'N','A','M','E'};
static const unsigned char I_AVR_[4] = {'2','B','I','T'}; /* first word of AVR files */
static const unsigned char I_SPIB[4] = {'%','/','/','\n'}; /* first word of IEEE spib text sound files */
static const unsigned char I_S___[4] = {'%','-','-','-'}; /* first word of other IEEE spib text sound files */
static const unsigned char I_ALaw[4] = {'A','L','a','w'}; /* first word of PSION alaw files */
static const unsigned char I_MThd[4] = {'M','T','h','d'}; /* sigh -- the M word */
static const unsigned char I_DECN[4] = {'.','s','d','\0'}; /* first word of DEC files (?) */
static const unsigned char I_LIST[4] = {'L','I','S','T'};
static const unsigned char I_GF1P[4] = {'G','F','1','P'}; /* first word of Gravis Ultrsound patch files */
static const unsigned char I_DSIG[4] = {'$','S','I','G'}; /* first word of Comdisco SPW file */
static const unsigned char I_GOLD[4] = {'G','O','L','D'}; /* first word Goldwave(?) sample file */
static const unsigned char I_SRFS[4] = {'S','R','F','S'}; /* first word Sonic Resource Foundry file(?) */
static const unsigned char I_Diam[4] = {'D','i','a','m'}; /* first word DiamondWare file */
static const unsigned char I_CSRE[4] = {'C','S','R','E'}; /* adf first word -- second starts with "40" */
static const unsigned char I_SND_[4] = {'S','N','D',' '}; /* SBStudio II */
static const unsigned char I_DDSF[4] = {'D','D','S','F'}; /* Delusion Digital Sound File */
static const unsigned char I_FSMt[4] = {'F','S','M',(unsigned char)'\376'}; /* Farandole Composer WaveSample */
static const unsigned char I_UWFD[4] = {'U','W','F','D'}; /* Ultratracker Wavesample */
static const unsigned char I_LM89[4] = {'L','M','8','9'}; /* Yamaha TX-16 */
static const unsigned char I_SY80[4] = {'S','Y','8','0'}; /* Yamaha SY-99 */
static const unsigned char I_SY85[4] = {'S','Y','8','5'}; /* Yamaha SY-85 */
static const unsigned char I_SCRS[4] = {'S','C','R','S'}; /* Digiplayer ST3 */
static const unsigned char I_covox[4] = {(unsigned char)'\377','\125',(unsigned char)'\377',(unsigned char)'\252'};
static const unsigned char I_PRAM[4] = {'P','R','A','M'}; /* Kurzweil 2000 */
static const unsigned char I__PAF[4] = {' ','p','a','f'}; /* Paris Ensoniq */
static const unsigned char I_FAP_[4] = {'f','a','p',' '}; /* Paris Ensoniq */
static const unsigned char I_file[4] = {'f','i','l','e'}; /* snack "SMP" */
static const unsigned char I_PVF1[4] = {'P','V','F','1'}; /* portable voice format (mgetty) */
static const unsigned char I_PVF2[4] = {'P','V','F','2'};
static const unsigned char I_riff[4] = {'r','i','f','f'}; /* SoundForge */
static const unsigned char I_TWIN[4] = {'T','W','I','N'}; /* TwinVQ */
static const unsigned char I_IMPS[4] = {'I','M','P','S'}; /* Impulse Tracker */
static const unsigned char I_SMP1[4] = {'S','M','P','1'}; /* Korg */
static const unsigned char I_Maui[4] = {'M','a','u','i'}; /* Turtle Beach */
static const unsigned char I_SDIF[4] = {'S','D','I','F'}; /* IRCAM sdif */
#if G7XX
static const unsigned char I_NVF_[4] = {'N','V','F',' '}; /* Nomad II Creative NVF */
#endif
static const unsigned char I_ajkg[4] = {'a','j','k','g'}; /* shorten */
static const unsigned char I_RF64[4] = {'R','F','6','4'}; /* EBU RF64 */
static const unsigned char I_ds64[4] = {'d','s','6','4'}; /* EBU RF64 */
static const unsigned char I_caff[4] = {'c','a','f','f'}; /* Apple CAFF */
static const unsigned char I_desc[4] = {'d','e','s','c'}; /* Apple CAFF */
static const unsigned char I_lpcm[4] = {'l','p','c','m'}; /* Apple CAFF */
static const unsigned char I_dSoX[4] = {'.','S','o','X'}; /* Sox intermediate (little-endian?) */
static const unsigned char I_XoSd[4] = {'X','o','S','.'}; /* Sox intermediate */
#define HDRBUFSIZ 256
static unsigned char *hdrbuf;
#define INITIAL_READ_SIZE 256
/* AIFF files can have any number of ANNO chunks, so we'll grab at least 4 of them */
#define AUX_COMMENTS 4
static mus_long_t *aux_comment_start = NULL, *aux_comment_end = NULL;
#define LOOPS 2
static int *loop_modes = NULL, *loop_starts = NULL, *loop_ends = NULL;
static int markers = 0;
static int *marker_ids = NULL, *marker_positions = NULL;
static bool hdrbuf_is_inited = false;
/* for CLM */
void mus_reset_headers_c(void)
{
hdrbuf_is_inited = false;
markers = 0;
}
int mus_header_initialize(void)
{
if (!hdrbuf_is_inited)
{
hdrbuf_is_inited = true;
hdrbuf = (unsigned char *)calloc(HDRBUFSIZ, sizeof(unsigned char));
aux_comment_start = (mus_long_t *)calloc(AUX_COMMENTS, sizeof(mus_long_t));
aux_comment_end = (mus_long_t *)calloc(AUX_COMMENTS, sizeof(mus_long_t));
loop_modes = (int *)calloc(LOOPS, sizeof(int));
loop_starts = (int *)calloc(LOOPS, sizeof(int));
loop_ends = (int *)calloc(LOOPS, sizeof(int));
if ((hdrbuf == NULL) || (aux_comment_start == NULL) || (aux_comment_end == NULL) ||
(loop_modes == NULL) || (loop_starts == NULL) || (loop_ends == NULL))
return(mus_error(MUS_MEMORY_ALLOCATION_FAILED, "mus_header_initialize: buffer allocation failed"));
}
return(MUS_NO_ERROR);
}
#define I_IRCAM_VAX 0x0001a364
#define I_IRCAM_SUN 0x0002a364
#define I_IRCAM_MIPS 0x0003a364
#define I_IRCAM_NEXT 0x0004a364
static mus_long_t data_location = 0;
static int srate = 0, chans = 0, original_sample_type = 0;
static mus_sample_t sample_type = MUS_UNKNOWN_SAMPLE;
static mus_header_t header_type = MUS_UNKNOWN_HEADER;
static int type_specifier = 0, bits_per_sample = 0, block_align = 0, fact_samples = 0;
static mus_long_t comment_start = 0, comment_end = 0;
static mus_long_t true_file_length = 0, data_size = 0;
static int base_detune = 0, base_note = 0;
static bool little_endian = false;
mus_long_t mus_header_samples(void) {return(data_size);}
mus_long_t mus_header_data_location(void) {return(data_location);}
int mus_header_chans(void) {return(chans);}
int mus_header_srate(void) {return(srate);}
mus_header_t mus_header_type(void) {return(header_type);}
mus_sample_t mus_header_sample_type(void) {return(sample_type);}
mus_long_t mus_header_comment_start(void) {return(comment_start);}
mus_long_t mus_header_comment_end(void) {return(comment_end);}
mus_long_t mus_header_aux_comment_start(int n) {if (aux_comment_start) return(aux_comment_start[n]); else return(-1);}
mus_long_t mus_header_aux_comment_end(int n) {if (aux_comment_end) return(aux_comment_end[n]); else return(-1);}
int mus_header_type_specifier(void) {return(type_specifier);}
int mus_header_bits_per_sample(void) {return(bits_per_sample);}
int mus_header_fact_samples(void) {return(fact_samples);}
int mus_header_block_align(void) {return(block_align);}
mus_long_t mus_header_true_length(void) {return(true_file_length);}
int mus_header_original_sample_type(void) {return(original_sample_type);}
int mus_header_loop_mode(int which) {if (loop_modes) return(loop_modes[which]); else return(-1);}
int mus_header_loop_start(int which) {if (loop_starts) return(loop_starts[which]); else return(-1);}
int mus_header_loop_end(int which) {if (loop_ends) return(loop_ends[which]); else return(-1);}
int mus_header_mark_position(int id) {int i; for (i = 0; i < markers; i++) {if (marker_ids[i] == id) return(marker_positions[i]);} return(-1);}
int mus_header_base_detune(void) {return(base_detune);}
int mus_header_base_note(void) {return(base_note);}
int mus_header_mark_info(int **m_ids, int **m_positions)
{
(*m_ids) = marker_ids;
(*m_positions) = marker_positions;
return(markers);
}
int mus_bytes_per_sample(mus_sample_t samp_type)
{
switch (samp_type)
{
case MUS_BYTE: return(1); break;
case MUS_BSHORT: return(2); break;
case MUS_UBYTE: return(1); break;
case MUS_MULAW: return(1); break;
case MUS_ALAW: return(1); break;
case MUS_BINT: return(4); break;
case MUS_BFLOAT: return(4); break;
case MUS_BFLOAT_UNSCALED: return(4); break;
case MUS_B24INT: return(3); break;
case MUS_BDOUBLE: return(8); break;
case MUS_BDOUBLE_UNSCALED: return(8); break;
case MUS_LSHORT: return(2); break;
case MUS_LINT: return(4); break;
case MUS_LFLOAT: return(4); break;
case MUS_LDOUBLE: return(8); break;
case MUS_LFLOAT_UNSCALED: return(4); break;
case MUS_LDOUBLE_UNSCALED: return(8); break;
case MUS_L24INT: return(3); break;
case MUS_UBSHORT: return(2); break;
case MUS_ULSHORT: return(2); break;
case MUS_BINTN: return(4); break;
case MUS_LINTN: return(4); break;
default: return(1); break; /* we divide by this number, so 0 is not safe */
}
}
mus_long_t mus_samples_to_bytes (mus_sample_t samp_type, mus_long_t size)
{
return(size * (mus_bytes_per_sample(samp_type)));
}
mus_long_t mus_bytes_to_samples (mus_sample_t samp_type, mus_long_t size)
{
return((mus_long_t)(size / (mus_bytes_per_sample(samp_type))));
}
static bool equal_big_or_little_endian(const unsigned char *n1, const unsigned int n2)
{
return((mus_char_to_ubint(n1) == n2) || (mus_char_to_ulint(n1) == n2));
}
static short big_or_little_endian_short(const unsigned char *n, bool little)
{
if (little) return(mus_char_to_lshort(n));
return(mus_char_to_bshort(n));
}
static int big_or_little_endian_int(const unsigned char *n, bool little)
{
if (little) return(mus_char_to_lint(n));
return(mus_char_to_bint(n));
}
static unsigned int big_or_little_endian_uint(const unsigned char *n, bool little)
{
if (little) return(mus_char_to_ulint(n));
return(mus_char_to_ubint(n));
}
static float big_or_little_endian_float(const unsigned char *n, bool little)
{
if (little) return(mus_char_to_lfloat(n));
return(mus_char_to_bfloat(n));
}
static bool match_four_chars(const unsigned char *head, const unsigned char *match)
{
return((head[0] == match[0]) &&
(head[1] == match[1]) &&
(head[2] == match[2]) &&
(head[3] == match[3]));
}
static void write_four_chars(unsigned char *head, const unsigned char *match)
{
head[0] = match[0];
head[1] = match[1];
head[2] = match[2];
head[3] = match[3];
}
const char *mus_header_type_name(mus_header_t type)
{
switch (type)
{
case MUS_NEXT: return("Sun/Next"); break;
case MUS_AIFC: return("AIFC"); break;
case MUS_RIFF: return("RIFF"); break;
case MUS_BICSF: return("BICSF"); break;
case MUS_NIST: return("NIST"); break;
case MUS_INRS: return("INRS"); break;
case MUS_ESPS: return("ESPS"); break;
case MUS_SVX: return("SVX8"); break;
case MUS_VOC: return("VOC"); break;
case MUS_SNDT: return("SNDT"); break;
case MUS_SOX: return("Sox"); break;
case MUS_RAW: return("raw (no header)"); break;
case MUS_SMP: return("SMP"); break;
case MUS_AVR: return("AVR"); break;
case MUS_IRCAM: return("IRCAM"); break;
case MUS_SD1: return("Sound Designer 1"); break;
case MUS_SPPACK: return("SPPACK"); break;
case MUS_MUS10: return("Mus10"); break;
case MUS_HCOM: return("HCOM"); break;
case MUS_PSION: return("PSION"); break;
case MUS_MAUD: return("MAUD"); break;
case MUS_IEEE: return("IEEE text"); break;
case MUS_MATLAB: return("Matlab"); break;
case MUS_ADC: return("ADC/OGI"); break;
case MUS_MIDI: return("MIDI"); break;
case MUS_SOUNDFONT: return("SoundFont"); break;
case MUS_GRAVIS: return("Gravis Ultrasound patch"); break;
case MUS_COMDISCO: return("Comdisco SPW signal"); break;
case MUS_GOLDWAVE: return("Goldwave sample"); break;
case MUS_SRFS: return("SRFS"); break;
case MUS_MIDI_SAMPLE_DUMP: return("MIDI sample dump"); break;
case MUS_DIAMONDWARE: return("DiamondWare"); break;
case MUS_ADF: return("CSRE adf"); break;
case MUS_SBSTUDIOII: return("SBStudioII"); break;
case MUS_DELUSION: return("Delusion"); break;
case MUS_FARANDOLE: return("Farandole"); break;
case MUS_SAMPLE_DUMP: return("Sample dump"); break;
case MUS_ULTRATRACKER: return("Ultratracker"); break;
case MUS_YAMAHA_TX16W: return("TX-16W"); break;
case MUS_YAMAHA_SY85: return("Sy-85"); break;
case MUS_YAMAHA_SY99: return("Sy-99"); break;
case MUS_KURZWEIL_2000: return("Kurzweil 2000"); break;
case MUS_KORG: return("Korg"); break;
case MUS_MAUI: return("Turtle Beach"); break;
case MUS_IMPULSETRACKER: return("Impulse Tracker"); break;
case MUS_AKAI4: return("AKAI 4"); break;
case MUS_DIGIPLAYER: return("Digiplayer ST3"); break;
case MUS_COVOX: return("Covox V8"); break;
case MUS_AVI: return("AVI"); break;
case MUS_OMF: return("OMF"); break;
case MUS_QUICKTIME: return("Quicktime"); break;
case MUS_ASF: return("asf"); break;
case MUS_AIFF: return("AIFF"); break;
case MUS_PAF: return("Ensoniq Paris"); break;
case MUS_CSL: return("CSL"); break;
case MUS_FILE_SAMP: return("snack SMP"); break;
case MUS_PVF: return("Portable Voice Format"); break;
case MUS_SOUNDFORGE: return("SoundForge"); break;
case MUS_TWINVQ: return("TwinVQ"); break;
case MUS_SDIF: return("IRCAM sdif"); break;
#if G7XX
case MUS_NVF: return("Creative NVF"); break;
#endif
case MUS_OGG: return("Ogg Vorbis"); break;
case MUS_FLAC: return("Flac"); break;
case MUS_SPEEX: return("Speex"); break;
case MUS_MPEG: return("mpeg"); break;
case MUS_SHORTEN: return("shorten"); break;
case MUS_TTA: return("tta"); break;
case MUS_WAVPACK: return("wavpack"); break;
case MUS_RF64: return("rf64"); break;
case MUS_CAFF: return("caff"); break;
default: return("unknown"); break;
}
}
const char *mus_sample_type_name(mus_sample_t samp_type)
{
switch (samp_type)
{
case MUS_BSHORT: return("big endian short (16 bits)"); break;
case MUS_MULAW: return("mulaw (8 bits)"); break;
case MUS_BYTE: return("signed byte (8 bits)"); break;
case MUS_BFLOAT: return("big endian float (32 bits)"); break;
case MUS_BFLOAT_UNSCALED: return("big endian float (32 bits, unscaled)"); break;
case MUS_BINT: return("big endian int (32 bits)"); break;
case MUS_ALAW: return("alaw (8 bits)"); break;
case MUS_UBYTE: return("unsigned byte (8 bits)"); break;
case MUS_B24INT: return("big endian int (24 bits)"); break;
case MUS_BDOUBLE: return("big endian double (64 bits)"); break;
case MUS_BDOUBLE_UNSCALED: return("big endian double (64 bits, unscaled)"); break;
case MUS_LSHORT: return("little endian short (16 bits)"); break;
case MUS_LINT: return("little endian int (32 bits)"); break;
case MUS_LFLOAT: return("little endian float (32 bits)"); break;
case MUS_LDOUBLE: return("little endian double (64 bits)"); break;
case MUS_LFLOAT_UNSCALED: return("little endian float (32 bits, unscaled)"); break;
case MUS_LDOUBLE_UNSCALED: return("little endian double (64 bits, unscaled)"); break;
case MUS_UBSHORT: return("unsigned big endian short (16 bits)"); break;
case MUS_ULSHORT: return("unsigned little endian short (16 bits)"); break;
case MUS_L24INT: return("little endian int (24 bits)"); break;
case MUS_BINTN: return("normalized big endian int (32 bits)"); break;
case MUS_LINTN: return("normalized little endian int (32 bits)"); break;
default: return("unknown"); break;
}
}
const char *mus_sample_type_short_name(mus_sample_t samp_type)
{
switch (samp_type)
{
case MUS_BSHORT: return("short int"); break;
case MUS_MULAW: return("mulaw"); break;
case MUS_BYTE: return("signed byte"); break;
case MUS_BFLOAT: return("float"); break;
case MUS_BFLOAT_UNSCALED: return("float unscaled)"); break;
case MUS_BINT: return("int"); break;
case MUS_ALAW: return("alaw"); break;
case MUS_UBYTE: return("unsigned byte"); break;
case MUS_B24INT: return("24-bit int"); break;
case MUS_BDOUBLE: return("double"); break;
case MUS_BDOUBLE_UNSCALED: return("double unscaled"); break;
case MUS_LSHORT: return("short int"); break;
case MUS_LINT: return("int"); break;
case MUS_LFLOAT: return("float"); break;
case MUS_LDOUBLE: return("double"); break;
case MUS_LFLOAT_UNSCALED: return("float unscaled"); break;
case MUS_LDOUBLE_UNSCALED: return("double unscaled"); break;
case MUS_UBSHORT: return("unsigned short"); break;
case MUS_ULSHORT: return("unsigned short"); break;
case MUS_L24INT: return("24-bit int"); break;
case MUS_BINTN: return("normalized int"); break;
case MUS_LINTN: return("normalized int"); break;
default: return("unknown"); break;
}
}
#if HAVE_RUBY
#define TO_LANG(Str) (const char *)xen_scheme_constant_to_ruby(Str)
#else
#define TO_LANG(Str) Str
#endif
const char *mus_header_type_to_string(mus_header_t type)
{
switch (type)
{
case MUS_NEXT: return(TO_LANG(S_mus_next));
case MUS_AIFF: return(TO_LANG(S_mus_aiff));
case MUS_AIFC: return(TO_LANG(S_mus_aifc));
case MUS_RIFF: return(TO_LANG(S_mus_riff));
case MUS_NIST: return(TO_LANG(S_mus_nist));
case MUS_IRCAM: return(TO_LANG(S_mus_ircam));
case MUS_RAW: return(TO_LANG(S_mus_raw));
case MUS_BICSF: return(TO_LANG(S_mus_bicsf));
case MUS_VOC: return(TO_LANG(S_mus_voc));
case MUS_SVX: return(TO_LANG(S_mus_svx));
case MUS_SOUNDFONT: return(TO_LANG(S_mus_soundfont));
case MUS_RF64: return(TO_LANG(S_mus_rf64));
case MUS_CAFF: return(TO_LANG(S_mus_caff));
default: break;
}
return(NULL);
}
const char *mus_sample_type_to_string(mus_sample_t samp_type)
{
switch (samp_type)
{
case MUS_BSHORT: return(TO_LANG(S_mus_bshort));
case MUS_LSHORT: return(TO_LANG(S_mus_lshort));
case MUS_MULAW: return(TO_LANG(S_mus_mulaw));
case MUS_ALAW: return(TO_LANG(S_mus_alaw));
case MUS_BYTE: return(TO_LANG(S_mus_byte));
case MUS_UBYTE: return(TO_LANG(S_mus_ubyte));
case MUS_BFLOAT: return(TO_LANG(S_mus_bfloat));
case MUS_LFLOAT: return(TO_LANG(S_mus_lfloat));
case MUS_BINT: return(TO_LANG(S_mus_bint));
case MUS_LINT: return(TO_LANG(S_mus_lint));
case MUS_BINTN: return(TO_LANG(S_mus_bintn));
case MUS_LINTN: return(TO_LANG(S_mus_lintn));
case MUS_B24INT: return(TO_LANG(S_mus_b24int));
case MUS_L24INT: return(TO_LANG(S_mus_l24int));
case MUS_BDOUBLE: return(TO_LANG(S_mus_bdouble));
case MUS_LDOUBLE: return(TO_LANG(S_mus_ldouble));
case MUS_UBSHORT: return(TO_LANG(S_mus_ubshort));
case MUS_ULSHORT: return(TO_LANG(S_mus_ulshort));
case MUS_BDOUBLE_UNSCALED: return(TO_LANG(S_mus_bdouble_unscaled));
case MUS_LDOUBLE_UNSCALED: return(TO_LANG(S_mus_ldouble_unscaled));
case MUS_BFLOAT_UNSCALED: return(TO_LANG(S_mus_bfloat_unscaled));
case MUS_LFLOAT_UNSCALED: return(TO_LANG(S_mus_lfloat_unscaled));
default: break;
}
return(NULL);
}
static const char *any_sample_type_name(mus_sample_t sndlib_samp_type)
{
if (mus_is_sample_type(sndlib_samp_type))
return(mus_sample_type_name(sndlib_samp_type));
else return(mus_header_original_sample_type_name(mus_header_original_sample_type(), mus_header_type()));
}
#define SEEK_FILE_LENGTH(File) lseek(File, 0L, SEEK_END)
static int read_bicsf_header(const char *filename, int fd);
/* ------------------------------------ NeXT (or Sun) --------------------------------
*
* 0: ".snd"
* 4: data_location (bytes) (not necessarily word aligned on Sun)
* 8: data_size (bytes) -- sometimes incorrect ("advisory")
* 12: sample type indicator -- see below
* 16: srate (int)
* 20: chans
* 24: comment start
*
* in an AFsp file, the first 4 bytes of the comment are "AFsp",
* for bicsf, the integer at 28 is 107364 or 107415
*
* on NeXTStep, always big-endian. ".snd"==0x2e736e64 on big-endian machines.
*
* formats are:
* 0 unspecified, 1 mulaw_8, 2 linear_8, 3 linear_16, 4 linear_24, 5 linear_32, 6 float,
* 7 double, 8 indirect, 9 nested, 10 dsp_core, 11 dsp_data_8, 12 dsp_data_16, 13 dsp_data_24,
* 14 dsp_data_32, 16 display, 17 mulaw_squelch, 18 emphasized, 19 compressed, 20 compressed_emphasized
* 21 dsp_commands, 22 dsp_commands_samples, 23 adpcm_g721, 24 adpcm_g722, 25 adpcm_g723,
* 26 adpcm_g723_5, 27 alaw_8, 28 aes, 29 delat_mulaw_8
* internal Snd(lib)-only formats:
* 30: mus_lint, 31: mus_lfloat,
* 32: mus_bintn, 33: mus_lintn,
* 34: mus_ldouble and others... (added by me for Snd internal use)
*/
/* according to the file /usr/share/magic, the DECN versions were little endian */
static int read_next_header(const char *filename, int fd)
{
int maybe_bicsf, err = MUS_NO_ERROR, i;
type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf);
data_location = mus_char_to_ubint((unsigned char *)(hdrbuf + 4));
if (data_location < 24) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data location: %lld?", filename, data_location));
data_size = mus_char_to_ubint((unsigned char *)(hdrbuf + 8)); /* changed to unsigned 11-Nov-06 */
/* can be bogus -- fixup if possible */
true_file_length = SEEK_FILE_LENGTH(fd);
if ((data_size <= 24) || (data_size > true_file_length))
data_size = (true_file_length - data_location);
else
{
if (true_file_length > (mus_long_t)0x80000000) /* (1 << 31)) */
data_size = true_file_length - data_location; /* assume size field overflowed 32 bits */
}
original_sample_type = mus_char_to_bint((unsigned char *)(hdrbuf + 12));
switch (original_sample_type)
{
case 1: sample_type = MUS_MULAW; break;
case 2: sample_type = MUS_BYTE; break; /* some sound files assume MUS_UBYTE here! (NAS from 1994 X11R6 contrib) */
case 3: sample_type = MUS_BSHORT; break;
case 4: sample_type = MUS_B24INT; break;
case 5: sample_type = MUS_BINT; break;
case 6: sample_type = MUS_BFLOAT; break;
case 7: sample_type = MUS_BDOUBLE; break;
case 18: sample_type = MUS_BSHORT; break; /* "emphasized": Xavier Serra's de-emphasis filter: y(n) = x(n) + .9 y(n-1) */
case 27: sample_type = MUS_ALAW; break;
case 30: sample_type = MUS_LINT; break; /* from here on, for Snd's internal benefit -- these are probably not used elsewhere */
case 31: sample_type = MUS_LFLOAT; break;
case 32: sample_type = MUS_BINTN; break;
case 33: sample_type = MUS_LINTN; break;
case 34: sample_type = MUS_LDOUBLE; break;
case 35: sample_type = MUS_ULSHORT; break;
case 36: sample_type = MUS_UBSHORT; break;
case 37: sample_type = MUS_LFLOAT_UNSCALED; break;
case 38: sample_type = MUS_BFLOAT_UNSCALED; break;
case 39: sample_type = MUS_LDOUBLE_UNSCALED; break;
case 40: sample_type = MUS_BDOUBLE_UNSCALED; break;
case 41: sample_type = MUS_LSHORT; break;
case 42: sample_type = MUS_L24INT; break;
case 43: sample_type = MUS_UBYTE; break;
default: sample_type = MUS_UNKNOWN_SAMPLE; break;
}
srate = mus_char_to_bint((unsigned char *)(hdrbuf + 16));
chans = mus_char_to_bint((unsigned char *)(hdrbuf + 20));
comment_start = 0;
comment_end = 0;
for (i = 24; i < data_location - 1; i++)
if (hdrbuf[i] == '\0')
break;
else
{
if (hdrbuf[i] != ' ')
{
comment_start = i;
comment_end = data_location - 1;
break;
}
}
if (comment_end < comment_start) comment_end = comment_start;
maybe_bicsf = mus_char_to_bint((unsigned char *)(hdrbuf + 28));
if (maybe_bicsf == 107364) err = read_bicsf_header(filename, fd);
data_size = mus_bytes_to_samples(sample_type, data_size);
return(err);
}
static int sndlib_format_to_next(mus_sample_t samp_type)
{
switch (samp_type)
{
case MUS_MULAW: return(1); break;
case MUS_BYTE: return(2); break;
case MUS_BSHORT: return(3); break;
case MUS_B24INT: return(4); break;
case MUS_BINT: return(5); break;
case MUS_BFLOAT: return(6); break;
case MUS_BDOUBLE: return(7); break;
case MUS_ALAW: return(27); break;
case MUS_LINT: return(30); break; /* see above */
case MUS_LFLOAT: return(31); break;
case MUS_BINTN: return(32); break;
case MUS_LINTN: return(33); break;
case MUS_LDOUBLE: return(34); break;
case MUS_ULSHORT: return(35); break;
case MUS_UBSHORT: return(36); break;
case MUS_LFLOAT_UNSCALED: return(37); break;
case MUS_BFLOAT_UNSCALED: return(38); break;
case MUS_LDOUBLE_UNSCALED: return(39); break;
case MUS_BDOUBLE_UNSCALED: return(40); break;
case MUS_LSHORT: return(41); break;
case MUS_L24INT: return(42); break;
case MUS_UBYTE: return(43); break;
default:
return(mus_error(MUS_UNSUPPORTED_SAMPLE_TYPE, "Next header: can't write sample type: %d (%s)",
samp_type,
any_sample_type_name(samp_type)));
break;
}
}
static int header_write(int fd, unsigned char *buf, int chars)
{
if (chars > 0)
{
long long int bytes;
bytes = (long long int)write(fd, buf, chars);
if (bytes != chars)
{
char *errstr = NULL;
errstr = STRERROR(errno);
return(mus_error(MUS_WRITE_ERROR, "header_write: wrote %lld of %d bytes, %s",
bytes, chars, (errstr) ? errstr : "unknown error?"));
}
}
return(MUS_NO_ERROR);
}
static int header_read(int fd, unsigned char *buf, int chars)
{
if (chars > 0)
{
long long int bytes;
bytes = (long long int)read(fd, buf, chars);
if (bytes != chars)
{
char *errstr = NULL;
errstr = STRERROR(errno);
return(mus_error(MUS_READ_ERROR, "header_read: read %lld of %d bytes, %s",
bytes, chars, (errstr) ? errstr : "unknown error?"));
}
}
return(MUS_NO_ERROR);
}
static void write_next_comment(int fd, const char *comment, int len, int loc)
{
if (len > 0)
header_write(fd, (unsigned char *)comment, len);
len = loc - (len + 24);
if (len > 0)
{
unsigned char *combuf;
combuf = (unsigned char *)calloc(len, sizeof(unsigned char));
header_write(fd, combuf, len);
free(combuf);
}
}
static int mus_header_write_next_header(int fd, int wsrate, int wchans, int loc, int siz, mus_sample_t samp_type, const char *comment, int len)
{
int i, j;
write_four_chars((unsigned char *)hdrbuf, I_DSND); /* ".snd" */
i = len / 4;
j = 24 + (4 * (i + 1));
if (loc < j) loc = j;
mus_bint_to_char((unsigned char *)(hdrbuf + 4), loc);
mus_bint_to_char((unsigned char *)(hdrbuf + 8), siz);
mus_bint_to_char((unsigned char *)(hdrbuf + 12), sndlib_format_to_next(samp_type));
mus_bint_to_char((unsigned char *)(hdrbuf + 16), wsrate);
mus_bint_to_char((unsigned char *)(hdrbuf + 20), wchans);
header_write(fd, hdrbuf, 24);
write_next_comment(fd, comment, len, loc);
data_location = loc;
return(MUS_NO_ERROR);
}
/* ------------------------------------ AIFF ------------------------------------
*
* 0: "FORM"
* 4: size (bytes)
* 8: "AIFF" or "AIFC" -- the latter includes compressed formats (list extended for 8.5 Sound.h)
*
* Thereafter the file is organized into "chunks", each chunk being
* a 4-byte identifer followed by an int (4-bytes) giving the chunk size
* not including the 8-byte header. AIFF data is signed. If the chunk
* size is odd, an extra (unaccounted-for) null byte is added at the end.
*
* The chunks we want are "COMM", "SSND", and "APPL".
*
* COMM: 0: chans
* 2: framples
* 6: bits per sample
* 8: srate as 80-bit IEEE float
* then if AIFC (not AIFF), 4 bytes giving compression id ("NONE"=not compressed)
* followed by Pascal string giving long name of compression type
*
* SSND: 0: data location (offset within SSND chunk)
*
* Other chunks include: ANNO: a comment, INST: loop control, MARK: marker, MIDI: midi,
* COMT: comment (max 65536 chars), NAME: sound name, AUTH: author's name
* (c), AESD: recording data, APPL: application specific stuff
* "MARK" size short-#marks {marks} -- latter are short-ID long-position pstring-name.
* "INST" size chars[baseNote detune lowNote highNote lowVelocity HighVelocity] short-gain loops[sustain release]
* loop: short-playMode marker-begin marker-end (signed?) shorts)
* playMode: 0 no loop, 1 forward loop, 2 forward/backward loop
* chars are MIDI data (detune is in cents)
* "MIDI" size MIDI-data...
* "AESD" size AES Channel Status Data (24 bytes as specified by AES)
* see "AES: Guidelines for the use of the AES3 interface"
* byte 0: bit 0: 0 = consumer, 1 = pro
* bit 1: 0 = audio, 1 = non-audio
* bits 2:4: emphasis: 0:none, 4:none, 6:CD, 7:CCITT J17
* bits 6:7: srate: 00 = 48KHz, 01 = 48, 10 = 44.1, 11 = 32
* byte 1: bits 0:3: chans: 2:mono, else stereo
* byte 2 for word size stuff (always ends up 16-bit): bits 3-5 = sample length where 4 = 16-bit
* byte 3: multi-channels modes, 4: AES sync ref, 5:unused, 6-9:ASCII source ID, 10-13:ASCII destination ID
* byte 14-17:local sample addr, 18-21:time of day addr, then CRC checks
* "APPL" size signature data
* "COMT" size short-#comments {comments} -- the latter are long-time marker short-text-length char-text
* time is in seconds since 1-Jan-1904
* "NAME"/"AUTH"/"(c) "/"ANNO" size char-name
* "FVER" size(4) AIFC-format-version -- currently always 0xA2805140
* "SAXL" -- a desperate kludge to get around Apple's own compression schemes!
*
* always big-endian
* There was also (briefly) an AIFS file, now deprecated.
*/
/* ieee-80 conversions -- design by committee! */
/* this code taken from CSound sources -- apparently originally written by Malcolm Slaney at Apple */
#define ULPOW2TO31 ((unsigned int)0x80000000)
#define DPOW2TO31 ((double)2147483648.0) /* 2^31 */
static double myUlongToDouble(unsigned int ul)
{
double val;
if (ul & ULPOW2TO31) val = DPOW2TO31 + (ul & (~ULPOW2TO31));
else val = ul;
return val;
}
static unsigned int myDoubleToUlong(double val)
{
unsigned int ul;
if (val < DPOW2TO31) ul = (unsigned int)val;
else ul = ULPOW2TO31 | (unsigned int)(val-DPOW2TO31);
return ul;
}
static double ieee_80_to_double(unsigned char *p)
{
unsigned char sign;
short lexp = 0;
unsigned int mant1 = 0;
unsigned int mant0 = 0;
lexp = *p++; lexp <<= 8; lexp |= *p++; sign = (lexp & 0x8000) ? 1 : 0; lexp &= 0x7FFF;
mant1 = *p++; mant1 <<= 8; mant1 |= *p++; mant1 <<= 8; mant1 |= *p++; mant1 <<= 8; mant1 |= *p++;
mant0 = *p++; mant0 <<= 8; mant0 |= *p++; mant0 <<= 8; mant0 |= *p++; mant0 <<= 8; mant0 |= *p++;
if (mant1 == 0 && mant0 == 0 && lexp == 0 && sign == 0)
return 0.0;
else
{
double val;
val = myUlongToDouble(mant0) * pow(2.0, -63.0);
val += myUlongToDouble(mant1) * pow(2.0, -31.0);
val *= pow(2.0, ((double) lexp) - 16383.0);
return sign ? -val : val;
}
}
static void double_to_ieee_80(double val, unsigned char *p)
{
short lexp = 0;
unsigned char sign = 0;
unsigned int mant1 = 0;
unsigned int mant0 = 0;
if (val < 0.0)
{
sign = 1;
val = -val;
}
if (val != 0.0) /* val identically zero -> all elements zero */
{
lexp = (short)(log(val) / log(2.0) + 16383.0);
val *= pow(2.0, 31.0 + 16383.0 - (double)lexp);
mant1 = myDoubleToUlong(val);
val -= myUlongToDouble(mant1);
val *= pow(2.0, 32.0);
mant0 = myDoubleToUlong(val);
}
*p++ = ((sign << 7) | (lexp >> 8)); *p++ = 0xFF & lexp;
*p++ = 0xFF & (mant1 >> 24); *p++ = 0xFF & (mant1 >> 16); *p++ = 0xFF & (mant1 >> 8); *p++ = 0xFF & (mant1);
*p++ = 0xFF & (mant0 >> 24); *p++ = 0xFF & (mant0 >> 16); *p++ = 0xFF & (mant0 >> 8); *p++ = 0xFF & (mant0);
}
static mus_long_t update_form_size, update_framples_location, update_ssnd_location, update_rf64_location;
static long long int seek_and_read(int fd, unsigned char *buf, mus_long_t offset, int nbytes)
{
if (offset < 0) return(-1);
lseek(fd, offset, SEEK_SET);
return(read(fd, buf, nbytes));
}
static int read_aiff_marker(int m, unsigned char *buf)
{
int psize;
marker_ids[m] = mus_char_to_bshort((unsigned char *)buf);
marker_positions[m] = mus_char_to_bint((unsigned char *)(buf + 2));
psize = (int)buf[6] + 1;
if (psize & 1) psize++;
return(psize+6);
}
static void read_aif_mark_chunk(int fd, unsigned char *buf, mus_long_t offset)
{
int num_marks, m, moff, msize;
/* unsigned short #marks, each mark: id pos name (pstring damn it) */
num_marks = mus_char_to_ubshort((unsigned char *)(buf + 8));
if (num_marks > markers)
{
if (markers > 0)
{
if (marker_ids) free(marker_ids);
if (marker_positions) free(marker_positions);
}
markers = num_marks;
marker_ids = (int *)calloc(markers, sizeof(int));
marker_positions = (int *)calloc(markers, sizeof(int));
}
moff = 10;
for (m = 0; m < num_marks; m++)
{
if (seek_and_read(fd, (unsigned char *)buf, offset + moff, 8) > 0)
{
msize = read_aiff_marker(m, (unsigned char *)buf);
moff += msize;
}
}
}
static void read_aif_inst_chunk(unsigned char *buf)
{
base_note = buf[8];
base_detune = buf[9];
loop_modes[0] = mus_char_to_bshort((unsigned char *)(buf + 16));
loop_starts[0] = mus_char_to_bshort((unsigned char *)(buf + 18));
loop_ends[0] = mus_char_to_bshort((unsigned char *)(buf + 20));
loop_modes[1] = mus_char_to_bshort((unsigned char *)(buf + 22));
loop_starts[1] = mus_char_to_bshort((unsigned char *)(buf + 24));
loop_ends[1] = mus_char_to_bshort((unsigned char *)(buf + 26));
/* these are mark numbers */
}
static void read_aif_aux_comment(unsigned char *buf, mus_long_t offset, int chunksize)
{
int i, j = 0;
for (i = 0; i < AUX_COMMENTS; i++)
if (aux_comment_start[i] == 0)
{
j = i;
break;
}
if (j >= AUX_COMMENTS)
{
mus_print("read_aiff_header: ran out of auxiliary comment space");
j = 0;
}
aux_comment_start[j] = offset + 8;
if (match_four_chars((unsigned char *)buf, I_COMT))
aux_comment_start[j] += 8; /* skip time stamp and markerId (not ID, I assume!) */
aux_comment_end[j] = offset + 7 + chunksize;
}
static void read_aif_appl_chunk(unsigned char *buf, mus_long_t offset, int chunksize)
{
static const unsigned char I_SU7M[4] = {'S','U','7','M'};
static const unsigned char I_SU7R[4] = {'S','U','7','R'};
if (match_four_chars((unsigned char *)(buf + 8), I_MUS_))
{
/* my chunk has an arbitrary length comment (a lisp program evaluated in the CLM package)
* to handle mix et al. Can't use the built-in chunk for this because the comment length might
* be greater than 65536 chars. Need to remember to pad to even length here.
*/
comment_start = offset + 12;
comment_end = comment_start + chunksize - 5;
}
else
{
if ((match_four_chars((unsigned char *)(buf + 8), I_SU7M)) ||
(match_four_chars((unsigned char *)(buf + 8), I_SU7R)))
{
mus_print("this is an SU700 ssp file?");
data_location = 512;
chans = 1;
/* actually SU7M and SU7R point to 2 chan data as separate chunks */
}
}
}
static int read_aiff_header(const char *filename, int fd, int overall_offset)
{
/* we know we have checked for FORM xxxx AIFF|AIFC when we arrive here */
/* as far as I can tell, the COMM block has the header data we seek, and the SSND block has the sound data */
int chunkloc, i, ssnd_bytes = 0;
bool happy = true, got_comm = false;
mus_long_t offset = 0;
type_specifier = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 8 + overall_offset));
update_ssnd_location = 0;