michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// michael@0: /// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound michael@0: /// samples by operating like a first-in-first-out pipe: New samples are fed michael@0: /// into one end of the pipe with the 'putSamples' function, and the processed michael@0: /// samples are received from the other end with the 'receiveSamples' function. michael@0: /// michael@0: /// 'FIFOProcessor' : A base class for classes the do signal processing with michael@0: /// the samples while operating like a first-in-first-out pipe. When samples michael@0: /// are input with the 'putSamples' function, the class processes them michael@0: /// and moves the processed samples to the given 'output' pipe object, which michael@0: /// may be either another processing stage, or a fifo sample buffer object. michael@0: /// michael@0: /// Author : Copyright (c) Olli Parviainen michael@0: /// Author e-mail : oparviai 'at' iki.fi michael@0: /// SoundTouch WWW: http://www.surina.net/soundtouch michael@0: /// michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // michael@0: // Last changed : $Date: 2012-06-13 14:29:53 -0500 (Wed, 13 Jun 2012) $ michael@0: // File revision : $Revision: 4 $ michael@0: // michael@0: // $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $ michael@0: // michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // michael@0: // License : michael@0: // michael@0: // SoundTouch audio processing library michael@0: // Copyright (c) Olli Parviainen michael@0: // michael@0: // This library is free software; you can redistribute it and/or michael@0: // modify it under the terms of the GNU Lesser General Public michael@0: // License as published by the Free Software Foundation; either michael@0: // version 2.1 of the License, or (at your option) any later version. michael@0: // michael@0: // This library is distributed in the hope that it will be useful, michael@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: // Lesser General Public License for more details. michael@0: // michael@0: // You should have received a copy of the GNU Lesser General Public michael@0: // License along with this library; if not, write to the Free Software michael@0: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA michael@0: // michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef FIFOSamplePipe_H michael@0: #define FIFOSamplePipe_H michael@0: michael@0: #include michael@0: #include michael@0: #include "STTypes.h" michael@0: michael@0: namespace soundtouch michael@0: { michael@0: michael@0: /// Abstract base class for FIFO (first-in-first-out) sample processing classes. michael@0: class FIFOSamplePipe michael@0: { michael@0: public: michael@0: // virtual default destructor michael@0: virtual ~FIFOSamplePipe() {} michael@0: michael@0: michael@0: /// Returns a pointer to the beginning of the output samples. michael@0: /// This function is provided for accessing the output samples directly. michael@0: /// Please be careful for not to corrupt the book-keeping! michael@0: /// michael@0: /// When using this function to output samples, also remember to 'remove' the michael@0: /// output samples from the buffer by calling the michael@0: /// 'receiveSamples(numSamples)' function michael@0: virtual SAMPLETYPE *ptrBegin() = 0; michael@0: michael@0: /// Adds 'numSamples' pcs of samples from the 'samples' memory position to michael@0: /// the sample buffer. michael@0: virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. michael@0: uint numSamples ///< Number of samples to insert. michael@0: ) = 0; michael@0: michael@0: michael@0: // Moves samples from the 'other' pipe instance to this instance. michael@0: void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data. michael@0: ) michael@0: { michael@0: int oNumSamples = other.numSamples(); michael@0: michael@0: putSamples(other.ptrBegin(), oNumSamples); michael@0: other.receiveSamples(oNumSamples); michael@0: }; michael@0: michael@0: /// Output samples from beginning of the sample buffer. Copies requested samples to michael@0: /// output buffer and removes them from the sample buffer. If there are less than michael@0: /// 'numsample' samples in the buffer, returns all that available. michael@0: /// michael@0: /// \return Number of samples returned. michael@0: virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. michael@0: uint maxSamples ///< How many samples to receive at max. michael@0: ) = 0; michael@0: michael@0: /// Adjusts book-keeping so that given number of samples are removed from beginning of the michael@0: /// sample buffer without copying them anywhere. michael@0: /// michael@0: /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly michael@0: /// with 'ptrBegin' function. michael@0: virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe. michael@0: ) = 0; michael@0: michael@0: /// Returns number of samples currently available. michael@0: virtual uint numSamples() const = 0; michael@0: michael@0: // Returns nonzero if there aren't any samples available for outputting. michael@0: virtual int isEmpty() const = 0; michael@0: michael@0: /// Clears all the samples. michael@0: virtual void clear() = 0; michael@0: michael@0: /// allow trimming (downwards) amount of samples in pipeline. michael@0: /// Returns adjusted amount of samples michael@0: virtual uint adjustAmountOfSamples(uint numSamples) = 0; michael@0: michael@0: }; michael@0: michael@0: michael@0: michael@0: /// Base-class for sound processing routines working in FIFO principle. With this base michael@0: /// class it's easy to implement sound processing stages that can be chained together, michael@0: /// so that samples that are fed into beginning of the pipe automatically go through michael@0: /// all the processing stages. michael@0: /// michael@0: /// When samples are input to this class, they're first processed and then put to michael@0: /// the FIFO pipe that's defined as output of this class. This output pipe can be michael@0: /// either other processing stage or a FIFO sample buffer. michael@0: class FIFOProcessor :public FIFOSamplePipe michael@0: { michael@0: protected: michael@0: /// Internal pipe where processed samples are put. michael@0: FIFOSamplePipe *output; michael@0: michael@0: /// Sets output pipe. michael@0: void setOutPipe(FIFOSamplePipe *pOutput) michael@0: { michael@0: assert(output == NULL); michael@0: assert(pOutput != NULL); michael@0: output = pOutput; michael@0: } michael@0: michael@0: michael@0: /// Constructor. Doesn't define output pipe; it has to be set be michael@0: /// 'setOutPipe' function. michael@0: FIFOProcessor() michael@0: { michael@0: output = NULL; michael@0: } michael@0: michael@0: michael@0: /// Constructor. Configures output pipe. michael@0: FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe. michael@0: ) michael@0: { michael@0: output = pOutput; michael@0: } michael@0: michael@0: michael@0: /// Destructor. michael@0: virtual ~FIFOProcessor() michael@0: { michael@0: } michael@0: michael@0: michael@0: /// Returns a pointer to the beginning of the output samples. michael@0: /// This function is provided for accessing the output samples directly. michael@0: /// Please be careful for not to corrupt the book-keeping! michael@0: /// michael@0: /// When using this function to output samples, also remember to 'remove' the michael@0: /// output samples from the buffer by calling the michael@0: /// 'receiveSamples(numSamples)' function michael@0: virtual SAMPLETYPE *ptrBegin() michael@0: { michael@0: return output->ptrBegin(); michael@0: } michael@0: michael@0: public: michael@0: michael@0: /// Output samples from beginning of the sample buffer. Copies requested samples to michael@0: /// output buffer and removes them from the sample buffer. If there are less than michael@0: /// 'numsample' samples in the buffer, returns all that available. michael@0: /// michael@0: /// \return Number of samples returned. michael@0: virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples. michael@0: uint maxSamples ///< How many samples to receive at max. michael@0: ) michael@0: { michael@0: return output->receiveSamples(outBuffer, maxSamples); michael@0: } michael@0: michael@0: michael@0: /// Adjusts book-keeping so that given number of samples are removed from beginning of the michael@0: /// sample buffer without copying them anywhere. michael@0: /// michael@0: /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly michael@0: /// with 'ptrBegin' function. michael@0: virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe. michael@0: ) michael@0: { michael@0: return output->receiveSamples(maxSamples); michael@0: } michael@0: michael@0: michael@0: /// Returns number of samples currently available. michael@0: virtual uint numSamples() const michael@0: { michael@0: return output->numSamples(); michael@0: } michael@0: michael@0: michael@0: /// Returns nonzero if there aren't any samples available for outputting. michael@0: virtual int isEmpty() const michael@0: { michael@0: return output->isEmpty(); michael@0: } michael@0: michael@0: /// allow trimming (downwards) amount of samples in pipeline. michael@0: /// Returns adjusted amount of samples michael@0: virtual uint adjustAmountOfSamples(uint numSamples) michael@0: { michael@0: return output->adjustAmountOfSamples(numSamples); michael@0: } michael@0: michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif