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 'at' iki.fi
13
/// SoundTouch WWW: http://www.surina.net/soundtouch
15
////////////////////////////////////////////////////////////////////////////////
17
// Last changed : $Date: 2009-02-21 18:00:14 +0200 (Sat, 21 Feb 2009) $
18
// File revision : $Revision: 4 $
20
// $Id: RateTransposer.h 63 2009-02-21 16:00:14Z oparviai $
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
50
#include "FIFOSamplePipe.h"
51
#include "FIFOSampleBuffer.h"
58
/// A common linear samplerate transposer class.
60
/// Note: Use function "RateTransposer::newInstance()" to create a new class
61
/// instance instead of the "new" operator; that function automatically
62
/// chooses a correct implementation depending on if integer or floating
63
/// arithmetics are to be used.
64
class RateTransposer : public FIFOProcessor
67
/// Anti-alias filter object
74
/// Buffer for collecting samples to feed the anti-alias filter between
76
FIFOSampleBuffer storeBuffer;
78
/// Buffer for keeping samples between transposing & anti-alias filter
79
FIFOSampleBuffer tempBuffer;
81
/// Output sample buffer
82
FIFOSampleBuffer outputBuffer;
86
virtual void resetRegisters() = 0;
88
virtual uint transposeStereo(SAMPLETYPE *dest,
89
const SAMPLETYPE *src,
91
virtual uint transposeMono(SAMPLETYPE *dest,
92
const SAMPLETYPE *src,
94
inline uint transpose(SAMPLETYPE *dest,
95
const SAMPLETYPE *src,
98
void downsample(const SAMPLETYPE *src,
100
void upsample(const SAMPLETYPE *src,
103
/// Transposes sample rate by applying anti-alias filter to prevent folding.
104
/// Returns amount of samples returned in the "dest" buffer.
105
/// The maximum amount of samples that can be returned at a time is set by
106
/// the 'set_returnBuffer_size' function.
107
void processSamples(const SAMPLETYPE *src,
113
virtual ~RateTransposer();
115
/// Operator 'new' is overloaded so that it automatically creates a suitable instance
116
/// depending on if we're to use integer or floating point arithmetics.
117
static void *operator new(size_t s);
119
/// Use this function instead of "new" operator to create a new instance of this class.
120
/// This function automatically chooses a correct implementation, depending on if
121
/// integer ot floating point arithmetics are to be used.
122
static RateTransposer *newInstance();
124
/// Returns the output buffer object
125
FIFOSamplePipe *getOutput() { return &outputBuffer; };
127
/// Returns the store buffer object
128
FIFOSamplePipe *getStore() { return &storeBuffer; };
130
/// Return anti-alias filter object
131
AAFilter *getAAFilter();
133
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
134
void enableAAFilter(BOOL newMode);
136
/// Returns nonzero if anti-alias filter is enabled.
137
BOOL isAAFilterEnabled() const;
139
/// Sets new target rate. Normal rate = 1.0, smaller values represent slower
140
/// rate, larger faster rates.
141
virtual void setRate(float newRate);
143
/// Sets the number of channels, 1 = mono, 2 = stereo
144
void setChannels(int channels);
146
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
147
/// the input of the object.
148
void putSamples(const SAMPLETYPE *samples, uint numSamples);
150
/// Clears all the samples in the object
153
/// Returns nonzero if there aren't any samples available for outputting.