libsidplayfp 1.8.8
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 <cmath>
26
27#include "Resampler.h"
28#include "SincResampler.h"
29
30namespace reSIDfp
31{
32
37{
38private:
39 SincResampler* s1;
40 SincResampler* s2;
41
42public:
43 TwoPassSincResampler(double clockFrequency, double samplingFrequency,
44 double highestAccurateFrequency)
45 {
46 // Calculation according to Laurent Ganier. It evaluates to about 120 kHz at typical settings.
47 // Some testing around the chosen value seems to confirm that this does work.
48 const double intermediateFrequency = 2. * highestAccurateFrequency
49 + sqrt(2. * highestAccurateFrequency * clockFrequency
50 * (samplingFrequency - 2. * highestAccurateFrequency) / samplingFrequency);
51 s1 = new SincResampler(clockFrequency, intermediateFrequency, highestAccurateFrequency);
52 s2 = new SincResampler(intermediateFrequency, samplingFrequency, highestAccurateFrequency);
53 }
54
56 {
57 delete s1;
58 delete s2;
59 }
60
61 bool input(int sample)
62 {
63 return s1->input(sample) && s2->input(s1->output());
64 }
65
66 int output() const
67 {
68 return s2->output();
69 }
70
71 void reset()
72 {
73 s1->reset();
74 s2->reset();
75 }
76};
77
78} // namespace reSIDfp
79
80#endif
Definition: Resampler.h:33
Definition: SincResampler.h:52
bool input(int input)
Definition: SincResampler.cpp:240
Definition: TwoPassSincResampler.h:37
bool input(int sample)
Definition: TwoPassSincResampler.h:61