Ejemplo n.º 1
0
        public override int Read(float[] buffer, int offset, int count, uint frame)
        {
            //ResetByFrame(frame);	// TODO

            // Get input samples
            if (inputBuffer.Length < count)
            {
                inputBuffer = new float[count];
            }
            count = InputSampleProvider.Read(inputBuffer, 0, count, frame);

            // Convolve each input sample with the filter coefficients
            float outputSample;

            for (int i = 0; i < count; i++)
            {
                // Load one sample into the circle buffer (overwriting the oldest sample)
                inputCircleBuffer.Write(inputBuffer[i]);

                outputSample = 0f;
                int oldestInputOffset = 2 * filterCoefficients.Length - 1;                  // The offset of the last input sample
                for (int j = 0; j < filterCoefficients.Length; j++)
                {
                    // Fold two input samples together and multiply by the filter coefficient
                    outputSample += (inputCircleBuffer.Read(j) +
                                     inputCircleBuffer.Read(oldestInputOffset - j)) * filterCoefficients[j];
                }

                // Put the output sample in the output buffer
                buffer[i + offset] = outputSample;
            }

            return(count);
        }
Ejemplo n.º 2
0
        public override int Read(float[] buffer, int offset, int count, uint frame)
        {
            //ResetByFrame(frame);

            // Grow input buffer and get samples
            if (inputBuffer.Length < count)
            {
                inputBuffer = new float[count];
            }
            InputSampleProvider.Read(inputBuffer, 0, count, frame);

            // Generate echoes
            float outputSample;

            for (int i = 0; i < count; i++)
            {
                // Adjust echo volume
                amplitude = AmplitudeSmoothing * amplitude + (1f - AmplitudeSmoothing) * amplitudeTarget;

                // Adjust delay
                if (delaySamples < delaySamplesTarget)
                {
                    delaySamples++;
                }
                else if (delaySamples > delaySamplesTarget)
                {
                    delaySamples--;
                }

                // Read the oldest sample, mix it with the input and write it back to the circle buffer
                outputSample = amplitude * echoCircleBuffer.Read(delaySamples) + inputBuffer[i];
                echoCircleBuffer.Write(outputSample);

                buffer[i + offset] = outputSample;
            }

            return(count);
        }