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;
|
2012-09-29 22:01:15 +00:00
|
|
|
using ANX.Framework.Media;
|
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
|
|
|
|
{
|
2012-09-29 22:01:15 +00:00
|
|
|
private float currentDistanceScale;
|
|
|
|
private float currentMasterVolume;
|
|
|
|
|
2012-01-25 15:31:58 +00:00
|
|
|
#region Public
|
2012-09-29 22:01:15 +00:00
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "OpenAL"; }
|
|
|
|
}
|
2012-01-25 15:31:58 +00:00
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
public int Priority
|
|
|
|
{
|
|
|
|
get { return 100; }
|
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
public bool IsSupported
|
2012-01-25 15:31:58 +00:00
|
|
|
{
|
|
|
|
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-09-29 22:01:15 +00:00
|
|
|
public float DistanceScale
|
|
|
|
{
|
|
|
|
get { return currentDistanceScale; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
currentDistanceScale = value;
|
|
|
|
// TODO: set actual property
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float DopplerScale
|
|
|
|
{
|
|
|
|
get { return AL.Get(ALGetFloat.DopplerFactor); }
|
|
|
|
set { AL.DopplerFactor(value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public float MasterVolume
|
|
|
|
{
|
|
|
|
get { return currentMasterVolume; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
currentMasterVolume = value;
|
|
|
|
// TODO: set actual property
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float SpeedOfSound
|
|
|
|
{
|
|
|
|
get { return AL.Get(ALGetFloat.SpeedOfSound); }
|
|
|
|
set { AL.SpeedOfSound(value); }
|
|
|
|
}
|
|
|
|
#endregion
|
2012-02-11 23:53:03 +00:00
|
|
|
|
2012-08-29 13:04:22 +00:00
|
|
|
public Creator()
|
|
|
|
{
|
2012-09-29 22:01:15 +00:00
|
|
|
currentDistanceScale = 1f;
|
|
|
|
currentMasterVolume = 1f;
|
2012-08-29 13:04:22 +00:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
private static void Init()
|
|
|
|
{
|
|
|
|
ContextHandle context = Alc.GetCurrentContext();
|
|
|
|
if (context.Handle == IntPtr.Zero)
|
|
|
|
{
|
|
|
|
string deviceName = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
|
|
|
|
IntPtr deviceHandle = Alc.OpenDevice(deviceName);
|
|
|
|
context = Alc.CreateContext(deviceHandle, new int[0]);
|
|
|
|
}
|
2012-08-29 13:04:22 +00:00
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
Alc.MakeContextCurrent(context);
|
|
|
|
}
|
2012-08-29 13:04:22 +00:00
|
|
|
|
2012-09-29 22:01:15 +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-10-04 07:07:18 +00:00
|
|
|
return new OpenALSoundEffect(stream);
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
|
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-10-04 07:07:18 +00:00
|
|
|
return new OpenALSoundEffect(buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
2012-10-05 20:41:18 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CreateDynamicSoundEffectInstance
|
|
|
|
public IDynamicSoundEffectInstance CreateDynamicSoundEffectInstance(int sampleRate, AudioChannels channels)
|
|
|
|
{
|
|
|
|
PreventSystemChange();
|
|
|
|
return new OpenALDynamicSoundEffectInstance(sampleRate, channels);
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
2012-10-05 20:41:18 +00:00
|
|
|
#region CreateMicrophone (TODO)
|
2012-08-22 14:28:22 +00:00
|
|
|
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
|
|
|
|
|
2012-10-05 20:41:18 +00:00
|
|
|
#region GetAllMicrophones (TODO)
|
|
|
|
public ReadOnlyCollection<Microphone> GetAllMicrophones()
|
2012-08-22 14:28:22 +00:00
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 14:28:22 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-10-05 20:41:18 +00:00
|
|
|
#region GetDefaultMicrophone (TODO)
|
|
|
|
public int GetDefaultMicrophone(ReadOnlyCollection<Microphone> allMicrophones)
|
2012-08-22 14:28:22 +00:00
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
PreventSystemChange();
|
2012-08-22 14:28:22 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2012-09-29 22:01:15 +00:00
|
|
|
#endregion
|
|
|
|
|
2012-10-05 20:41:18 +00:00
|
|
|
#region CreateSong
|
2012-09-29 22:01:15 +00:00
|
|
|
public ISong CreateSong(Song parentSong, Uri uri)
|
2012-09-30 08:28:17 +00:00
|
|
|
{
|
|
|
|
PreventSystemChange();
|
2012-10-10 10:48:19 +00:00
|
|
|
return new OpenALSong(uri);
|
2012-10-03 20:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ISong CreateSong(Song parentSong, string filepath, int duration)
|
|
|
|
{
|
|
|
|
PreventSystemChange();
|
2012-10-10 10:48:19 +00:00
|
|
|
return new OpenALSong(filepath, duration);
|
2012-09-30 08:28:17 +00:00
|
|
|
}
|
2012-10-05 20:41:18 +00:00
|
|
|
#endregion
|
2012-08-26 12:53:00 +00:00
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
private static void PreventSystemChange()
|
2012-08-26 12:53:00 +00:00
|
|
|
{
|
|
|
|
AddInSystemFactory.Instance.PreventSystemChange(AddInType.SoundSystem);
|
|
|
|
}
|
2012-01-25 15:31:58 +00:00
|
|
|
}
|
2011-12-01 08:47:54 +00:00
|
|
|
}
|