示例#1
0
 static Track()
 {
     Tones       = new Tone[Constants.MaxToneCount];
     FreqTable   = Enumerable.Range(0, 128).Select(GetFreq).ToArray();
     AudioTimers = new AudioTimer[Constants.MaxToneCount];
     for (var i = 0; i < AudioTimers.Length; i++)
     {
         AudioTimers[i] = new AudioTimer();
     }
 }
示例#2
0
            public (short, short) Process(int index, int sampleRate)
            {
                Tone       t  = Tones[index];
                AudioTimer at = AudioTimers[index];

                (short, short)output = (0, 0);
                if (t == null)
                {
                    return(output);
                }
                IInstrument il;

                il = t.Channel == 9 ? GetDrumsets().FindInstruments(t.NoteNum, t.Velocity).FirstOrDefault() : GetCurrentInstrument();


                if (il == null)
                {
                    return(output);
                }

                var panrt = Channel.Panpot * 0.0078f;
                var a     = 4f / Tones.Length;

                if (t.Channel == 9)
                {
                    a *= 2;
                }

                var kake = (Channel.Volume * 0.0078f) * (Channel.Expression * 0.0078f) * (t.Velocity * 0.0078f) * a;

                var freq = FreqTable[t.NoteNum] * Channel.FreqExts;

                t.Frequency = (int)freq;
                if (t.Channel == 9)
                {
                    freq = 441 * Channel.FreqExts;
                }
                at.SetCycle(freq, sampleRate);

                output       = il.Source.GetSample(t.SampleTick, sampleRate, t);
                output.Item1 = (short)(output.Item1 * kake * (1 - panrt));
                output.Item2 = (short)(output.Item2 * kake * panrt);

                t.SampleTick = (int)at.Update();
                return(output);
            }