using System.Collections.Generic; namespace MoonWorks.Audio { internal class SourceVoicePool { private AudioDevice Device; Dictionary<(System.Type, Format), Queue> VoiceLists = new Dictionary<(System.Type, Format), Queue>(); public SourceVoicePool(AudioDevice device) { Device = device; } public T Obtain(Format format) where T : SourceVoice, IPoolable { if (!VoiceLists.ContainsKey((typeof(T), format))) { VoiceLists.Add((typeof(T), format), new Queue()); } var list = VoiceLists[(typeof(T), format)]; if (list.Count == 0) { list.Enqueue(T.Create(Device, format)); } return (T) list.Dequeue(); } public void Return(SourceVoice voice) { var list = VoiceLists[(voice.GetType(), voice.Format)]; list.Enqueue(voice); } } }