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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations) (download)
Mon Sep 6 11:19:43 2010 UTC (9 years, 4 months ago) by william
File MIME type: text/plain
File size: 5678 byte(s)
Exported ./upsream/trunk @r3730 from http://pcsx2.googlecode.com/svn/trunk/
1 ////////////////////////////////////////////////////////////////////////////////
2 ///
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).
6 ///
7 /// Use either of the derived classes of 'RateTransposerInteger' or
8 /// 'RateTransposerFloat' for corresponding integer/floating point tranposing
9 /// algorithm implementation.
10 ///
11 /// Author : Copyright (c) Olli Parviainen
12 /// Author e-mail : oparviai 'at' iki.fi
13 /// SoundTouch WWW: http://www.surina.net/soundtouch
14 ///
15 ////////////////////////////////////////////////////////////////////////////////
16 //
17 // Last changed : $Date: 2009-02-21 18:00:14 +0200 (Sat, 21 Feb 2009) $
18 // File revision : $Revision: 4 $
19 //
20 // $Id: RateTransposer.h 63 2009-02-21 16:00:14Z oparviai $
21 //
22 ////////////////////////////////////////////////////////////////////////////////
23 //
24 // License :
25 //
26 // SoundTouch audio processing library
27 // Copyright (c) Olli Parviainen
28 //
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.
33 //
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.
38 //
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
42 //
43 ////////////////////////////////////////////////////////////////////////////////
44
45 #ifndef RateTransposer_H
46 #define RateTransposer_H
47
48 #include <stddef.h>
49 #include "AAFilter.h"
50 #include "FIFOSamplePipe.h"
51 #include "FIFOSampleBuffer.h"
52
53 #include "STTypes.h"
54
55 namespace soundtouch
56 {
57
58 /// A common linear samplerate transposer class.
59 ///
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
65 {
66 protected:
67 /// Anti-alias filter object
68 AAFilter *pAAFilter;
69
70 float fRate;
71
72 int numChannels;
73
74 /// Buffer for collecting samples to feed the anti-alias filter between
75 /// two batches
76 FIFOSampleBuffer storeBuffer;
77
78 /// Buffer for keeping samples between transposing & anti-alias filter
79 FIFOSampleBuffer tempBuffer;
80
81 /// Output sample buffer
82 FIFOSampleBuffer outputBuffer;
83
84 BOOL bUseAAFilter;
85
86 virtual void resetRegisters() = 0;
87
88 virtual uint transposeStereo(SAMPLETYPE *dest,
89 const SAMPLETYPE *src,
90 uint numSamples) = 0;
91 virtual uint transposeMono(SAMPLETYPE *dest,
92 const SAMPLETYPE *src,
93 uint numSamples) = 0;
94 inline uint transpose(SAMPLETYPE *dest,
95 const SAMPLETYPE *src,
96 uint numSamples);
97
98 void downsample(const SAMPLETYPE *src,
99 uint numSamples);
100 void upsample(const SAMPLETYPE *src,
101 uint numSamples);
102
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,
108 uint numSamples);
109
110
111 public:
112 RateTransposer();
113 virtual ~RateTransposer();
114
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);
118
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();
123
124 /// Returns the output buffer object
125 FIFOSamplePipe *getOutput() { return &outputBuffer; };
126
127 /// Returns the store buffer object
128 FIFOSamplePipe *getStore() { return &storeBuffer; };
129
130 /// Return anti-alias filter object
131 AAFilter *getAAFilter();
132
133 /// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
134 void enableAAFilter(BOOL newMode);
135
136 /// Returns nonzero if anti-alias filter is enabled.
137 BOOL isAAFilterEnabled() const;
138
139 /// Sets new target rate. Normal rate = 1.0, smaller values represent slower
140 /// rate, larger faster rates.
141 virtual void setRate(float newRate);
142
143 /// Sets the number of channels, 1 = mono, 2 = stereo
144 void setChannels(int channels);
145
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);
149
150 /// Clears all the samples in the object
151 void clear();
152
153 /// Returns nonzero if there aren't any samples available for outputting.
154 int isEmpty() const;
155 };
156
157 }
158
159 #endif

  ViewVC Help
Powered by ViewVC 1.1.22