[SDL] filling up variable of type SDL_AudioSpec for a wav file
Ryan C. Gordon
icculus at icculus.org
Tue Mar 13 14:58:51 PDT 2007
> SDL_OpenAudio(desired, &hwspec);
> [...]
> I can play the above mentioned wav file with format AUDIO_S16 only.
> Why it works only with AUDIO_S16 format? why it is not working with
> AUDIO_U8/AUDIO_S8 as file property tells that it is 8 bit.
Be careful in specifying a second argument to SDL_OpenAudio() that isn't
NULL. If it's NULL, it says, "I can only feed the audio device with data
in exactly (desired) format."
Passing (&hwspec) there says, "I prefer to write (desired) data to the
audio hardware since it's most efficient for me, but I'll be able to
handle whatever format the audio device actually turns out to be."
Most applications should specify NULL for the second parameter unless
they plan to supply a full mixer of their own (as some games and
libraries do).
SDL always tries to set the hardware to the closest thing to (desired),
but if the second parameter is NULL, it'll convert as necessary
internally so you always feed it data in the format you requested. If
you don't specify NULL, you are expected to feed data in the format it
reports, and it will do bad things (sound runs too fast/slow, sounds
like static, crashes) without warning if you don't.
--ryan.
More information about the SDL
mailing list