Greetings,
I’m sure playing a simple wav. file using SDL is trivial, but being new to it, I am having trouble playing a simple wav. sound file. I’m sure it probably takes only a couple of lines of code to do it; HELP. Please, someone, help me with this.
Thanks.
Richard---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
I’m sure playing a simple wav. file using SDL is trivial, but being
new to it, I am having trouble playing a simple wav. sound file. I’m
sure it probably takes only a couple of lines of code to do it; HELP.
Please, someone, help me with this.
It’s not hard, but it’s not simple, either. You load the WAV file with
SDL’s SDL_LoadWAV() function, and then feed it bit by bit to the audio
callback that you specified with SDL_OpenAudio().
If you just want to fire off a WAV sound and forget about it, you might
want to look at using the SDL_mixer library:
Mix_OpenAudio(blahblahblah);
Mix_Chunk *chunk = Mix_LoadWAV(filename);
Mix_PlayChannel(-1, chunk, 0);
/* at the end of your program: */
Mix_HaltChannel(-1);
Mix_FreeChunk(chunk);
Mix_CloseAudio();
–ryan.
Hmm, does Mix_CloseAudio() halt the channels for you? I normally just call
Mix_CloseAudio() first and then free the chunks via destructor calls
automatically. Seems to work fine, but if this doing things wrong, someone
let me know now.
Actually, it does; I’m just being anal.
–ryan.