/// <summary>
        /// Transposes down the sample rate, causing the observed playback
        /// 'rate' of the sound to increase
        /// </summary>
        private void Downsample(ArrayPtr <TSampleType> src, int numSamples)
        {
            // If the parameter 'uRate' value is larger than 'SCALE', first apply the
            // anti-alias filter to remove high frequencies (prevent them from folding
            // over the lover frequencies), then transpose.

            // Add the new samples to the end of the storeBuffer
            _storeBuffer.PutSamples(src, numSamples);

            // Anti-alias filter the samples to prevent folding and output the filtered
            // data to tempBuffer. Note : because of the FIR filter length, the
            // filtering routine takes in 'filter_length' more samples than it outputs.
            Debug.Assert(_tempBuffer.IsEmpty);
            var sizeTemp = _storeBuffer.AvailableSamples;

            int count = _antiAliasFilter.Evaluate(_tempBuffer.PtrEnd(sizeTemp), _storeBuffer.PtrBegin(), sizeTemp, _channels);

            if (count == 0)
            {
                return;
            }

            // Remove the filtered samples from 'storeBuffer'
            _storeBuffer.ReceiveSamples(count);

            // Transpose the samples (+16 is to reserve some slack in the destination buffer)
            sizeTemp = (int)(numSamples / Rate + 16.0f);
            count    = Transpose(_outputBuffer.PtrEnd(sizeTemp), _tempBuffer.PtrBegin(), count);
            _outputBuffer.PutSamples(count);
        }
예제 #2
0
        /// <summary>
        /// Transposes sample rate by applying anti-alias filter to prevent
        /// folding.  Returns amount of samples returned in the
        /// <see cref="_outputBuffer"/> buffer.
        /// </summary>
        private void ProcessSamples(ArrayPtr <TSampleType> src, int numSamples)
        {
            if (numSamples == 0)
            {
                return;
            }

            // Store samples to input buffer
            _inputBuffer.PutSamples(src, numSamples);

            // If anti-alias filter is turned off, simply transpose without applying
            // the filter
            if (!_useAliasFilter)
            {
                int count = _transposer.Transpose(_outputBuffer, _inputBuffer);

                return;
            }

            Debug.Assert(_antiAliasFilter != null);

            // Transpose with anti-alias filter
            if (_transposer.rate < 1.0f)
            {
                // If the parameter 'Rate' value is smaller than 1, first transpose
                // the samples and then apply the anti-alias filter to remove aliasing.

                // Transpose the samples, store the result to end of "midBuffer"
                _transposer.Transpose(_midBuffer, _inputBuffer);

                // Apply the anti-alias filter for transposed samples in midBuffer
                _antiAliasFilter.Evaluate(_outputBuffer, _midBuffer);
            }
            else
            {
                // If the parameter 'Rate' value is larger than 1, first apply the
                // anti-alias filter to remove high frequencies (prevent them from folding
                // over the lover frequencies), then transpose.

                // Apply the anti-alias filter for samples in inputBuffer
                _antiAliasFilter.Evaluate(_midBuffer, _inputBuffer);

                // Transpose the AA-filtered samples in "midBuffer"
                _transposer.Transpose(_outputBuffer, _midBuffer);
            }
        }