Esempio n. 1
0
        public void Process(float[,] workingBuffer)
        {
            if (IsAlive)
            {
                int samplesPerBuffer = workingBuffer.GetLength(1);
                for (int i = 0; i < samplesPerBuffer; i++)
                {
                    if (_state == VoiceState.Attack)
                    {
                        _fadeMultiplier = (float)_fadeCounter / _synth.FadeInDuration;

                        ++_fadeCounter;
                        if (_fadeCounter >= _synth.FadeInDuration)
                        {
                            _state = VoiceState.Sustain;
                        }
                    }
                    else if (_state == VoiceState.Release)
                    {
                        _fadeMultiplier = 1.0f - (float)_fadeCounter / _synth.FadeOutDuration;

                        ++_fadeCounter;
                        if (_fadeCounter >= _synth.FadeOutDuration)
                        {
                            IsAlive = false;
                            return;
                        }
                    }
                    else
                    {
                        _fadeMultiplier = 1.0f;
                    }

                    float sample = _synth.Oscillator(_frequency + (10 * _synth.PitchBend), ref _time);
                    workingBuffer[0, i] += sample * 0.2f * _fadeMultiplier;
                    _time += 1.0f / Synth.SampleRate;
                }
            }
        }