Getting Sound Working In LIAV

From EQUIS Lab Wiki

Jump to: navigation, search

To get audio working in LIAV:

1. Install OpenAL

http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx

2. Update the Listener position

Add the following lines to the end of the UpdateAvatar method in CAXGameState (after avatar->rotateā€¦):

//Set the OpenAL Listener's position and orientation to match the Avatar's

CAXSoundManager::getSingleton().setListenerPosition(tpos);

CAXSoundManager::getSingleton().setListenerOrientation(avatar->getDirection(), Vector3(0.0f, 1.0f, 0.0f));

This is the crucial code that LIAV was missing - in OpenAL there can be multiple sound sources at independent locations in the world, and a single "listener" placed at the user's position. Because LIAV was not updating the listener with the avatar's position and orientation in each frame, the listener position could go out of sync (and in fact would be initialized so far away from all sound sources that no sound could be heard at all)

3. Verify

To verify that sound now works, you can put a sound file where LIAV is expecting to find some ambient background noise in a .wav file:

a) Create a folder called "sound" inside the LIAV "media" folder

b) Add some wave file to this folder and rename it to "forest.wav"

Your .wav file sound should start playing and repeat until you close LIAV. This would be a convenient way to add ambient noise or background music to your game. This is a bit of a hack - LIAV is simply playing back "forest.wav" on repeat at the exact same position as the listener, so that the sound plays over both speakers and doesn't vary as the listener moves.

4. Further sound effects

Further use of sound, such as for sound effects, requires some knowledge of OpenAL. The CAXSoundManager and CAXSoundSource classes provide an OO-centric wrapper for OpenAL and the ALUT libraries. More info is available here:

http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf