libsidplayfp 2.4.2
TwoPassSincResampler.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2015 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 <memory>
28
29#include "Resampler.h"
30#include "SincResampler.h"
31
32#include "sidcxx11.h"
33
34namespace reSIDfp
35{
36
40class TwoPassSincResampler final : public Resampler
41{
42private:
43 std::unique_ptr<SincResampler> const s1;
44 std::unique_ptr<SincResampler> const s2;
45
46private:
47 TwoPassSincResampler(double clockFrequency, double samplingFrequency, double highestAccurateFrequency, double intermediateFrequency) :
48 s1(new SincResampler(clockFrequency, intermediateFrequency, highestAccurateFrequency)),
49 s2(new SincResampler(intermediateFrequency, samplingFrequency, highestAccurateFrequency))
50 {}
51
52public:
53 // Named constructor
54 static TwoPassSincResampler* create(double clockFrequency, double samplingFrequency, double highestAccurateFrequency)
55 {
56 // Calculation according to Laurent Ganier. It evaluates to about 120 kHz at typical settings.
57 // Some testing around the chosen value seems to confirm that this does work.
58 double const intermediateFrequency = 2. * highestAccurateFrequency
59 + sqrt(2. * highestAccurateFrequency * clockFrequency
60 * (samplingFrequency - 2. * highestAccurateFrequency) / samplingFrequency);
61 return new TwoPassSincResampler(clockFrequency, samplingFrequency, highestAccurateFrequency, intermediateFrequency);
62 }
63
64 bool input(int sample) override
65 {
66 return s1->input(sample) && s2->input(s1->output());
67 }
68
69 int output() const override
70 {
71 return s2->output();
72 }
73
74 void reset() override
75 {
76 s1->reset();
77 s2->reset();
78 }
79};
80
81} // namespace reSIDfp
82
83#endif
Definition Resampler.h:39
Definition SincResampler.h:54
Definition TwoPassSincResampler.h:41
bool input(int sample) override
Definition TwoPassSincResampler.h:64