comparison decoders/wav.c @ 178:bdbe09014724

Minor tweaks and such.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 05 Dec 2001 22:24:28 +0000
parents 1df5c106504e
children 26996236d790
comparison
equal deleted inserted replaced
177:028a6691fbf9 178:bdbe09014724
65 WAV_open, /* open() method */ 65 WAV_open, /* open() method */
66 WAV_close, /* close() method */ 66 WAV_close, /* close() method */
67 WAV_read /* read() method */ 67 WAV_read /* read() method */
68 }; 68 };
69 69
70 static int WAV_init(void)
71 {
72 return(1); /* always succeeds. */
73 } /* WAV_init */
74
75
76 static void WAV_quit(void)
77 {
78 /* it's a no-op. */
79 } /* WAV_quit */
80
81
82 70
83 /* Chunk management code... */ 71 /* Chunk management code... */
84 72
85 #define riffID 0x46464952 /* "RIFF", in ascii. */ 73 #define riffID 0x46464952 /* "RIFF", in ascii. */
86 #define waveID 0x45564157 /* "WAVE", in ascii. */ 74 #define waveID 0x45564157 /* "WAVE", in ascii. */
98 typedef struct { 86 typedef struct {
99 Uint16 iCoef1; 87 Uint16 iCoef1;
100 Uint16 iCoef2; 88 Uint16 iCoef2;
101 } ADPCMCOEFSET; 89 } ADPCMCOEFSET;
102 90
103 typedef struct S_FMT_T 91 typedef struct S_WAV_FMT_T
104 { 92 {
105 Uint32 chunkID; 93 Uint32 chunkID;
106 Sint32 chunkSize; 94 Sint32 chunkSize;
107 Sint16 wFormatTag; 95 Sint16 wFormatTag;
108 Uint16 wChannels; 96 Uint16 wChannels;
109 Uint32 dwSamplesPerSec; 97 Uint32 dwSamplesPerSec;
110 Uint32 dwAvgBytesPerSec; 98 Uint32 dwAvgBytesPerSec;
111 Uint16 wBlockAlign; 99 Uint16 wBlockAlign;
112 Uint16 wBitsPerSample; 100 Uint16 wBitsPerSample;
113 101
114 void (*free)(struct S_FMT_T *fmt); 102 void (*free)(struct S_WAV_FMT_T *fmt);
115 Uint32(*read_sample)(Sound_Sample *sample); 103 Uint32(*read_sample)(Sound_Sample *sample);
116 104
117 union 105 union
118 { 106 {
119 struct 107 struct
121 Uint16 cbSize; 109 Uint16 cbSize;
122 Uint16 wSamplesPerBlock; 110 Uint16 wSamplesPerBlock;
123 Uint16 wNumCoef; 111 Uint16 wNumCoef;
124 ADPCMCOEFSET *aCoeff; 112 ADPCMCOEFSET *aCoeff;
125 } adpcm; 113 } adpcm;
114
115 /* put other format-specific data here... */
126 } fmt; 116 } fmt;
127 } fmt_t; 117 } fmt_t;
128 118
129 119
130 /* 120 /*
263 } /* free_fmt_normal */ 253 } /* free_fmt_normal */
264 254
265 255
266 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) 256 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt)
267 { 257 {
258 /* (don't need to read more from the RWops...) */
268 fmt->free = free_fmt_normal; 259 fmt->free = free_fmt_normal;
269 fmt->read_sample = read_sample_fmt_normal; 260 fmt->read_sample = read_sample_fmt_normal;
270 return(1); 261 return(1);
271 } /* read_fmt_normal */ 262 } /* read_fmt_normal */
272 263
346 337
347 return(1); 338 return(1);
348 } /* read_fmt_adpcm */ 339 } /* read_fmt_adpcm */
349 340
350 341
342
351 /***************************************************************************** 343 /*****************************************************************************
352 * Everything else... * 344 * Everything else... *
353 *****************************************************************************/ 345 *****************************************************************************/
346
347 static int WAV_init(void)
348 {
349 return(1); /* always succeeds. */
350 } /* WAV_init */
351
352
353 static void WAV_quit(void)
354 {
355 /* it's a no-op. */
356 } /* WAV_quit */
354 357
355 358
356 static int read_fmt(SDL_RWops *rw, fmt_t *fmt) 359 static int read_fmt(SDL_RWops *rw, fmt_t *fmt)
357 { 360 {
358 /* if it's in this switch statement, we support the format. */ 361 /* if it's in this switch statement, we support the format. */
359 switch (fmt->wFormatTag) 362 switch (fmt->wFormatTag)
360 { 363 {
361 case FMT_NORMAL: 364 case FMT_NORMAL:
365 SNDDBG(("WAV: Appears to be uncompressed audio.\n"));
362 return(read_fmt_normal(rw, fmt)); 366 return(read_fmt_normal(rw, fmt));
363 367
364 case FMT_ADPCM: 368 case FMT_ADPCM:
369 SNDDBG(("WAV: Appears to be ADPCM compressed audio.\n"));
365 return(read_fmt_adpcm(rw, fmt)); 370 return(read_fmt_adpcm(rw, fmt));
371
372 /* add other types here. */
373
374 default:
375 SNDDBG(("WAV: Format %lu is unknown.\n",
376 (unsigned int) fmt->wFormatTag));
377 Sound_SetError("WAV: Unsupported format");
378 return(0); /* not supported whatsoever. */
366 } /* switch */ 379 } /* switch */
367 380
368 SNDDBG(("WAV: Format %d is unknown.\n", (int) fmt->wFormatTag)); 381 assert(0); /* shouldn't hit this point. */
369 Sound_SetError("WAV: Unsupported format"); 382 return(0);
370 return(0); /* not supported whatsoever. */
371 } /* read_fmt */ 383 } /* read_fmt */
372 384
373 385
374 /* 386 /*
375 * Locate a specific chunk in the WAVE file by ID... 387 * Locate a specific chunk in the WAVE file by ID...