Пример #1
0
        public VoiceManager(int voiceCount)
        {
            StealingMethod = VoiceStealingMethod.Quietest;
            Polyphony = voiceCount;

            _voicePool = new Voice[voiceCount];
            _vNodes = new LinkedList<VoiceNode>();
            FreeVoices = new LinkedList<Voice>();
            ActiveVoices = new LinkedList<Voice>();

            for (int i = 0; i < voiceCount; i++)
            {
                var v = new Voice();
                _voicePool[i] = v;
                _vNodes.AddLast(new VoiceNode());
                FreeVoices.AddLast(v);
            }

            Registry = new VoiceNode[SynthConstants.DefaultChannelCount][];
            for (int i = 0; i < Registry.Length; i++)
            {
                Registry[i] = new VoiceNode[SynthConstants.DefaultKeyCount];
            }
        }
Пример #2
0
 public void AddToRegistry(Voice voice)
 {
     var node = _vNodes.RemoveLast();
     node.Value = voice;
     node.Next = Registry[voice.VoiceParams.Channel][voice.VoiceParams.Note];
     Registry[voice.VoiceParams.Channel][voice.VoiceParams.Note] = node;
 }
Пример #3
0
 public void RemoveVoiceFromRegistry(Voice voice)
 {
     var node = Registry[voice.VoiceParams.Channel][voice.VoiceParams.Note];
     if (node == null)
         return;
     if (node.Value == voice)
     {
         Registry[voice.VoiceParams.Channel][voice.VoiceParams.Note] = node.Next;
         _vNodes.AddLast(node);
     }
     else
     {
         var node2 = node;
         node = node.Next;
         while (node != null)
         {
             if (node.Value == voice)
             {
                 node2.Next = node.Next;
                 _vNodes.AddLast(node);
                 return;
             }
             node2 = node;
             node = node.Next;
         }
     }
 }