Added int32 adn float32 support to SDL_LoadWAV_RW().
authorRyan C. Gordon
Thu, 31 Aug 2006 21:00:10 +0000
changeset 19946abc7e6f9817
parent 1993 7a3889fc9e5d
child 1995 0ca6ba107642
Added int32 adn float32 support to SDL_LoadWAV_RW().
src/audio/SDL_wave.c
src/audio/SDL_wave.h
     1.1 --- a/src/audio/SDL_wave.c	Thu Aug 31 20:59:42 2006 +0000
     1.2 +++ b/src/audio/SDL_wave.c	Thu Aug 31 21:00:10 2006 +0000
     1.3 @@ -413,7 +413,7 @@
     1.4      int was_error;
     1.5      Chunk chunk;
     1.6      int lenread;
     1.7 -    int MS_ADPCM_encoded, IMA_ADPCM_encoded;
     1.8 +    int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded;
     1.9      int samplesize;
    1.10  
    1.11      /* WAV magic header */
    1.12 @@ -472,11 +472,15 @@
    1.13          was_error = 1;
    1.14          goto done;
    1.15      }
    1.16 -    MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
    1.17 +    IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
    1.18      switch (SDL_SwapLE16(format->encoding)) {
    1.19      case PCM_CODE:
    1.20          /* We can understand this */
    1.21          break;
    1.22 +    case IEEE_FLOAT_CODE:
    1.23 +        IEEE_float_encoded = 1;
    1.24 +        /* We can understand this */
    1.25 +        break;
    1.26      case MS_ADPCM_CODE:
    1.27          /* Try to understand this */
    1.28          if (InitMS_ADPCM(format) < 0) {
    1.29 @@ -506,24 +510,37 @@
    1.30      }
    1.31      SDL_memset(spec, 0, (sizeof *spec));
    1.32      spec->freq = SDL_SwapLE32(format->frequency);
    1.33 -    switch (SDL_SwapLE16(format->bitspersample)) {
    1.34 -    case 4:
    1.35 -        if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
    1.36 -            spec->format = AUDIO_S16;
    1.37 +
    1.38 +    if (IEEE_float_encoded) {
    1.39 +        if ((SDL_SwapLE16(format->bitspersample)) != 32) {
    1.40 +            was_error = 1;
    1.41          } else {
    1.42 -            was_error = 1;
    1.43 +            spec->format = AUDIO_F32;
    1.44          }
    1.45 -        break;
    1.46 -    case 8:
    1.47 -        spec->format = AUDIO_U8;
    1.48 -        break;
    1.49 -    case 16:
    1.50 -        spec->format = AUDIO_S16;
    1.51 -        break;
    1.52 -    default:
    1.53 -        was_error = 1;
    1.54 -        break;
    1.55 +    } else {
    1.56 +        switch (SDL_SwapLE16(format->bitspersample)) {
    1.57 +        case 4:
    1.58 +            if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
    1.59 +                spec->format = AUDIO_S16;
    1.60 +            } else {
    1.61 +                was_error = 1;
    1.62 +            }
    1.63 +            break;
    1.64 +        case 8:
    1.65 +            spec->format = AUDIO_U8;
    1.66 +            break;
    1.67 +        case 16:
    1.68 +            spec->format = AUDIO_S16;
    1.69 +            break;
    1.70 +        case 32:
    1.71 +            spec->format = AUDIO_S32;
    1.72 +            break;
    1.73 +        default:
    1.74 +            was_error = 1;
    1.75 +            break;
    1.76 +        }
    1.77      }
    1.78 +
    1.79      if (was_error) {
    1.80          SDL_SetError("Unknown %d-bit PCM data format",
    1.81                       SDL_SwapLE16(format->bitspersample));
     2.1 --- a/src/audio/SDL_wave.h	Thu Aug 31 20:59:42 2006 +0000
     2.2 +++ b/src/audio/SDL_wave.h	Thu Aug 31 21:00:10 2006 +0000
     2.3 @@ -34,6 +34,7 @@
     2.4  #define DATA		0x61746164      /* "data" */
     2.5  #define PCM_CODE	0x0001
     2.6  #define MS_ADPCM_CODE	0x0002
     2.7 +#define IEEE_FLOAT_CODE	0x0003
     2.8  #define IMA_ADPCM_CODE	0x0011
     2.9  #define MP3_CODE	0x0055
    2.10  #define WAVE_MONO	1