2012-08-09 09:45:04 +00:00
|
|
|
using System;
|
2012-08-22 14:28:22 +00:00
|
|
|
using System.Collections.ObjectModel;
|
2011-12-01 08:47:54 +00:00
|
|
|
using System.IO;
|
2012-01-25 15:31:58 +00:00
|
|
|
using ANX.Framework.Audio;
|
2011-12-01 08:47:54 +00:00
|
|
|
using ANX.Framework.NonXNA;
|
2012-01-25 15:31:58 +00:00
|
|
|
using ANX.Framework.NonXNA.SoundSystem;
|
2012-08-29 13:04:22 +00:00
|
|
|
using OpenTK;
|
2012-08-26 12:53:00 +00:00
|
|
|
using OpenTK.Audio.OpenAL;
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-12-01 08:47:54 +00:00
|
|
|
|
|
|
|
namespace ANX.SoundSystem.OpenAL
|
|
|
|
{
|
2012-01-25 15:31:58 +00:00
|
|
|
public class Creator : ISoundSystemCreator
|
|
|
|
{
|
|
|
|
#region Public
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-09 09:45:04 +00:00
|
|
|
return "Sound.OpenAL";
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Priority
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-01-25 15:31:58 +00:00
|
|
|
public bool IsSupported
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-09 09:45:04 +00:00
|
|
|
PlatformName os = OSInformation.GetName();
|
|
|
|
return OSInformation.IsWindows ||
|
|
|
|
os == PlatformName.Linux ||
|
|
|
|
os == PlatformName.MacOSX;
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-02-11 23:53:03 +00:00
|
|
|
public float DistanceScale
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
return 1f;
|
|
|
|
//throw new NotImplementedException();
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
//throw new NotImplementedException();
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float DopplerScale
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
return AL.Get(ALGetFloat.DopplerFactor);
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
AL.DopplerFactor(value);
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float MasterVolume
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
return 1f;
|
|
|
|
//throw new NotImplementedException();
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
//throw new NotImplementedException();
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float SpeedOfSound
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
return AL.Get(ALGetFloat.SpeedOfSound);
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
AL.SpeedOfSound(value);
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-08-29 13:04:22 +00:00
|
|
|
public Creator()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
{
|
|
|
|
IntPtr deviceHandle;
|
|
|
|
ContextHandle context = Alc.GetCurrentContext();
|
|
|
|
if (context.Handle != IntPtr.Zero)
|
|
|
|
{
|
|
|
|
deviceHandle = Alc.GetContextsDevice(context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deviceHandle = Alc.OpenDevice(Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier));
|
|
|
|
context = Alc.CreateContext(deviceHandle, new int[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNowCurrent = Alc.MakeContextCurrent(context);
|
|
|
|
}
|
|
|
|
|
2012-02-12 11:28:59 +00:00
|
|
|
#region CreateSoundEffectInstance
|
2012-08-26 12:53:00 +00:00
|
|
|
public ISoundEffectInstance CreateSoundEffectInstance(ISoundEffect nativeSoundEffect)
|
2012-01-25 15:31:58 +00:00
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
|
|
|
return new OpenALSoundEffectInstance(nativeSoundEffect as OpenALSoundEffect);
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
|
|
|
#endregion
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-02-12 11:28:59 +00:00
|
|
|
#region CreateSoundEffect
|
|
|
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
2012-01-25 15:31:58 +00:00
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-02-12 11:28:59 +00:00
|
|
|
return new OpenALSoundEffect(parent, stream);
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
2012-02-12 11:28:59 +00:00
|
|
|
#endregion
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-08-29 13:04:22 +00:00
|
|
|
#region CreateSoundEffect
|
2012-08-26 12:53:00 +00:00
|
|
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate,
|
|
|
|
AudioChannels channels, int loopStart, int loopLength)
|
2012-01-25 15:31:58 +00:00
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-29 13:04:22 +00:00
|
|
|
return new OpenALSoundEffect(parent, buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
|
|
|
#endregion
|
2012-02-11 23:53:03 +00:00
|
|
|
|
2012-08-22 09:51:35 +00:00
|
|
|
#region CreateAudioListener
|
2012-02-11 23:53:03 +00:00
|
|
|
public IAudioListener CreateAudioListener()
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 09:51:35 +00:00
|
|
|
return new OpenALAudioListener();
|
2012-02-11 23:53:03 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CreateAudioEmitter (TODO)
|
|
|
|
public IAudioEmitter CreateAudioEmitter()
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-02-11 23:53:03 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
2012-08-22 14:28:22 +00:00
|
|
|
|
|
|
|
#region CreateMicrophone
|
|
|
|
public IMicrophone CreateMicrophone(Microphone managedMicrophone)
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 14:28:22 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region GetAllMicrophones
|
|
|
|
public ReadOnlyCollection<Microphone> GetAllMicrophones()
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 14:28:22 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region GetDefaultMicrophone
|
|
|
|
public int GetDefaultMicrophone(ReadOnlyCollection<Microphone> allMicrophones)
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 14:28:22 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
2012-08-26 12:53:00 +00:00
|
|
|
|
|
|
|
private void PreventSystemChange()
|
|
|
|
{
|
|
|
|
AddInSystemFactory.Instance.PreventSystemChange(AddInType.SoundSystem);
|
|
|
|
}
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
}
|