public OpenAlSoundEngine(string deviceName)
{
if (deviceName != null)
Console.WriteLine("Using sound device `{0}`", deviceName);
else
Console.WriteLine("Using default sound device");
device = ALC10.alcOpenDevice(deviceName);
if (device == IntPtr.Zero)
{
Console.WriteLine("Failed to open device. Falling back to default");
device = ALC10.alcOpenDevice(null);
if (device == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL device");
}
context = ALC10.alcCreateContext(device, null);
if (context == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL context");
ALC10.alcMakeContextCurrent(context);
for (var i = 0; i < PoolSize; i++)
{
var source = 0U;
AL10.alGenSources(new IntPtr(1), out source);
if (AL10.alGetError() != AL10.AL_NO_ERROR)
{
Log.Write("sound", "Failed generating OpenAL source {0}", i);
return;
}
sourcePool.Add(source, new PoolSlot() { IsActive = false });
}
}