/[pcsx2_0.9.7]/trunk/3rdparty/SoundTouch/FIFOSamplePipe.h
ViewVC logotype

Contents of /trunk/3rdparty/SoundTouch/FIFOSamplePipe.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 4 months ago) by william
File MIME type: text/plain
File size: 8213 byte(s)
exported r3113 from ./upstream/trunk
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 'at' iki.fi
16 /// SoundTouch WWW: http://www.surina.net/soundtouch
17 ///
18 ////////////////////////////////////////////////////////////////////////////////
19 //
20 // Last changed : $Date: 2009-04-13 16:18:48 +0300 (Mon, 13 Apr 2009) $
21 // File revision : $Revision: 4 $
22 //
23 // $Id: FIFOSamplePipe.h 69 2009-04-13 13:18:48Z oparviai $
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26 //
27 // License :
28 //
29 // SoundTouch audio processing library
30 // Copyright (c) Olli Parviainen
31 //
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.
36 //
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.
41 //
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
45 //
46 ////////////////////////////////////////////////////////////////////////////////
47
48 #ifndef FIFOSamplePipe_H
49 #define FIFOSamplePipe_H
50
51 #include <assert.h>
52 #include <stdlib.h>
53 #include "STTypes.h"
54
55 namespace soundtouch
56 {
57
58 /// Abstract base class for FIFO (first-in-first-out) sample processing classes.
59 class FIFOSamplePipe
60 {
61 public:
62 // virtual default destructor
63 virtual ~FIFOSamplePipe() {}
64
65
66 /// Returns a pointer to the beginning of the output samples.
67 /// This function is provided for accessing the output samples directly.
68 /// Please be careful for not to corrupt the book-keeping!
69 ///
70 /// When using this function to output samples, also remember to 'remove' the
71 /// output samples from the buffer by calling the
72 /// 'receiveSamples(numSamples)' function
73 virtual SAMPLETYPE *ptrBegin() = 0;
74
75 /// Adds 'numSamples' pcs of samples from the 'samples' memory position to
76 /// the sample buffer.
77 virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples.
78 uint numSamples ///< Number of samples to insert.
79 ) = 0;
80
81
82 // Moves samples from the 'other' pipe instance to this instance.
83 void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data.
84 )
85 {
86 int oNumSamples = other.numSamples();
87
88 putSamples(other.ptrBegin(), oNumSamples);
89 other.receiveSamples(oNumSamples);
90 };
91
92 /// Output samples from beginning of the sample buffer. Copies requested samples to
93 /// output buffer and removes them from the sample buffer. If there are less than
94 /// 'numsample' samples in the buffer, returns all that available.
95 ///
96 /// \return Number of samples returned.
97 virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
98 uint maxSamples ///< How many samples to receive at max.
99 ) = 0;
100
101 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
102 /// sample buffer without copying them anywhere.
103 ///
104 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
105 /// with 'ptrBegin' function.
106 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
107 ) = 0;
108
109 /// Returns number of samples currently available.
110 virtual uint numSamples() const = 0;
111
112 // Returns nonzero if there aren't any samples available for outputting.
113 virtual int isEmpty() const = 0;
114
115 /// Clears all the samples.
116 virtual void clear() = 0;
117 };
118
119
120
121 /// Base-class for sound processing routines working in FIFO principle. With this base
122 /// class it's easy to implement sound processing stages that can be chained together,
123 /// so that samples that are fed into beginning of the pipe automatically go through
124 /// all the processing stages.
125 ///
126 /// When samples are input to this class, they're first processed and then put to
127 /// the FIFO pipe that's defined as output of this class. This output pipe can be
128 /// either other processing stage or a FIFO sample buffer.
129 class FIFOProcessor :public FIFOSamplePipe
130 {
131 protected:
132 /// Internal pipe where processed samples are put.
133 FIFOSamplePipe *output;
134
135 /// Sets output pipe.
136 void setOutPipe(FIFOSamplePipe *pOutput)
137 {
138 assert(output == NULL);
139 assert(pOutput != NULL);
140 output = pOutput;
141 }
142
143
144 /// Constructor. Doesn't define output pipe; it has to be set be
145 /// 'setOutPipe' function.
146 FIFOProcessor()
147 {
148 output = NULL;
149 }
150
151
152 /// Constructor. Configures output pipe.
153 FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe.
154 )
155 {
156 output = pOutput;
157 }
158
159
160 /// Destructor.
161 virtual ~FIFOProcessor()
162 {
163 }
164
165
166 /// Returns a pointer to the beginning of the output samples.
167 /// This function is provided for accessing the output samples directly.
168 /// Please be careful for not to corrupt the book-keeping!
169 ///
170 /// When using this function to output samples, also remember to 'remove' the
171 /// output samples from the buffer by calling the
172 /// 'receiveSamples(numSamples)' function
173 virtual SAMPLETYPE *ptrBegin()
174 {
175 return output->ptrBegin();
176 }
177
178 public:
179
180 /// Output samples from beginning of the sample buffer. Copies requested samples to
181 /// output buffer and removes them from the sample buffer. If there are less than
182 /// 'numsample' samples in the buffer, returns all that available.
183 ///
184 /// \return Number of samples returned.
185 virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
186 uint maxSamples ///< How many samples to receive at max.
187 )
188 {
189 return output->receiveSamples(outBuffer, maxSamples);
190 }
191
192
193 /// Adjusts book-keeping so that given number of samples are removed from beginning of the
194 /// sample buffer without copying them anywhere.
195 ///
196 /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
197 /// with 'ptrBegin' function.
198 virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
199 )
200 {
201 return output->receiveSamples(maxSamples);
202 }
203
204
205 /// Returns number of samples currently available.
206 virtual uint numSamples() const
207 {
208 return output->numSamples();
209 }
210
211
212 /// Returns nonzero if there aren't any samples available for outputting.
213 virtual int isEmpty() const
214 {
215 return output->isEmpty();
216 }
217 };
218
219 }
220
221 #endif

  ViewVC Help
Powered by ViewVC 1.1.22