1 ////////////////////////////////////////////////////////////////////////////////
3 /// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound
4 /// samples by operating like a first-in-first-out pipe: New samples are fed
5 /// into one end of the pipe with the 'putSamples' function, and the processed
6 /// samples are received from the other end with the 'receiveSamples' function.
8 /// 'FIFOProcessor' : A base class for classes the do signal processing with
9 /// the samples while operating like a first-in-first-out pipe. When samples
10 /// are input with the 'putSamples' function, the class processes them
11 /// and moves the processed samples to the given 'output' pipe object, which
12 /// may be either another processing stage, or a fifo sample buffer object.
14 /// Author : Copyright (c) Olli Parviainen
15 /// Author e-mail : oparviai @ iki.fi
16 /// SoundTouch WWW: http://www.iki.fi/oparviai/soundtouch
18 ////////////////////////////////////////////////////////////////////////////////
20 // Last changed : $Date$
21 // File revision : $Revision$
25 ////////////////////////////////////////////////////////////////////////////////
29 // SoundTouch audio processing library
30 // Copyright (c) Olli Parviainen
32 // This library is free software; you can redistribute it and/or
33 // modify it under the terms of the GNU Lesser General Public
34 // License as published by the Free Software Foundation; either
35 // version 2.1 of the License, or (at your option) any later version.
37 // This library is distributed in the hope that it will be useful,
38 // but WITHOUT ANY WARRANTY; without even the implied warranty of
39 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 // Lesser General Public License for more details.
42 // You should have received a copy of the GNU Lesser General Public
43 // License along with this library; if not, write to the Free Software
44 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 ////////////////////////////////////////////////////////////////////////////////
48 #ifndef FIFOSamplePipe_H
49 #define FIFOSamplePipe_H
58 /// Abstract base class for FIFO (first-in-first-out) sample processing classes.
62 /// Returns a pointer to the beginning of the output samples.
63 /// This function is provided for accessing the output samples directly.
64 /// Please be careful for not to corrupt the book-keeping!
66 /// When using this function to output samples, also remember to 'remove' the
67 /// output samples from the buffer by calling the
68 /// 'receiveSamples(numSamples)' function
69 virtual SAMPLETYPE *ptrBegin() const = 0;
71 /// Adds 'numSamples' pcs of samples from the 'samples' memory position to
72 /// the sample buffer.
73 virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples.
74 uint numSamples ///< Number of samples to insert.
78 // Moves samples from the 'other' pipe instance to this instance.
79 void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data.
82 int oNumSamples = other.numSamples();
84 putSamples(other.ptrBegin(), oNumSamples);
85 other.receiveSamples(oNumSamples);
88 /// Output samples from beginning of the sample buffer. Copies requested samples to
89 /// output buffer and removes them from the sample buffer. If there are less than
90 /// 'numsample' samples in the buffer, returns all that available.
92 /// \return Number of samples returned.
93 virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
94 uint maxSamples ///< How many samples to receive at max.
97 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
98 /// sample buffer without copying them anywhere.
100 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
101 /// with 'ptrBegin' function.
102 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
105 /// Returns number of samples currently available.
106 virtual uint numSamples() const = 0;
108 // Returns nonzero if there aren't any samples available for outputting.
109 virtual int isEmpty() const = 0;
111 /// Clears all the samples.
112 virtual void clear() = 0;
117 /// Base-class for sound processing routines working in FIFO principle. With this base
118 /// class it's easy to implement sound processing stages that can be chained together,
119 /// so that samples that are fed into beginning of the pipe automatically go through
120 /// all the processing stages.
122 /// When samples are input to this class, they're first processed and then put to
123 /// the FIFO pipe that's defined as output of this class. This output pipe can be
124 /// either other processing stage or a FIFO sample buffer.
125 class FIFOProcessor :public FIFOSamplePipe
128 /// Internal pipe where processed samples are put.
129 FIFOSamplePipe *output;
131 /// Sets output pipe.
132 void setOutPipe(FIFOSamplePipe *pOutput)
134 assert(output == NULL);
135 assert(pOutput != NULL);
140 /// Constructor. Doesn't define output pipe; it has to be set be
141 /// 'setOutPipe' function.
148 /// Constructor. Configures output pipe.
149 FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe.
157 virtual ~FIFOProcessor()
162 /// Returns a pointer to the beginning of the output samples.
163 /// This function is provided for accessing the output samples directly.
164 /// Please be careful for not to corrupt the book-keeping!
166 /// When using this function to output samples, also remember to 'remove' the
167 /// output samples from the buffer by calling the
168 /// 'receiveSamples(numSamples)' function
169 virtual SAMPLETYPE *ptrBegin() const
171 return output->ptrBegin();
176 /// Output samples from beginning of the sample buffer. Copies requested samples to
177 /// output buffer and removes them from the sample buffer. If there are less than
178 /// 'numsample' samples in the buffer, returns all that available.
180 /// \return Number of samples returned.
181 virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
182 uint maxSamples ///< How many samples to receive at max.
185 return output->receiveSamples(outBuffer, maxSamples);
189 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
190 /// sample buffer without copying them anywhere.
192 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
193 /// with 'ptrBegin' function.
194 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
197 return output->receiveSamples(maxSamples);
201 /// Returns number of samples currently available.
202 virtual uint numSamples() const
204 return output->numSamples();
208 /// Returns nonzero if there aren't any samples available for outputting.
209 virtual int isEmpty() const
211 return output->isEmpty();