libsidplayfp  1.1.0
TwoPassSincResampler.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef TWOPASSSINCRESAMPLER_H
23 #define TWOPASSSINCRESAMPLER_H
24 
25 #include <math.h>
26 
27 #include "Resampler.h"
28 #include "SincResampler.h"
29 
30 namespace reSIDfp
31 {
32 
39 {
40 private:
41  SincResampler* s1;
42  SincResampler* s2;
43 
44 public:
45  TwoPassSincResampler(double clockFrequency, double samplingFrequency,
46  double highestAccurateFrequency)
47  {
48  /* Calculation according to Laurent Ganier. It evaluates to about 120 kHz at typical settings.
49  * Some testing around the chosen value seems to confirm that this does work. */
50  const double intermediateFrequency = 2. * highestAccurateFrequency
51  + sqrt(2. * highestAccurateFrequency * clockFrequency
52  * (samplingFrequency - 2. * highestAccurateFrequency) / samplingFrequency);
53  s1 = new SincResampler(clockFrequency, intermediateFrequency, highestAccurateFrequency);
54  s2 = new SincResampler(intermediateFrequency, samplingFrequency, highestAccurateFrequency);
55  }
56 
58  {
59  delete s1;
60  delete s2;
61  }
62 
63  bool input(int sample)
64  {
65  return s1->input(sample) && s2->input(s1->output());
66  }
67 
68  int output() const
69  {
70  return s2->output();
71  }
72 
73  void reset()
74  {
75  s1->reset();
76  s2->reset();
77  }
78 };
79 
80 } // namespace reSIDfp
81 
82 #endif
Definition: SincResampler.h:70
Definition: TwoPassSincResampler.h:38
bool input(int input)
Definition: SincResampler.cpp:212
Definition: Resampler.h:34
bool input(int sample)
Definition: TwoPassSincResampler.h:63