1 ////////////////////////////////////////////////////////////////////////////////
3 /// Sample rate transposer. Changes sample rate by using linear interpolation
4 /// together with anti-alias filtering (first order interpolation with anti-
5 /// alias filtering should be quite adequate for this application).
7 /// Use either of the derived classes of 'RateTransposerInteger' or
8 /// 'RateTransposerFloat' for corresponding integer/floating point tranposing
9 /// algorithm implementation.
11 /// Author : Copyright (c) Olli Parviainen
12 /// Author e-mail : oparviai @ iki.fi
13 /// SoundTouch WWW: http://www.iki.fi/oparviai/soundtouch
15 ////////////////////////////////////////////////////////////////////////////////
17 // Last changed : $Date$
18 // File revision : $Revision$
22 ////////////////////////////////////////////////////////////////////////////////
26 // SoundTouch audio processing library
27 // Copyright (c) Olli Parviainen
29 // This library is free software; you can redistribute it and/or
30 // modify it under the terms of the GNU Lesser General Public
31 // License as published by the Free Software Foundation; either
32 // version 2.1 of the License, or (at your option) any later version.
34 // This library is distributed in the hope that it will be useful,
35 // but WITHOUT ANY WARRANTY; without even the implied warranty of
36 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 // Lesser General Public License for more details.
39 // You should have received a copy of the GNU Lesser General Public
40 // License along with this library; if not, write to the Free Software
41 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43 ////////////////////////////////////////////////////////////////////////////////
45 #ifndef RateTransposer_H
46 #define RateTransposer_H
49 #include "FIFOSamplePipe.h"
50 #include "FIFOSampleBuffer.h"
57 /// A common linear samplerate transposer class.
59 /// Note: Use function "RateTransposer::newInstance()" to create a new class
60 /// instance instead of the "new" operator; that function automatically
61 /// chooses a correct implementation depending on if integer or floating
62 /// arithmetics are to be used.
63 class RateTransposer : public FIFOProcessor
66 /// Anti-alias filter object
73 /// Buffer for collecting samples to feed the anti-alias filter between
75 FIFOSampleBuffer storeBuffer;
77 /// Buffer for keeping samples between transposing & anti-alias filter
78 FIFOSampleBuffer tempBuffer;
80 /// Output sample buffer
81 FIFOSampleBuffer outputBuffer;
87 virtual void resetRegisters() = 0;
89 virtual uint transposeStereo(SAMPLETYPE *dest,
90 const SAMPLETYPE *src,
92 virtual uint transposeMono(SAMPLETYPE *dest,
93 const SAMPLETYPE *src,
95 uint transpose(SAMPLETYPE *dest,
96 const SAMPLETYPE *src,
99 void flushStoreBuffer();
101 void downsample(const SAMPLETYPE *src,
103 void upsample(const SAMPLETYPE *src,
106 /// Transposes sample rate by applying anti-alias filter to prevent folding.
107 /// Returns amount of samples returned in the "dest" buffer.
108 /// The maximum amount of samples that can be returned at a time is set by
109 /// the 'set_returnBuffer_size' function.
110 void processSamples(const SAMPLETYPE *src,
116 virtual ~RateTransposer();
118 /// Use this function instead of "new" operator to create a new instance of this class.
119 /// This function automatically chooses a correct implementation, depending on if
120 /// integer ot floating point arithmetics are to be used.
121 static RateTransposer *newInstance();
123 /// Returns the output buffer object
124 FIFOSamplePipe *getOutput() { return &outputBuffer; };
126 /// Returns the store buffer object
127 FIFOSamplePipe *getStore() { return &storeBuffer; };
129 /// Return anti-alias filter object
130 AAFilter *getAAFilter() const;
132 /// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
133 void enableAAFilter(BOOL newMode);
135 /// Returns nonzero if anti-alias filter is enabled.
136 BOOL isAAFilterEnabled() const;
138 /// Sets new target rate. Normal rate = 1.0, smaller values represent slower
139 /// rate, larger faster rates.
140 virtual void setRate(float newRate);
142 /// Sets the number of channels, 1 = mono, 2 = stereo
143 void setChannels(uint channels);
145 /// Adds 'numSamples' pcs of samples from the 'samples' memory position into
146 /// the input of the object.
147 void putSamples(const SAMPLETYPE *samples, uint numSamples);
149 /// Clears all the samples in the object
152 /// Returns nonzero if there aren't any samples available for outputting.