Game Development Reference
In-Depth Information
{
Al.alSourcef(channel, Al.AL_GAIN, _masterVolume);
Al.alSourcePlay(channel);
return new Sound(channel);
}
This now gives a master volume control for all the sound channels. The volume
can also be set per channel; this is useful when fading out music or making one
sound effect more or less noticeable.
public void ChangeVolume(Sound sound, float value)
{
Al.alSourcef(sound.Channel, Al.AL_GAIN, _masterVolume * value);
}
Here the volume of a particular sound is scaled by the master volume; this en-
sures that if the player sets his master volume to low setting then a new sound
isn't going to suddenly be very loud. The value should be between 0 and 1. Here's
some more test code that shows these volume changes.
public SoundTestState(SoundManager soundManager)
{
_soundManager = soundManager;
_soundManager.MasterVolume(0.1f);
}
This will set the volume to be one tenth its previous value. If you run the test state
again the difference should be immediately noticeable. The final task for the
sound manager is to make sure it closes down correctly. It creates a lot of refer-
ences to sound files and data and it needs to free these when it is destroyed. The
best way to do this is to implement the IDisposable interface.
public class SoundManager : IDisposable
public void Dispose()
{
foreach (SoundSource soundSource in _soundIdentifier.Values)
{
SoundSource temp = soundSource;
Al.alDeleteBuffers(1, ref temp._bufferId);
}
_soundIdentifier.Clear();
foreach (int slot in _soundChannels)
 
Search WWH ::




Custom Search