libsidplayfp  0.3.5
TwoPassSincResampler.h
1 #ifndef TWOPASSSINCRESAMPLER_H
2 #define TWOPASSSINCRESAMPLER_H
3 
4 #include "Resampler.h"
5 #include "SincResampler.h"
6 
7 #include <math.h>
8 
9 namespace reSIDfp
10 {
11 
18 private:
19  SincResampler* s1;
20  SincResampler* s2;
21 
22 public:
23  TwoPassSincResampler(const double clockFrequency, const double samplingFrequency,
24  const double highestAccurateFrequency) {
25  /* Calculation according to Laurent Ganier. It evaluates to about 120 kHz at typical settings.
26  * Some testing around the chosen value seems to confirm that this does work. */
27  const double intermediateFrequency = 2. * highestAccurateFrequency
28  + sqrt(2. * highestAccurateFrequency * clockFrequency
29  * (samplingFrequency - 2. * highestAccurateFrequency) / samplingFrequency);
30  s1 = new SincResampler(clockFrequency, intermediateFrequency, highestAccurateFrequency);
31  s2 = new SincResampler(intermediateFrequency, samplingFrequency, highestAccurateFrequency);
32  }
33 
35  delete s1;
36  delete s2;
37  }
38 
39  bool input(const int sample) {
40  return s1->input(sample) && s2->input(s1->output());
41  }
42 
43  int output() const {
44  return s2->output();
45  }
46 
47  void reset() {
48  s1->reset();
49  s2->reset();
50  }
51 };
52 
53 } // namespace reSIDfp
54 
55 #endif