libsidplayfp  2.0.2
FilterModelConfig.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2004,2010 Dag Lem
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef FILTERMODELCONFIG_H
24 #define FILTERMODELCONFIG_H
25 
26 #include <memory>
27 
28 #include "Dac.h"
29 #include "Spline.h"
30 
31 #include "sidcxx11.h"
32 
33 namespace reSIDfp
34 {
35 
36 class Integrator;
37 
42 {
43 private:
44  static const unsigned int DAC_BITS = 11;
45 
46 private:
47  static std::unique_ptr<FilterModelConfig> instance;
48  // This allows access to the private constructor
49 #ifdef HAVE_CXX11
50  friend std::unique_ptr<FilterModelConfig>::deleter_type;
51 #else
52  friend class std::auto_ptr<FilterModelConfig>;
53 #endif
54 
55  const double voice_voltage_range;
56  const double voice_DC_voltage;
57 
59  const double C;
60 
62 
63  const double Vdd;
64  const double Vth;
65  const double Ut;
66  const double k;
67  const double uCox;
68  const double WL_vcr;
69  const double WL_snake;
70  const double kVddt;
71 
72 
74 
75  const double dac_zero;
76  const double dac_scale;
78 
79  // Derived stuff
80  const double vmin, vmax;
81  const double denorm, norm;
82 
84  const double N16;
85 
87 
88  unsigned short* mixer[8];
89  unsigned short* summer[5];
90  unsigned short* gain[16];
92 
94  Dac dac;
95 
97 
98  unsigned short vcr_kVg[1 << 16];
99  unsigned short vcr_n_Ids_term[1 << 16];
101 
103  unsigned short opamp_rev[1 << 16];
104 
105 private:
106  double getDacZero(double adjustment) const { return dac_zero + (1. - adjustment); }
107 
110 
111 public:
112  static FilterModelConfig* getInstance();
113 
118  int getVoiceScaleS14() const { return static_cast<int>((norm * ((1 << 14) - 1)) * voice_voltage_range); }
119 
123  int getVoiceDC() const { return static_cast<int>(N16 * (voice_DC_voltage - vmin)); }
124 
125  unsigned short** getGain() { return gain; }
126 
127  unsigned short** getSummer() { return summer; }
128 
129  unsigned short** getMixer() { return mixer; }
130 
139  unsigned short* getDAC(double adjustment) const;
140 
146  std::unique_ptr<Integrator> buildIntegrator();
147 };
148 
149 } // namespace reSIDfp
150 
151 #endif
reSIDfp::FilterModelConfig
Definition: FilterModelConfig.h:42
reSIDfp::FilterModelConfig::getVoiceScaleS14
int getVoiceScaleS14() const
Definition: FilterModelConfig.h:118
reSIDfp::FilterModelConfig::getVoiceDC
int getVoiceDC() const
Definition: FilterModelConfig.h:123
reSIDfp::Dac
Definition: Dac.h:76
reSIDfp::FilterModelConfig::getDAC
unsigned short * getDAC(double adjustment) const
Definition: FilterModelConfig.cpp:286
reSIDfp::FilterModelConfig::buildIntegrator
std::unique_ptr< Integrator > buildIntegrator()
Definition: FilterModelConfig.cpp:303