NScumm.Core.Audio.SoftSynth.AdlibMidiDriver.AllocateVoice C# (CSharp) Method

AllocateVoice() private method

private AllocateVoice ( byte pri ) : AdLibVoice
pri byte
return AdLibVoice
        AdLibVoice AllocateVoice(byte pri)
        {
            AdLibVoice ac, best = null;

            for (var i = 0; i < 9; i++)
            {
                if (++_voiceIndex >= 9)
                    _voiceIndex = 0;
                ac = _voices[_voiceIndex];
                if (ac.Part == null)
                    return ac;
                if (ac.Next == null)
                {
                    if (ac.Part._priEff <= pri)
                    {
                        pri = ac.Part._priEff;
                        best = ac;
                    }
                }
            }

            /* SCUMM V3 games don't have note priorities, first comes wins. */
            if (_scummSmallHeader)
                return null;

            if (best != null)
                McOff(best);
            return best;
        }