Exemplo n.º 1
0
        public override void Process(float[] buffer)
        {
            var temp = BufferControl.RequestBuffer();

            Component.Process(temp);

            if (IsStereo)
            {
                var tempRight = BufferControl.RequestBuffer();
                RightComponent.Process(tempRight);

                for (int i = 0; i < buffer.Length; i += 2)
                {
                    buffer[i]     += temp[i >> 1] * (float)LeftGain;
                    buffer[i + 1] += tempRight[i >> 1] * (float)RightGain;
                }

                BufferControl.FreeBuffer(tempRight);
            }
            else
            {
                for (int i = 0; i < buffer.Length; i += 2)
                {
                    buffer[i]     += temp[i >> 1] * (float)LeftGain;
                    buffer[i + 1] += temp[i >> 1] * (float)RightGain;
                }
            }

            BufferControl.FreeBuffer(temp);
        }
Exemplo n.º 2
0
        public override void Process(float[] buffer)
        {
            if (!IsOn && releaseCounter <= 0)
            {
                // Off and released
                System.Array.Clear(buffer, 0, buffer.Length);
                return;
            }

            Source.Process(buffer);

            // On
            if (IsOn)
            {
                return;
            }

            // Off but not released
            for (int i = 0; i < buffer.Length; i++)
            {
                if (releaseCounter <= 0)
                {
                    System.Array.Clear(buffer, i, buffer.Length - i);
                    return;
                }

                buffer[i] *= (float)releaseCounter / releaseSample;

                --releaseCounter;
            }
        }
Exemplo n.º 3
0
        public override void Process(float[] buffer)
        {
            var lfoTemp = BufferControl.RequestBuffer();

            Lfo.Process(lfoTemp);
            Envelope.Process(buffer);

            if (ModBuffer != null)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] *= (float)(Math.Sin(phase + feedback + ModBuffer[i]) * (1 - (lfoTemp[i] + 1) * lfoAmpGain * 0.5));
                    feedback   = buffer[i] * FeedbackRatio;

                    phase += phaseStep * Math.Pow(lfoPitchGain, lfoTemp[i]);
                    if (phase >= Pi2)
                    {
                        phase -= Pi2;
                    }

                    buffer[i] *= (float)outputGain;
                }
            }
            else
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] *= (float)(Math.Sin(phase + feedback) * (1 - (lfoTemp[i] + 1) * lfoAmpGain * 0.5));
                    feedback   = buffer[i] * FeedbackRatio;

                    phase += phaseStep * Math.Pow(lfoPitchGain, lfoTemp[i]);
                    if (phase >= Pi2)
                    {
                        phase -= Pi2;
                    }

                    buffer[i] *= (float)outputGain;
                }
            }

            BufferControl.FreeBuffer(lfoTemp);
        }
Exemplo n.º 4
0
        public override void Process(float[] buffer)
        {
            if (!IsOn && offCounter >= releaseSample)
            {
                // Off and offed
                System.Array.Clear(buffer, 0, buffer.Length);
                return;
            }

            Source.Process(buffer);

            // On and oned
            if (IsOn && onCounter >= onLength)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] *= (float)Sustain;
                }
                return;
            }

            // On but not oned
            if (IsOn)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (onCounter <= attackSample)
                    {
                        buffer[i] *= (float)onCounter / attackSample;
                    }
                    else if (onCounter > attackSample + holdSample)
                    {
                        buffer[i] *= (float)(1 - decayDrop * (onCounter - attackSample - holdSample) / decaySample);
                    }

                    ++onCounter;

                    if (onCounter >= onLength)
                    {
                        // Fast forward
                        for (i = i + 1; i < buffer.Length; i++)
                        {
                            buffer[i] *= (float)Sustain;
                        }
                        return;
                    }
                }
            }
            else
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (offCounter >= releaseSample)
                    {
                        System.Array.Clear(buffer, i, buffer.Length - i);
                        return;
                    }

                    buffer[i] *= (float)releaseDrop * (1 - (float)offCounter / releaseSample);

                    ++offCounter;
                }
            }
        }