SDL  2.0
SDL_wave.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 
23 /* Microsoft WAVE file loading routines */
24 
25 #include "SDL_audio.h"
26 #include "SDL_wave.h"
27 
28 
29 static int ReadChunk(SDL_RWops * src, Chunk * chunk);
30 
32 {
37 };
38 static struct MS_ADPCM_decoder
39 {
43  Sint16 aCoeff[7][2];
44  /* * * */
47 
48 static int
50 {
51  Uint8 *rogue_feel;
52  int i;
53 
54  /* Set the rogue pointer to the MS_ADPCM specific data */
61  SDL_SwapLE16(format->bitspersample);
62  rogue_feel = (Uint8 *) format + sizeof(*format);
63  if (sizeof(*format) == 16) {
64  /* const Uint16 extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); */
65  rogue_feel += sizeof(Uint16);
66  }
67  MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
68  rogue_feel += sizeof(Uint16);
69  MS_ADPCM_state.wNumCoef = ((rogue_feel[1] << 8) | rogue_feel[0]);
70  rogue_feel += sizeof(Uint16);
71  if (MS_ADPCM_state.wNumCoef != 7) {
72  SDL_SetError("Unknown set of MS_ADPCM coefficients");
73  return (-1);
74  }
75  for (i = 0; i < MS_ADPCM_state.wNumCoef; ++i) {
76  MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1] << 8) | rogue_feel[0]);
77  rogue_feel += sizeof(Uint16);
78  MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1] << 8) | rogue_feel[0]);
79  rogue_feel += sizeof(Uint16);
80  }
81  return (0);
82 }
83 
84 static Sint32
86  Uint8 nybble, Sint16 * coeff)
87 {
88  const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
89  const Sint32 min_audioval = -(1 << (16 - 1));
90  const Sint32 adaptive[] = {
91  230, 230, 230, 230, 307, 409, 512, 614,
92  768, 614, 512, 409, 307, 230, 230, 230
93  };
94  Sint32 new_sample, delta;
95 
96  new_sample = ((state->iSamp1 * coeff[0]) +
97  (state->iSamp2 * coeff[1])) / 256;
98  if (nybble & 0x08) {
99  new_sample += state->iDelta * (nybble - 0x10);
100  } else {
101  new_sample += state->iDelta * nybble;
102  }
103  if (new_sample < min_audioval) {
104  new_sample = min_audioval;
105  } else if (new_sample > max_audioval) {
106  new_sample = max_audioval;
107  }
108  delta = ((Sint32) state->iDelta * adaptive[nybble]) / 256;
109  if (delta < 16) {
110  delta = 16;
111  }
112  state->iDelta = (Uint16) delta;
113  state->iSamp2 = state->iSamp1;
114  state->iSamp1 = (Sint16) new_sample;
115  return (new_sample);
116 }
117 
118 static int
119 MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
120 {
121  struct MS_ADPCM_decodestate *state[2];
122  Uint8 *freeable, *encoded, *encoded_end, *decoded, *decoded_end;
123  Sint32 encoded_len, samplesleft;
124  Sint8 nybble;
125  Uint8 stereo;
126  Sint16 *coeff[2];
127  Sint32 new_sample;
128 
129  /* Allocate the proper sized output buffer */
130  encoded_len = *audio_len;
131  encoded = *audio_buf;
132  encoded_end = encoded + encoded_len;
133  freeable = *audio_buf;
134  *audio_len = (encoded_len / MS_ADPCM_state.wavefmt.blockalign) *
137  *audio_buf = (Uint8 *) SDL_malloc(*audio_len);
138  if (*audio_buf == NULL) {
139  return SDL_OutOfMemory();
140  }
141  decoded = *audio_buf;
142  decoded_end = decoded + *audio_len;
143 
144  /* Get ready... Go! */
145  stereo = (MS_ADPCM_state.wavefmt.channels == 2);
146  state[0] = &MS_ADPCM_state.state[0];
147  state[1] = &MS_ADPCM_state.state[stereo];
148  while (encoded_len >= MS_ADPCM_state.wavefmt.blockalign) {
149  /* Grab the initial information for this block */
150  if (encoded + 7 + (stereo ? 7 : 0) > encoded_end) goto invalid_size;
151  state[0]->hPredictor = *encoded++;
152  if (stereo) {
153  state[1]->hPredictor = *encoded++;
154  }
155  if (state[0]->hPredictor >= 7 || state[1]->hPredictor >= 7) {
156  goto invalid_predictor;
157  }
158  state[0]->iDelta = ((encoded[1] << 8) | encoded[0]);
159  encoded += sizeof(Sint16);
160  if (stereo) {
161  state[1]->iDelta = ((encoded[1] << 8) | encoded[0]);
162  encoded += sizeof(Sint16);
163  }
164  state[0]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
165  encoded += sizeof(Sint16);
166  if (stereo) {
167  state[1]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
168  encoded += sizeof(Sint16);
169  }
170  state[0]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
171  encoded += sizeof(Sint16);
172  if (stereo) {
173  state[1]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
174  encoded += sizeof(Sint16);
175  }
176  coeff[0] = MS_ADPCM_state.aCoeff[state[0]->hPredictor];
177  coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor];
178 
179  /* Store the two initial samples we start with */
180  if (decoded + 4 + (stereo ? 4 : 0) > decoded_end) goto invalid_size;
181  decoded[0] = state[0]->iSamp2 & 0xFF;
182  decoded[1] = state[0]->iSamp2 >> 8;
183  decoded += 2;
184  if (stereo) {
185  decoded[0] = state[1]->iSamp2 & 0xFF;
186  decoded[1] = state[1]->iSamp2 >> 8;
187  decoded += 2;
188  }
189  decoded[0] = state[0]->iSamp1 & 0xFF;
190  decoded[1] = state[0]->iSamp1 >> 8;
191  decoded += 2;
192  if (stereo) {
193  decoded[0] = state[1]->iSamp1 & 0xFF;
194  decoded[1] = state[1]->iSamp1 >> 8;
195  decoded += 2;
196  }
197 
198  /* Decode and store the other samples in this block */
199  samplesleft = (MS_ADPCM_state.wSamplesPerBlock - 2) *
201  while (samplesleft > 0) {
202  if (encoded + 1 > encoded_end) goto invalid_size;
203  if (decoded + 4 > decoded_end) goto invalid_size;
204 
205  nybble = (*encoded) >> 4;
206  new_sample = MS_ADPCM_nibble(state[0], nybble, coeff[0]);
207  decoded[0] = new_sample & 0xFF;
208  new_sample >>= 8;
209  decoded[1] = new_sample & 0xFF;
210  decoded += 2;
211 
212  nybble = (*encoded) & 0x0F;
213  new_sample = MS_ADPCM_nibble(state[1], nybble, coeff[1]);
214  decoded[0] = new_sample & 0xFF;
215  new_sample >>= 8;
216  decoded[1] = new_sample & 0xFF;
217  decoded += 2;
218 
219  ++encoded;
220  samplesleft -= 2;
221  }
222  encoded_len -= MS_ADPCM_state.wavefmt.blockalign;
223  }
224  SDL_free(freeable);
225  return (0);
226 invalid_size:
227  SDL_SetError("Unexpected chunk length for a MS ADPCM decoder");
228  SDL_free(freeable);
229  return(-1);
230 invalid_predictor:
231  SDL_SetError("Invalid predictor value for a MS ADPCM decoder");
232  SDL_free(freeable);
233  return(-1);
234 }
235 
237 {
240 };
241 static struct IMA_ADPCM_decoder
242 {
245  /* * * */
248 
249 static int
251 {
252  Uint8 *rogue_feel, *rogue_feel_end;
253 
254  /* Set the rogue pointer to the IMA_ADPCM specific data */
255  if (length < sizeof(*format)) goto too_short;
262  SDL_SwapLE16(format->bitspersample);
263  rogue_feel = (Uint8 *) format + sizeof(*format);
264  rogue_feel_end = (Uint8 *)format + length;
265  if (sizeof(*format) == 16) {
266  /* const Uint16 extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); */
267  rogue_feel += sizeof(Uint16);
268  }
269  if (rogue_feel + 2 > rogue_feel_end) goto too_short;
270  IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
271  return (0);
272 too_short:
273  SDL_SetError("Unexpected length of a chunk with an IMA ADPCM format");
274  return(-1);
275 }
276 
277 static Sint32
279 {
280  const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
281  const Sint32 min_audioval = -(1 << (16 - 1));
282  const int index_table[16] = {
283  -1, -1, -1, -1,
284  2, 4, 6, 8,
285  -1, -1, -1, -1,
286  2, 4, 6, 8
287  };
288  const Sint32 step_table[89] = {
289  7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
290  34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
291  143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
292  449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
293  1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
294  3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
295  9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
296  22385, 24623, 27086, 29794, 32767
297  };
298  Sint32 delta, step;
299 
300  /* Compute difference and new sample value */
301  if (state->index > 88) {
302  state->index = 88;
303  } else if (state->index < 0) {
304  state->index = 0;
305  }
306  /* explicit cast to avoid gcc warning about using 'char' as array index */
307  step = step_table[(int)state->index];
308  delta = step >> 3;
309  if (nybble & 0x04)
310  delta += step;
311  if (nybble & 0x02)
312  delta += (step >> 1);
313  if (nybble & 0x01)
314  delta += (step >> 2);
315  if (nybble & 0x08)
316  delta = -delta;
317  state->sample += delta;
318 
319  /* Update index value */
320  state->index += index_table[nybble];
321 
322  /* Clamp output sample */
323  if (state->sample > max_audioval) {
324  state->sample = max_audioval;
325  } else if (state->sample < min_audioval) {
326  state->sample = min_audioval;
327  }
328  return (state->sample);
329 }
330 
331 /* Fill the decode buffer with a channel block of data (8 samples) */
332 static void
333 Fill_IMA_ADPCM_block(Uint8 * decoded, Uint8 * encoded,
334  int channel, int numchannels,
336 {
337  int i;
338  Sint8 nybble;
339  Sint32 new_sample;
340 
341  decoded += (channel * 2);
342  for (i = 0; i < 4; ++i) {
343  nybble = (*encoded) & 0x0F;
344  new_sample = IMA_ADPCM_nibble(state, nybble);
345  decoded[0] = new_sample & 0xFF;
346  new_sample >>= 8;
347  decoded[1] = new_sample & 0xFF;
348  decoded += 2 * numchannels;
349 
350  nybble = (*encoded) >> 4;
351  new_sample = IMA_ADPCM_nibble(state, nybble);
352  decoded[0] = new_sample & 0xFF;
353  new_sample >>= 8;
354  decoded[1] = new_sample & 0xFF;
355  decoded += 2 * numchannels;
356 
357  ++encoded;
358  }
359 }
360 
361 static int
362 IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
363 {
365  Uint8 *freeable, *encoded, *decoded;
366  Sint32 encoded_len, samplesleft;
367  unsigned int c, channels;
368 
369  /* Check to make sure we have enough variables in the state array */
370  channels = IMA_ADPCM_state.wavefmt.channels;
371  if (channels > SDL_arraysize(IMA_ADPCM_state.state)) {
372  SDL_SetError("IMA ADPCM decoder can only handle %u channels",
373  (unsigned int)SDL_arraysize(IMA_ADPCM_state.state));
374  return (-1);
375  }
376  state = IMA_ADPCM_state.state;
377 
378  /* Allocate the proper sized output buffer */
379  encoded_len = *audio_len;
380  encoded = *audio_buf;
381  freeable = *audio_buf;
382  *audio_len = (encoded_len / IMA_ADPCM_state.wavefmt.blockalign) *
385  *audio_buf = (Uint8 *) SDL_malloc(*audio_len);
386  if (*audio_buf == NULL) {
387  return SDL_OutOfMemory();
388  }
389  decoded = *audio_buf;
390 
391  /* Get ready... Go! */
392  while (encoded_len >= IMA_ADPCM_state.wavefmt.blockalign) {
393  /* Grab the initial information for this block */
394  for (c = 0; c < channels; ++c) {
395  /* Fill the state information for this block */
396  state[c].sample = ((encoded[1] << 8) | encoded[0]);
397  encoded += 2;
398  if (state[c].sample & 0x8000) {
399  state[c].sample -= 0x10000;
400  }
401  state[c].index = *encoded++;
402  /* Reserved byte in buffer header, should be 0 */
403  if (*encoded++ != 0) {
404  /* Uh oh, corrupt data? Buggy code? */ ;
405  }
406 
407  /* Store the initial sample we start with */
408  decoded[0] = (Uint8) (state[c].sample & 0xFF);
409  decoded[1] = (Uint8) (state[c].sample >> 8);
410  decoded += 2;
411  }
412 
413  /* Decode and store the other samples in this block */
414  samplesleft = (IMA_ADPCM_state.wSamplesPerBlock - 1) * channels;
415  while (samplesleft > 0) {
416  for (c = 0; c < channels; ++c) {
417  Fill_IMA_ADPCM_block(decoded, encoded,
418  c, channels, &state[c]);
419  encoded += 4;
420  samplesleft -= 8;
421  }
422  decoded += (channels * 8 * 2);
423  }
424  encoded_len -= IMA_ADPCM_state.wavefmt.blockalign;
425  }
426  SDL_free(freeable);
427  return (0);
428 }
429 
431 SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
432  SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
433 {
434  int was_error;
435  Chunk chunk;
436  int lenread;
437  int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded;
438  int samplesize;
439 
440  /* WAV magic header */
441  Uint32 RIFFchunk;
442  Uint32 wavelen = 0;
443  Uint32 WAVEmagic;
444  Uint32 headerDiff = 0;
445 
446  /* FMT chunk */
447  WaveFMT *format = NULL;
448 
449  SDL_zero(chunk);
450 
451  /* Make sure we are passed a valid data source */
452  was_error = 0;
453  if (src == NULL) {
454  was_error = 1;
455  goto done;
456  }
457 
458  /* Check the magic header */
459  RIFFchunk = SDL_ReadLE32(src);
460  wavelen = SDL_ReadLE32(src);
461  if (wavelen == WAVE) { /* The RIFFchunk has already been read */
462  WAVEmagic = wavelen;
463  wavelen = RIFFchunk;
464  RIFFchunk = RIFF;
465  } else {
466  WAVEmagic = SDL_ReadLE32(src);
467  }
468  if ((RIFFchunk != RIFF) || (WAVEmagic != WAVE)) {
469  SDL_SetError("Unrecognized file type (not WAVE)");
470  was_error = 1;
471  goto done;
472  }
473  headerDiff += sizeof(Uint32); /* for WAVE */
474 
475  /* Read the audio data format chunk */
476  chunk.data = NULL;
477  do {
478  SDL_free(chunk.data);
479  chunk.data = NULL;
480  lenread = ReadChunk(src, &chunk);
481  if (lenread < 0) {
482  was_error = 1;
483  goto done;
484  }
485  /* 2 Uint32's for chunk header+len, plus the lenread */
486  headerDiff += lenread + 2 * sizeof(Uint32);
487  } while ((chunk.magic == FACT) || (chunk.magic == LIST) || (chunk.magic == BEXT) || (chunk.magic == JUNK));
488 
489  /* Decode the audio data format */
490  format = (WaveFMT *) chunk.data;
491  if (chunk.magic != FMT) {
492  SDL_SetError("Complex WAVE files not supported");
493  was_error = 1;
494  goto done;
495  }
496  IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
497  switch (SDL_SwapLE16(format->encoding)) {
498  case PCM_CODE:
499  /* We can understand this */
500  break;
501  case IEEE_FLOAT_CODE:
502  IEEE_float_encoded = 1;
503  /* We can understand this */
504  break;
505  case MS_ADPCM_CODE:
506  /* Try to understand this */
507  if (InitMS_ADPCM(format) < 0) {
508  was_error = 1;
509  goto done;
510  }
511  MS_ADPCM_encoded = 1;
512  break;
513  case IMA_ADPCM_CODE:
514  /* Try to understand this */
515  if (InitIMA_ADPCM(format,lenread) < 0) {
516  was_error = 1;
517  goto done;
518  }
519  IMA_ADPCM_encoded = 1;
520  break;
521  case MP3_CODE:
522  SDL_SetError("MPEG Layer 3 data not supported");
523  was_error = 1;
524  goto done;
525  default:
526  SDL_SetError("Unknown WAVE data format: 0x%.4x",
527  SDL_SwapLE16(format->encoding));
528  was_error = 1;
529  goto done;
530  }
531  SDL_zerop(spec);
532  spec->freq = SDL_SwapLE32(format->frequency);
533 
534  if (IEEE_float_encoded) {
535  if ((SDL_SwapLE16(format->bitspersample)) != 32) {
536  was_error = 1;
537  } else {
538  spec->format = AUDIO_F32;
539  }
540  } else {
541  switch (SDL_SwapLE16(format->bitspersample)) {
542  case 4:
543  if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
544  spec->format = AUDIO_S16;
545  } else {
546  was_error = 1;
547  }
548  break;
549  case 8:
550  spec->format = AUDIO_U8;
551  break;
552  case 16:
553  spec->format = AUDIO_S16;
554  break;
555  case 32:
556  spec->format = AUDIO_S32;
557  break;
558  default:
559  was_error = 1;
560  break;
561  }
562  }
563 
564  if (was_error) {
565  SDL_SetError("Unknown %d-bit PCM data format",
566  SDL_SwapLE16(format->bitspersample));
567  goto done;
568  }
569  spec->channels = (Uint8) SDL_SwapLE16(format->channels);
570  spec->samples = 4096; /* Good default buffer size */
571 
572  /* Read the audio data chunk */
573  *audio_buf = NULL;
574  do {
575  SDL_free(*audio_buf);
576  *audio_buf = NULL;
577  lenread = ReadChunk(src, &chunk);
578  if (lenread < 0) {
579  was_error = 1;
580  goto done;
581  }
582  *audio_len = lenread;
583  *audio_buf = chunk.data;
584  if (chunk.magic != DATA)
585  headerDiff += lenread + 2 * sizeof(Uint32);
586  } while (chunk.magic != DATA);
587  headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */
588 
589  if (MS_ADPCM_encoded) {
590  if (MS_ADPCM_decode(audio_buf, audio_len) < 0) {
591  was_error = 1;
592  goto done;
593  }
594  }
595  if (IMA_ADPCM_encoded) {
596  if (IMA_ADPCM_decode(audio_buf, audio_len) < 0) {
597  was_error = 1;
598  goto done;
599  }
600  }
601 
602  /* Don't return a buffer that isn't a multiple of samplesize */
603  samplesize = ((SDL_AUDIO_BITSIZE(spec->format)) / 8) * spec->channels;
604  *audio_len &= ~(samplesize - 1);
605 
606  done:
607  SDL_free(format);
608  if (src) {
609  if (freesrc) {
610  SDL_RWclose(src);
611  } else {
612  /* seek to the end of the file (given by the RIFF chunk) */
613  SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
614  }
615  }
616  if (was_error) {
617  spec = NULL;
618  }
619  return (spec);
620 }
621 
622 /* Since the WAV memory is allocated in the shared library, it must also
623  be freed here. (Necessary under Win32, VC++)
624  */
625 void
626 SDL_FreeWAV(Uint8 * audio_buf)
627 {
628  SDL_free(audio_buf);
629 }
630 
631 static int
633 {
634  chunk->magic = SDL_ReadLE32(src);
635  chunk->length = SDL_ReadLE32(src);
636  chunk->data = (Uint8 *) SDL_malloc(chunk->length);
637  if (chunk->data == NULL) {
638  return SDL_OutOfMemory();
639  }
640  if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) {
641  SDL_free(chunk->data);
642  chunk->data = NULL;
643  return SDL_Error(SDL_EFREAD);
644  }
645  return (chunk->length);
646 }
647 
648 /* vi: set ts=4 sw=4 expandtab: */
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
#define PCM_CODE
Definition: SDL_wave.h:36
#define RIFF
Definition: SDL_wave.h:28
Uint16 wNumCoef
Definition: SDL_wave.c:42
Uint16 wSamplesPerBlock
Definition: SDL_wave.c:41
#define LIST
Definition: SDL_wave.h:31
Uint16 blockalign
Definition: SDL_wave.h:55
#define MP3_CODE
Definition: SDL_wave.h:40
static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded, int channel, int numchannels, struct IMA_ADPCM_decodestate *state)
Definition: SDL_wave.c:333
Definition: SDL_wave.h:60
struct xkb_state * state
void SDL_FreeWAV(Uint8 *audio_buf)
Definition: SDL_wave.c:626
#define SDL_ReadLE32
#define SDL_RWread(ctx, ptr, size, n)
Definition: SDL_rwops.h:187
Uint32 length
Definition: SDL_wave.h:63
Uint16 samples
Definition: SDL_audio.h:174
static int InitIMA_ADPCM(WaveFMT *format, int length)
Definition: SDL_wave.c:250
static struct IMA_ADPCM_decoder IMA_ADPCM_state
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
Uint16 encoding
Definition: SDL_wave.h:51
SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
Definition: SDL_wave.c:431
struct MS_ADPCM_decodestate state[2]
Definition: SDL_wave.c:45
#define SDL_zerop(x)
Definition: SDL_stdinc.h:362
#define SDL_Error
WaveFMT wavefmt
Definition: SDL_wave.c:243
static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state, Uint8 nybble, Sint16 *coeff)
Definition: SDL_wave.c:85
static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
Definition: SDL_wave.c:119
Uint16 channels
Definition: SDL_wave.h:52
#define FMT
Definition: SDL_wave.h:34
#define SDL_RWseek(ctx, offset, whence)
Definition: SDL_rwops.h:185
SDL_AudioSpec spec
Definition: loopwave.c:35
#define AUDIO_U8
Definition: SDL_audio.h:89
#define DATA
Definition: SDL_wave.h:35
#define FACT
Definition: SDL_wave.h:30
Uint8 channels
Definition: SDL_audio.h:172
int8_t Sint8
A signed 8-bit integer type.
Definition: SDL_stdinc.h:139
static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
Definition: SDL_wave.c:362
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
void SDL_free(void *mem)
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
#define SDL_SwapLE32(X)
Definition: SDL_endian.h:212
int done
Definition: checkkeys.c:28
#define AUDIO_S32
Definition: SDL_audio.h:105
#define WAVE
Definition: SDL_wave.h:29
struct IMA_ADPCM_decodestate state[2]
Definition: SDL_wave.c:246
const GLubyte * c
#define JUNK
Definition: SDL_wave.h:33
#define SDL_zero(x)
Definition: SDL_stdinc.h:361
Sint16 aCoeff[7][2]
Definition: SDL_wave.c:43
int32_t Sint32
Definition: SDL_stdinc.h:157
Uint8 * data
Definition: SDL_wave.h:64
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state, Uint8 nybble)
Definition: SDL_wave.c:278
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define IEEE_FLOAT_CODE
Definition: SDL_wave.h:38
#define SDL_RWclose(ctx)
Definition: SDL_rwops.h:189
#define IMA_ADPCM_CODE
Definition: SDL_wave.h:39
#define SDL_SetError
SDL_AudioFormat format
Definition: SDL_audio.h:171
static int InitMS_ADPCM(WaveFMT *format)
Definition: SDL_wave.c:49
Uint32 magic
Definition: SDL_wave.h:62
#define AUDIO_S16
Definition: SDL_audio.h:96
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:151
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:90
#define SDL_malloc
Uint16 wSamplesPerBlock
Definition: SDL_wave.c:244
Uint32 frequency
Definition: SDL_wave.h:53
#define RW_SEEK_CUR
Definition: SDL_rwops.h:175
Uint16 bitspersample
Definition: SDL_wave.h:56
#define AUDIO_F32
Definition: SDL_audio.h:114
GLuint GLsizei GLsizei * length
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:211
Uint32 byterate
Definition: SDL_wave.h:54
GLenum src
#define BEXT
Definition: SDL_wave.h:32
static int ReadChunk(SDL_RWops *src, Chunk *chunk)
Definition: SDL_wave.c:632
WaveFMT wavefmt
Definition: SDL_wave.c:40
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:147
static struct MS_ADPCM_decoder MS_ADPCM_state
#define MS_ADPCM_CODE
Definition: SDL_wave.h:37