ScummVM API documentation
FIRResampler.h
1 /* Copyright (C) 2015-2022 Sergey V. Mikayev
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation, either version 2.1 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef SRCTOOLS_FIR_RESAMPLER_H
18 #define SRCTOOLS_FIR_RESAMPLER_H
19 
20 #include "ResamplerStage.h"
21 
22 namespace SRCTools {
23 
24 typedef FloatSample FIRCoefficient;
25 
26 static const unsigned int FIR_INTERPOLATOR_CHANNEL_COUNT = 2;
27 
28 class FIRResampler : public ResamplerStage {
29 public:
30  FIRResampler(const unsigned int upsampleFactor, const double downsampleFactor, const FIRCoefficient kernel[], const unsigned int kernelLength);
31  ~FIRResampler();
32 
33  void process(const FloatSample *&inSamples, unsigned int &inLength, FloatSample *&outSamples, unsigned int &outLength);
34  unsigned int estimateInLength(const unsigned int outLength) const;
35 
36 private:
37  const struct Constants {
38  // Filter coefficients
39  const FIRCoefficient *taps;
40  // Indicates whether to interpolate filter taps
41  bool usePhaseInterpolation;
42  // Size of array of filter coefficients
43  unsigned int numberOfTaps;
44  // Upsampling factor
45  unsigned int numberOfPhases;
46  // Downsampling factor
47  double phaseIncrement;
48  // Index of last delay line element, generally greater than numberOfTaps to form a proper binary mask
49  unsigned int delayLineMask;
50  // Delay line
51  FloatSample(*ringBuffer)[FIR_INTERPOLATOR_CHANNEL_COUNT];
52 
53  Constants(const unsigned int upsampleFactor, const double downsampleFactor, const FIRCoefficient kernel[], const unsigned int kernelLength);
54  } constants;
55  // Index of current sample in delay line
56  unsigned int ringBufferPosition;
57  // Current phase
58  double phase;
59 
60  bool needNextInSample() const;
61  void addInSamples(const FloatSample *&inSamples);
62  void getOutSamplesStereo(FloatSample *&outSamples);
63 }; // class FIRResampler
64 
65 } // namespace SRCTools
66 
67 #endif // SRCTOOLS_FIR_RESAMPLER_H
unsigned int estimateInLength(const unsigned int outLength) const
void process(const FloatSample *&inSamples, unsigned int &inLength, FloatSample *&outSamples, unsigned int &outLength)
Definition: ResamplerStage.h:25
Definition: FIRResampler.h:28
Definition: FIRResampler.h:22