2012-02-12 11:28:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using ANX.Framework.Audio;
|
|
|
|
|
using ANX.Framework.NonXNA.SoundSystem;
|
2012-08-26 12:53:00 +00:00
|
|
|
|
using OpenTK.Audio;
|
|
|
|
|
|
|
|
|
|
// 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
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
|
|
|
|
namespace ANX.SoundSystem.OpenAL
|
|
|
|
|
{
|
|
|
|
|
public class OpenALSoundEffectInstance : ISoundEffectInstance
|
|
|
|
|
{
|
|
|
|
|
#region Private
|
|
|
|
|
private OpenALSoundEffect parent;
|
2012-08-26 12:53:00 +00:00
|
|
|
|
|
|
|
|
|
private int handle;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Public
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public bool IsLooped
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
bool result;
|
|
|
|
|
AL.GetSource(handle, ALSourceb.Looping, out result);
|
|
|
|
|
return result;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
AL.Source(handle, ALSourceb.Looping, value);
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Pan
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
|
return 0f;
|
|
|
|
|
//throw new NotImplementedException();
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2012-08-29 13:04:22 +00:00
|
|
|
|
//throw new NotImplementedException();
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Pitch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
float result;
|
|
|
|
|
AL.GetSource(handle, ALSourcef.Pitch, out result);
|
|
|
|
|
return result;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
AL.Source(handle, ALSourcef.Pitch, value);
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SoundState State
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Volume
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
float result;
|
|
|
|
|
AL.GetSource(handle, ALSourcef.Gain, out result);
|
|
|
|
|
return result;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
AL.Source(handle, ALSourcef.Gain, value);
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
internal OpenALSoundEffectInstance(OpenALSoundEffect setParent)
|
|
|
|
|
{
|
|
|
|
|
parent = setParent;
|
2012-08-26 12:53:00 +00:00
|
|
|
|
|
|
|
|
|
State = SoundState.Stopped;
|
|
|
|
|
|
|
|
|
|
handle = AL.GenSource();
|
|
|
|
|
AL.Source(handle, ALSourcei.Buffer, parent.bufferHandle);
|
|
|
|
|
IsLooped = false;
|
|
|
|
|
Pitch = 1f;
|
|
|
|
|
Volume = 1f;
|
|
|
|
|
// TODO: Pan = 0f;
|
2012-08-29 13:04:22 +00:00
|
|
|
|
|
|
|
|
|
ALError error = AL.GetError();
|
|
|
|
|
if (error != ALError.NoError)
|
|
|
|
|
throw new Exception("OpenAL error " + error + ": " + AL.GetErrorString(error));
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Play
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public void Play()
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
if (State != SoundState.Playing)
|
|
|
|
|
{
|
|
|
|
|
State = SoundState.Playing;
|
|
|
|
|
AL.SourcePlay(handle);
|
|
|
|
|
}
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#endregion
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Pause
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public void Pause()
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
if (State != SoundState.Paused)
|
|
|
|
|
{
|
|
|
|
|
State = SoundState.Paused;
|
|
|
|
|
AL.SourcePause(handle);
|
|
|
|
|
}
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#endregion
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Stop
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public void Stop(bool immediate)
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
if (State == SoundState.Stopped)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (immediate)
|
|
|
|
|
{
|
|
|
|
|
State = SoundState.Stopped;
|
|
|
|
|
AL.SourceStop(handle);
|
|
|
|
|
}
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#endregion
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Resume
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public void Resume()
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
if (State != SoundState.Playing)
|
|
|
|
|
{
|
|
|
|
|
State = SoundState.Playing;
|
|
|
|
|
AL.SourcePlay(handle);
|
|
|
|
|
}
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#endregion
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Apply3D (TODO)
|
|
|
|
|
public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
|
2012-02-12 11:28:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#endregion
|
2012-02-12 11:28:59 +00:00
|
|
|
|
|
2012-08-26 12:53:00 +00:00
|
|
|
|
#region Dispose
|
2012-02-12 11:28:59 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2012-08-26 12:53:00 +00:00
|
|
|
|
AL.DeleteSource(handle);
|
|
|
|
|
handle = -1;
|
2012-02-12 11:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|