Game Development Reference
In-Depth Information
Each sound channel is represented by a number so the available sound channels
can simply be stored as a list of integers. The SoundManager constructor
initializes OpenAL and then discovers all the sound channels up to a maximum
of 256. The OpenAL function alGenSources generates a sound source that
reserves one of the channels. The code then checks for errors; if an error is
detected that means that OpenAL is unable to generate anymore sound sources
so it's time to break out of the loop.
Now that sound sources are being discovered, it's time to start adding this to the
EngineTest project. The sound manager should exist in the form.cs class and
then be passed through to any state that wants to use it.
public partial class Form1 : Form
{
bool
_fullscreen
= false;
FastLoop _fastLoop;
StateSystem _system = new StateSystem();
Input _input = new Input();
TextureManager _textureManager = new TextureManager();
SoundManager
_soundManager
= new SoundManager();
The last line creates the sound manager object and it will discover the number of
sound channels available. The next step is to load files from the hard disk into
memory. A new structure needs to be created to hold the data for the sound files
loaded from the disk.
public class SoundManager
{
struct SoundSource
{
public SoundSource(int bufferId, string filePath)
{
_bufferId = bufferId;
_filePath = filePath;
}
public int _bufferId;
string _filePath;
}
Dictionary<string, SoundSource> _soundIdentifier = new
Dictionary<string, SoundSource>();
 
Search WWH ::




Custom Search