40 lines
725 B
C#
40 lines
725 B
C#
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace MoonWorks.Audio
|
||
|
{
|
||
|
internal class SourceVoicePool
|
||
|
{
|
||
|
private AudioDevice Device;
|
||
|
|
||
|
Dictionary<Format, Queue<SourceVoice>> VoiceLists = new Dictionary<Format, Queue<SourceVoice>>();
|
||
|
|
||
|
public SourceVoicePool(AudioDevice device)
|
||
|
{
|
||
|
Device = device;
|
||
|
}
|
||
|
|
||
|
public SourceVoice Obtain(Format format)
|
||
|
{
|
||
|
if (!VoiceLists.ContainsKey(format))
|
||
|
{
|
||
|
VoiceLists.Add(format, new Queue<SourceVoice>());
|
||
|
}
|
||
|
|
||
|
var list = VoiceLists[format];
|
||
|
|
||
|
if (list.Count == 0)
|
||
|
{
|
||
|
list.Enqueue(new SourceVoice(Device, format));
|
||
|
}
|
||
|
|
||
|
return list.Dequeue();
|
||
|
}
|
||
|
|
||
|
public void Return(SourceVoice voice)
|
||
|
{
|
||
|
var list = VoiceLists[voice.Format];
|
||
|
list.Enqueue(voice);
|
||
|
}
|
||
|
}
|
||
|
}
|