- SoundEffect and SoundEffectInstance now have all members implemented to use the native implementation
- Started OpenAL SoundSystem
This commit is contained in:
parent
d8ab2ef4cc
commit
70f30907ff
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
@ -113,7 +114,11 @@ namespace ANX.Framework.Audio
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
private ISoundEffect nativeSoundEffect;
|
||||
internal ISoundEffect nativeSoundEffect;
|
||||
|
||||
private static List<SoundEffectInstance> fireAndForgetInstances;
|
||||
|
||||
private List<WeakReference> children = new List<WeakReference>();
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
@ -139,9 +144,17 @@ namespace ANX.Framework.Audio
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
static SoundEffect()
|
||||
{
|
||||
MasterVolume = 1f;
|
||||
SpeedOfSound = 343.5f;
|
||||
DopplerScale = 1f;
|
||||
DistanceScale = 1f;
|
||||
}
|
||||
|
||||
private SoundEffect(Stream stream)
|
||||
{
|
||||
nativeSoundEffect = GetCreator().CreateSoundEffect(stream);
|
||||
nativeSoundEffect = GetCreator().CreateSoundEffect(this, stream);
|
||||
}
|
||||
|
||||
public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
|
||||
@ -152,7 +165,7 @@ namespace ANX.Framework.Audio
|
||||
public SoundEffect(byte[] buffer, int offset, int count, int sampleRate,
|
||||
AudioChannels channels, int loopStart, int loopLength)
|
||||
{
|
||||
nativeSoundEffect = GetCreator().CreateSoundEffect(buffer, offset,
|
||||
nativeSoundEffect = GetCreator().CreateSoundEffect(this, buffer, offset,
|
||||
count, sampleRate, channels, loopStart, loopLength);
|
||||
}
|
||||
|
||||
@ -172,7 +185,7 @@ namespace ANX.Framework.Audio
|
||||
#region CreateInstance
|
||||
public SoundEffectInstance CreateInstance()
|
||||
{
|
||||
return new SoundEffectInstance(this);
|
||||
return new SoundEffectInstance(this, false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -204,7 +217,7 @@ namespace ANX.Framework.Audio
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Play (TODO)
|
||||
#region Play
|
||||
public bool Play()
|
||||
{
|
||||
return Play(1f, 0f, 0f);
|
||||
@ -212,20 +225,72 @@ namespace ANX.Framework.Audio
|
||||
|
||||
public bool Play(float volume, float pitch, float pan)
|
||||
{
|
||||
// TODO: fire and forget play
|
||||
throw new NotImplementedException();
|
||||
if (IsDisposed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SoundEffectInstance newInstance = new SoundEffectInstance(this, true)
|
||||
{
|
||||
Volume = volume,
|
||||
Pitch = pitch,
|
||||
Pan = pan,
|
||||
};
|
||||
|
||||
children.Add(new WeakReference(newInstance));
|
||||
|
||||
lock (fireAndForgetInstances)
|
||||
{
|
||||
fireAndForgetInstances.Add(newInstance);
|
||||
}
|
||||
|
||||
newInstance.Play();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed == false)
|
||||
if (IsDisposed)
|
||||
{
|
||||
IsDisposed = true;
|
||||
nativeSoundEffect.Dispose();
|
||||
nativeSoundEffect = null;
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
nativeSoundEffect.Dispose();
|
||||
nativeSoundEffect = null;
|
||||
|
||||
List<WeakReference> weakRefs = new List<WeakReference>(children);
|
||||
|
||||
lock (fireAndForgetInstances)
|
||||
{
|
||||
foreach (WeakReference current in weakRefs)
|
||||
{
|
||||
SoundEffectInstance soundInstance =
|
||||
current.Target as SoundEffectInstance;
|
||||
|
||||
if (soundInstance != null)
|
||||
{
|
||||
if (soundInstance.IsFireAndForget)
|
||||
{
|
||||
fireAndForgetInstances.Remove(soundInstance);
|
||||
}
|
||||
soundInstance.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
weakRefs.Clear();
|
||||
children.Clear();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -58,6 +58,12 @@ namespace ANX.Framework.Audio
|
||||
private SoundEffect parent;
|
||||
|
||||
private ISoundEffectInstance nativeInstance;
|
||||
|
||||
internal bool IsFireAndForget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
@ -141,11 +147,13 @@ namespace ANX.Framework.Audio
|
||||
{
|
||||
}
|
||||
|
||||
internal SoundEffectInstance(SoundEffect setParent)
|
||||
internal SoundEffectInstance(SoundEffect setParent, bool setIsFireAndForget)
|
||||
{
|
||||
parent = setParent;
|
||||
IsFireAndForget = setIsFireAndForget;
|
||||
|
||||
nativeInstance = GetCreator().CreateSoundEffectInstance(setParent);
|
||||
nativeInstance = GetCreator().CreateSoundEffectInstance(
|
||||
setParent.nativeSoundEffect);
|
||||
}
|
||||
|
||||
~SoundEffectInstance()
|
||||
|
@ -81,11 +81,12 @@ namespace ANX.Framework.NonXNA
|
||||
|
||||
IAudioEmitter CreateAudioEmitter();
|
||||
|
||||
ISoundEffect CreateSoundEffect(Stream stream);
|
||||
ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream);
|
||||
|
||||
ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count,
|
||||
int sampleRate, AudioChannels channels, int loopStart, int loopLength);
|
||||
ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset,
|
||||
int count, int sampleRate, AudioChannels channels, int loopStart,
|
||||
int loopLength);
|
||||
|
||||
ISoundEffectInstance CreateSoundEffectInstance(SoundEffect parent);
|
||||
ISoundEffectInstance CreateSoundEffectInstance(ISoundEffect nativeSoundEffect);
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,6 @@
|
||||
<HintPath>..\..\lib\OpenTK\OpenTK.Compatibility.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Creator.cs" />
|
||||
@ -54,6 +48,8 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="OpenALSoundEffect.cs" />
|
||||
<Compile Include="OpenALSoundEffectInstance.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -153,23 +153,27 @@ namespace ANX.SoundSystem.OpenAL
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateSoundEffectInstance (TODO)
|
||||
public ISoundEffectInstance CreateSoundEffectInstance(SoundEffect parent)
|
||||
#region CreateSoundEffectInstance
|
||||
public ISoundEffectInstance CreateSoundEffectInstance(
|
||||
ISoundEffect nativeSoundEffect)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
throw new NotImplementedException();
|
||||
return new OpenALSoundEffectInstance((OpenALSoundEffect)nativeSoundEffect);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateSoundEffect
|
||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
return new OpenALSoundEffect(parent, stream);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateSoundEffect (TODO)
|
||||
public ISoundEffect CreateSoundEffect(Stream stream)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count,
|
||||
int sampleRate, AudioChannels channels, int loopStart, int loopLength)
|
||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer,
|
||||
int offset, int count, int sampleRate, AudioChannels channels,
|
||||
int loopStart, int loopLength)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
throw new NotImplementedException();
|
||||
@ -179,6 +183,7 @@ namespace ANX.SoundSystem.OpenAL
|
||||
#region CreateAudioListener (TODO)
|
||||
public IAudioListener CreateAudioListener()
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
@ -186,6 +191,7 @@ namespace ANX.SoundSystem.OpenAL
|
||||
#region CreateAudioEmitter (TODO)
|
||||
public IAudioEmitter CreateAudioEmitter()
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSoundSystemChange();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
38
SoundSystems/ANX.SoundSystem.OpenAL/OpenALSoundEffect.cs
Normal file
38
SoundSystems/ANX.SoundSystem.OpenAL/OpenALSoundEffect.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
{
|
||||
public class OpenALSoundEffect : ISoundEffect
|
||||
{
|
||||
#region Private
|
||||
internal SoundEffect parent;
|
||||
#endregion
|
||||
|
||||
#region Public (TODO)
|
||||
public TimeSpan Duration
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
internal OpenALSoundEffect(SoundEffect setParent, Stream stream)
|
||||
{
|
||||
parent = setParent;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose (TODO)
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
110
SoundSystems/ANX.SoundSystem.OpenAL/OpenALSoundEffectInstance.cs
Normal file
110
SoundSystems/ANX.SoundSystem.OpenAL/OpenALSoundEffectInstance.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
{
|
||||
public class OpenALSoundEffectInstance : ISoundEffectInstance
|
||||
{
|
||||
#region Private
|
||||
private OpenALSoundEffect parent;
|
||||
#endregion
|
||||
|
||||
#region Public (TODO)
|
||||
public bool IsLooped
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public float Pan
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public float Pitch
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public SoundState State
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public float Volume
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
internal OpenALSoundEffectInstance(OpenALSoundEffect setParent)
|
||||
{
|
||||
parent = setParent;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Play()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Stop(bool immediate)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Apply3D(Framework.Audio.AudioListener[] listeners, Framework.Audio.AudioEmitter emitter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#region Dispose (TODO)
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -41,12 +41,6 @@
|
||||
<HintPath>..\..\lib\SharpDX\Bin\SharpDX.XAudio2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Creator.cs" />
|
||||
|
@ -1,15 +1,8 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
using ANX.Framework.Audio;
|
||||
|
||||
#endregion // Using Statements
|
||||
|
||||
#region License
|
||||
|
||||
@ -62,29 +55,42 @@ namespace ANX.SoundSystem.Windows.XAudio
|
||||
{
|
||||
public class Creator : ISoundSystemCreator
|
||||
{
|
||||
public void RegisterCreator(AddInSystemFactory factory)
|
||||
{
|
||||
factory.AddCreator(this);
|
||||
}
|
||||
|
||||
#region Public
|
||||
#region Name
|
||||
public string Name
|
||||
{
|
||||
get { return "XAudio"; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Priority
|
||||
public int Priority
|
||||
{
|
||||
get { return 10; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IsSupported
|
||||
public bool IsSupported
|
||||
{
|
||||
get
|
||||
{
|
||||
//TODO: this is just a very basic version of test for support
|
||||
return AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Win32NT;
|
||||
return AddInSystemFactory.Instance.OperatingSystem.Platform ==
|
||||
PlatformID.Win32NT;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region RegisterCreator
|
||||
public void RegisterCreator(AddInSystemFactory factory)
|
||||
{
|
||||
factory.AddCreator(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ISoundSystemCreator Member
|
||||
|
||||
public float DistanceScale
|
||||
{
|
||||
@ -134,38 +140,31 @@ namespace ANX.SoundSystem.Windows.XAudio
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region ISoundSystemCreator Member
|
||||
|
||||
public ISoundEffect CreateSoundEffect(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffectInstance CreateSoundEffectInstance(SoundEffect parent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateAudioListener (TODO)
|
||||
public IAudioListener CreateAudioListener()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateAudioEmitter (TODO)
|
||||
public IAudioEmitter CreateAudioEmitter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISoundEffectInstance CreateSoundEffectInstance(ISoundEffect nativeSoundEffect)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user