Ejemplo n.º 1
0
        /// <summary>
        /// Flushes the last samples from the processing pipeline to the output.
        /// Clears also the internal processing buffers.
        /// </summary>
        /// <remarks>
        /// This function is meant for extracting the last samples of a sound
        /// stream. This function may introduce additional blank samples in the
        /// end of the sound stream, and thus it's not recommended to call this
        /// function in the middle of a sound stream.
        /// </remarks>
        public void Flush()
        {
            var buff = new TSampletype[64 * 2]; // note: allocate 2*64 to cater 64 sample frames of stereo sound

            // check how many samples still await processing, and scale
            // that by tempo & rate to get expected output sample count
            int nUnprocessed = NumberOfUnprocessedSamples();

            nUnprocessed = (int)((double)nUnprocessed / (_tempo * _rate) + 0.5);

            int nOut = AvailableSamples;

            nOut += nUnprocessed;       // ... and how many we expect there to be in the end

            // "Push" the last active samples out from the processing pipeline by
            // feeding blank samples into the processing pipeline until new,
            // processed samples appear in the output (not however, more than
            // 8k samples in any case)
            for (int i = 0; i < 128; i++)
            {
                PutSamples(buff, 64);
                if (AvailableSamples != nOut)
                {
                    // Enough new samples have appeared into the output!
                    // As samples come from processing with bigger chunks, now truncate it
                    // back to maximum "nOut" samples to improve duration accuracy
                    AdjustAmountOfSamples(nOut);

                    // finish
                    break;
                }
            }

            // Clear working buffers
            _rateTransposer.Clear();
            _stretch.ClearInput();
            // yet leave the 'tempoChanger' output intouched as that's where the
            // flushed samples are!
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Flushes the last samples from the processing pipeline to the output.
        /// Clears also the internal processing buffers.
        /// </summary>
        /// <remarks>
        /// This function is meant for extracting the last samples of a sound
        /// stream. This function may introduce additional blank samples in the
        /// end of the sound stream, and thus it's not recommended to call this
        /// function in the middle of a sound stream.
        /// </remarks>
        public void Flush()
        {
            var buff = new TSampletype[128 * _channels];

            // how many samples are still expected to output
            int numStillExpected = (int)((long)(_samplesExpectedOut + 0.5) - _samplesOutput);

            // "Push" the last active samples out from the processing pipeline by
            // feeding blank samples into the processing pipeline until new,
            // processed samples appear in the output (not however, more than
            // 24k samples in any case)
            for (int i = 0; (numStillExpected > AvailableSamples) && (i < 200); i++)
            {
                PutSamples(buff, 128);
            }

            AdjustAmountOfSamples(numStillExpected);

            // Clear input buffers
            // _rateTransposer.Clear();
            _stretch.ClearInput();
            // yet leave the 'tempoChanger' output intouched as that's where the
            // flushed samples are!
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Flushes the last samples from the processing pipeline to the output.
        /// Clears also the internal processing buffers.
        ///</summary>
        /// <remarks>
        /// This function is meant for extracting the last samples of a sound
        /// stream. This function may introduce additional blank samples in the
        /// end of the sound stream, and thus it's not recommended to call this
        /// function in the middle of a sound stream.
        /// </remarks>
        public void Flush()
        {
            var buff = new TSampletype[128];
            int nOut = AvailableSamples;

            // "Push" the last active samples out from the processing pipeline by
            // feeding blank samples into the processing pipeline until new,
            // processed samples appear in the output (not however, more than
            // 8k samples in any case)
            for (int i = 0; i < 128; i++)
            {
                PutSamples(buff, 64);
                if (AvailableSamples != nOut)
                {
                    break;                            // new samples have appeared in the output!
                }
            }

            // Clear working buffers
            _rateTransposer.Clear();
            _stretch.ClearInput();
            // yet leave the 'tempoChanger' output intouched as that's where the
            // flushed samples are!
        }