Replacing alutLoadWAV by SDL_LoadWAV

In the fps game AssaultCube, we only use straight OpenAL without using the ALUT library. Well almost, the only function we actually used was alutLoadWAV. Since this function is officially declared deprecated and nothing else was used from this library, we decided to replace this functionality by SDL_LoadWAV from the SDL library we use extensively. Here a C++ code snippet:

SDL_AudioSpec wavspec; uint32_t wavlen; uint8_t *wavbuf; if(!SDL_LoadWAV(file, &wavspec, &wavbuf, &wavlen)) return false;
// map wav header to openal format ALenum format; switch(wavspec.format) { case AUDIO_U8: case AUDIO_S8: format = wavspec.channels==2 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8; break; case AUDIO_U16: case AUDIO_S16: format = wavspec.channels==2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; break; default: SDL_FreeWAV(wavbuf); return false; } alBufferData(id, format, wavbuf, wavlen, wavspec.freq); SDL_FreeWAV(wavbuf);

Well it’s not a big deal, you only need to be careful with the format info, make sure you map the wav header correctly to the format enumeration for OpenAL, otherwise you will hear some strange sounds 😛

Advertisements

4 Responses to “Replacing alutLoadWAV by SDL_LoadWAV”


  1. 1 Coz May 21, 2008 at 10:59 pm

    Just wanted to say thanks for this little piece of code, I wanted to remove the ALut dependency from supertuxkart, another open source game :p

  2. 2 adrianhenke May 23, 2008 at 3:07 pm

    Heh, I was almost sure we aren’t the only project throwing out ALUT 😉 I’m glad it was useful for you..

  3. 3 Justin July 16, 2011 at 12:40 am

    I converted ALut to SDL using your code, but now I don’t hear anything.

    – with ALut I could hear the sound/Music.

    – When it loads the music it seems to load fine and everything just does not make any sound.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: