MoonWorks/src/Audio/StaticVoice.cs

55 lines
1.3 KiB
C#

namespace MoonWorks.Audio
{
public class StaticVoice : SourceVoice, IPoolable<StaticVoice>
{
/// <summary>
/// Indicates if the voice should return to the voice pool when the voice is idle.
/// If you set this and then hold on to the voice reference there will be problems!
/// </summary>
public bool DeactivateWhenIdle { get; set; }
public static StaticVoice Create(AudioDevice device, Format format)
{
return new StaticVoice(device, format);
}
public StaticVoice(AudioDevice device, Format format) : base(device, format)
{
}
public override void Update()
{
lock (StateLock)
{
if (DeactivateWhenIdle)
{
if (BuffersQueued == 0)
{
Return();
}
}
}
}
/// <summary>
/// Adds a static sound to the voice queue.
/// The voice processes and plays back the buffers in its queue in the order that they were submitted.
/// </summary>
/// <param name="sound">The sound to submit to the voice.</param>
/// <param name="loop">Designates that the voice will loop the submitted buffer.</param>
public void Submit(StaticSound sound, bool loop = false)
{
if (loop)
{
sound.Buffer.LoopCount = FAudio.FAUDIO_LOOP_INFINITE;
}
else
{
sound.Buffer.LoopCount = 0;
}
Submit(sound.Buffer);
}
}
}