libsidplayfp  0.3.5
SincResampler.h
1 /*
2  * This file is part of reSID, a MOS6581 SID emulator engine.
3  * Copyright (C) 2004 Dag Lem <resid@nimrod.no>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * @author Ken Händel
20  *
21  */
22 
23 #ifndef SINCRESAMPLER_H
24 #define SINCRESAMPLER_H
25 
26 #include "Resampler.h"
27 
28 #include "../array.h"
29 
30 #include <string>
31 #include <map>
32 
33 namespace reSIDfp
34 {
35 
60 class SincResampler : public Resampler {
61 
62 private:
63  static const int RINGSIZE = 2048;
64 
65  static const int BITS = 16;
66 
67  array<short>* firTable;
68 
69  int sampleIndex;
70 
71  int firRES, firN;
72 
73  const int cyclesPerSample;
74 
75  int sampleOffset;
76 
77  int outputValue;
78 
79  short sample[RINGSIZE * 2];
80 
84  static std::map<std::string, array<short> > FIR_CACHE;
85 
87  static const double I0E;
88 
97  static double I0(const double x);
98 
107  static int convolve(const short* a, const short* b, const int bLength);
108 
109  int fir(const int subcycle);
110 
111 public:
128  SincResampler(const double clockFrequency, const double samplingFrequency, const double highestAccurateFrequency);
129 
130  bool input(const int input);
131 
132  int output() const { return outputValue; }
133 
134  void reset();
135 #if 0
136 
142  static void main(String[] args);
143 #endif
144 };
145 
146 } // namespace reSIDfp
147 
148 #endif