Saturday, August 23, 2008

Sound Manager

hi, this time i worked on the sound system, there is a lot of sound libs such as openal, bass, fmod, miles.
i chosed to use fmod ex because it is very advanced system and very easy to use.
i created sound manager to manage all sound creation in the game, i also add something called sound shader which is very similar to my material script.
sound shader is a script that let you to define specific parameters to one or few sounds and when you want to play the sound/s in that shader you just call CreateSoundFromShader(shaderNameInScript) which is a function inside sound manager and it will be played with all the attributes you specified in the script.
for example:
sound weapon_blaster_fire
minDistance 393
maxDistance 1181
volumeDb -2

shakeData 0 zzzztsolggeedccbbbaaaaaaaa
shakeData 1 zzzztsolggeedccbbbaaaaaaaa
1) weapon_blaster_fire is sound shader name which we called from the code
min/max distance is the distance which the sound is audible
2) volumeDb is volume in decibels
3) frequentlyused is one of few flags that allow me to control few sound attributes such as occlusion, looping etc. this is used to cache the sound so it will be played from memory and wont be decompressed every time we want to play it
4) sound/weapons/blaster/fire01 and sound/weapons/blaster/fire02 is 2 sound files we wish to play while activating this sound shader. by default we chose randomly one of them.
5) shakeData is intensity of the sound in ascii form (z is loud, a is complete silence), i use it to change camera view based on the sound volume.
few of the sounds in the game must be played in relation to model animations, so to make it possible i created something called frame based event system, which allows you to specify events that will be triggered on specific animation frame/s.
for example, this is how i created shotgun reload sound events:
"RELOAD", "9", "sound", "weapon_shotgun_clipout",
"RELOAD", "22", "sound", "weapon_shotgun_clipin",
"RELOAD", "35", "sound", "weapon_shotgun_pump1",
"RELOAD", "38", "sound", "weapon_shotgun_pump2"
"RELOAD" is animation name
"9", "22", "35", "38" is frames to trigger the event
"sound" event type - all of them is sound
the last parameter is based on event type, in sound events its sound shader name


MarmAmic said...

This is really something. What about 3d sound like foot steps coming from behind or blasts from far away.

You can hear someone shooting a gun through a door but it will sound muffled. How do you handle that?

orenk2k said...

all the sound in the game are 3d sounds except for the music,
so you are hearing blasts and foot steps, even rocket sound if its flies nearby.
as for sounds played inside rooms that blocks by doors its relating to sound occlusion and right now i'm not supporting it.
i also doesn't support reverberation effects, so if you are inside water pool the sounds will be sound the same as if you are outside the pool.