private void FillWorkingBuffer()
{
/*Break the process loop into sections representing the smallest timeframe before the midi controls need to be updated
the bigger the timeframe the more efficent the process is, but playback quality will be reduced.*/
var sampleIndex = 0;
for (int x = 0; x < MicroBufferCount; x++)
{
if (MidiEventQueue.Length > 0)
{
for (int i = 0; i < MidiEventCounts[x]; i++)
{
var m = MidiEventQueue.RemoveLast();
ProcessMidiMessage(m.Event);
}
}
//voice processing loop
var node = _voiceManager.ActiveVoices.First; //node used to traverse the active voices
while (node != null)
{
node.Value.Process(sampleIndex, sampleIndex + MicroBufferSize * AudioChannels);
//if an active voice has stopped remove it from the list
if (node.Value.VoiceParams.State == VoiceStateEnum.Stopped)
{
var delnode = node; //node used to remove inactive voices
node = node.Next;
_voiceManager.RemoveVoiceFromRegistry(delnode.Value);
_voiceManager.ActiveVoices.Remove(delnode);
_voiceManager.FreeVoices.AddFirst(delnode.Value);
}
else
{
node = node.Next;
}
}
sampleIndex += MicroBufferSize * AudioChannels;
}
TypeUtils.ClearIntArray(MidiEventCounts);
}