remove a bunch of explicit uses of '/' as a directory separator; use Glib::build_file...
[ardour2.git] / libs / soundtouch / FIFOSamplePipe.h
blobbf42895c2612eea244c222674a1c675ae9cbc24b
1 ////////////////////////////////////////////////////////////////////////////////
2 ///
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.
7 ///
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.
13 ///
14 /// Author : Copyright (c) Olli Parviainen
15 /// Author e-mail : oparviai @ iki.fi
16 /// SoundTouch WWW: http://www.iki.fi/oparviai/soundtouch
17 ///
18 ////////////////////////////////////////////////////////////////////////////////
20 // Last changed : $Date$
21 // File revision : $Revision$
23 // $Id$
25 ////////////////////////////////////////////////////////////////////////////////
27 // License :
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
51 #include <cassert>
52 #include <cstdlib>
53 #include "STTypes.h"
55 namespace soundtouch
58 /// Abstract base class for FIFO (first-in-first-out) sample processing classes.
59 class FIFOSamplePipe
61 public:
62 virtual ~FIFOSamplePipe () {};
63 /// Returns a pointer to the beginning of the output samples.
64 /// This function is provided for accessing the output samples directly.
65 /// Please be careful for not to corrupt the book-keeping!
66 ///
67 /// When using this function to output samples, also remember to 'remove' the
68 /// output samples from the buffer by calling the
69 /// 'receiveSamples(numSamples)' function
70 virtual SAMPLETYPE *ptrBegin() const = 0;
72 /// Adds 'numSamples' pcs of samples from the 'samples' memory position to
73 /// the sample buffer.
74 virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples.
75 uint numSamples ///< Number of samples to insert.
76 ) = 0;
79 // Moves samples from the 'other' pipe instance to this instance.
80 void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data.
83 int oNumSamples = other.numSamples();
85 putSamples(other.ptrBegin(), oNumSamples);
86 other.receiveSamples(oNumSamples);
89 /// Output samples from beginning of the sample buffer. Copies requested samples to
90 /// output buffer and removes them from the sample buffer. If there are less than
91 /// 'numsample' samples in the buffer, returns all that available.
92 ///
93 /// \return Number of samples returned.
94 virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
95 uint maxSamples ///< How many samples to receive at max.
96 ) = 0;
98 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
99 /// sample buffer without copying them anywhere.
101 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
102 /// with 'ptrBegin' function.
103 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
104 ) = 0;
106 /// Returns number of samples currently available.
107 virtual uint numSamples() const = 0;
109 // Returns nonzero if there aren't any samples available for outputting.
110 virtual int isEmpty() const = 0;
112 /// Clears all the samples.
113 virtual void clear() = 0;
118 /// Base-class for sound processing routines working in FIFO principle. With this base
119 /// class it's easy to implement sound processing stages that can be chained together,
120 /// so that samples that are fed into beginning of the pipe automatically go through
121 /// all the processing stages.
123 /// When samples are input to this class, they're first processed and then put to
124 /// the FIFO pipe that's defined as output of this class. This output pipe can be
125 /// either other processing stage or a FIFO sample buffer.
126 class FIFOProcessor :public FIFOSamplePipe
128 protected:
129 /// Internal pipe where processed samples are put.
130 FIFOSamplePipe *output;
132 /// Sets output pipe.
133 void setOutPipe(FIFOSamplePipe *pOutput)
135 assert(output == NULL);
136 assert(pOutput != NULL);
137 output = pOutput;
141 /// Constructor. Doesn't define output pipe; it has to be set be
142 /// 'setOutPipe' function.
143 FIFOProcessor()
145 output = NULL;
149 /// Constructor. Configures output pipe.
150 FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe.
153 output = pOutput;
157 /// Destructor.
158 virtual ~FIFOProcessor()
163 /// Returns a pointer to the beginning of the output samples.
164 /// This function is provided for accessing the output samples directly.
165 /// Please be careful for not to corrupt the book-keeping!
167 /// When using this function to output samples, also remember to 'remove' the
168 /// output samples from the buffer by calling the
169 /// 'receiveSamples(numSamples)' function
170 virtual SAMPLETYPE *ptrBegin() const
172 return output->ptrBegin();
175 public:
177 /// Output samples from beginning of the sample buffer. Copies requested samples to
178 /// output buffer and removes them from the sample buffer. If there are less than
179 /// 'numsample' samples in the buffer, returns all that available.
181 /// \return Number of samples returned.
182 virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
183 uint maxSamples ///< How many samples to receive at max.
186 return output->receiveSamples(outBuffer, maxSamples);
190 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
191 /// sample buffer without copying them anywhere.
193 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
194 /// with 'ptrBegin' function.
195 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
198 return output->receiveSamples(maxSamples);
202 /// Returns number of samples currently available.
203 virtual uint numSamples() const
205 return output->numSamples();
209 /// Returns nonzero if there aren't any samples available for outputting.
210 virtual int isEmpty() const
212 return output->isEmpty();
218 #endif