src/audio/SDL_wave.c
changeset 10894 748bedefb03f
parent 10737 3406a0f8b041
child 11464 5af6d801e51f
equal deleted inserted replaced
10893:54480745c410 10894:748bedefb03f
   401     }
   401     }
   402     SDL_free(freeable);
   402     SDL_free(freeable);
   403     return (0);
   403     return (0);
   404 }
   404 }
   405 
   405 
       
   406 /* GUIDs that are used by WAVE_FORMAT_EXTENSIBLE */
       
   407 static const Uint8 extensible_pcm_guid[16] = { 1, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
       
   408 static const Uint8 extensible_ieee_guid[16] = { 3, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
       
   409 
   406 SDL_AudioSpec *
   410 SDL_AudioSpec *
   407 SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
   411 SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
   408                SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
   412                SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
   409 {
   413 {
   410     int was_error;
   414     int was_error;
   419     Uint32 WAVEmagic;
   423     Uint32 WAVEmagic;
   420     Uint32 headerDiff = 0;
   424     Uint32 headerDiff = 0;
   421 
   425 
   422     /* FMT chunk */
   426     /* FMT chunk */
   423     WaveFMT *format = NULL;
   427     WaveFMT *format = NULL;
       
   428     WaveExtensibleFMT *ext = NULL;
   424 
   429 
   425     SDL_zero(chunk);
   430     SDL_zero(chunk);
   426 
   431 
   427     /* Make sure we are passed a valid data source */
   432     /* Make sure we are passed a valid data source */
   428     was_error = 0;
   433     was_error = 0;
   491         if (InitIMA_ADPCM(format) < 0) {
   496         if (InitIMA_ADPCM(format) < 0) {
   492             was_error = 1;
   497             was_error = 1;
   493             goto done;
   498             goto done;
   494         }
   499         }
   495         IMA_ADPCM_encoded = 1;
   500         IMA_ADPCM_encoded = 1;
       
   501         break;
       
   502     case EXTENSIBLE_CODE:
       
   503         /* note that this ignores channel masks, smaller valid bit counts
       
   504            inside a larger container, and most subtypes. This is just enough
       
   505            to get things that didn't really _need_ WAVE_FORMAT_EXTENSIBLE
       
   506            to be useful working when they use this format flag. */
       
   507         ext = (WaveExtensibleFMT *) format;
       
   508         if (SDL_SwapLE16(ext->size) < 22) {
       
   509             SDL_SetError("bogus extended .wav header");
       
   510             was_error = 1;
       
   511             goto done;
       
   512         }
       
   513         if (SDL_memcmp(ext->subformat, extensible_pcm_guid, 16) == 0) {
       
   514             break;  /* cool. */
       
   515         } else if (SDL_memcmp(ext->subformat, extensible_ieee_guid, 16) == 0) {
       
   516             IEEE_float_encoded = 1;
       
   517             break;
       
   518         }
   496         break;
   519         break;
   497     case MP3_CODE:
   520     case MP3_CODE:
   498         SDL_SetError("MPEG Layer 3 data not supported");
   521         SDL_SetError("MPEG Layer 3 data not supported");
   499         was_error = 1;
   522         was_error = 1;
   500         goto done;
   523         goto done;