libsidplayfp  1.8.3
FilterModelConfig.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2014 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 "Spline.h"
29 
30 namespace reSIDfp
31 {
32 
33 class Integrator;
34 
39 {
40 private:
41  static const unsigned int OPAMP_SIZE = 33;
42  static const unsigned int DAC_BITS = 11;
43 
44 private:
45  static std::auto_ptr<FilterModelConfig> instance;
46  // This allows access to the private constructor
47  friend class std::auto_ptr<FilterModelConfig>;
48 
49  static const Spline::Point opamp_voltage[OPAMP_SIZE];
50 
51  const double voice_voltage_range;
52  const double voice_DC_voltage;
53 
55  const double C;
56 
58 
59  const double Vdd;
60  const double Vth;
61  const double Ut;
62  const double k;
63  const double uCox;
64  const double WL_vcr;
65  const double WL_snake;
66  const double kVddt;
67 
68 
70 
71  const double dac_zero;
72  const double dac_scale;
74 
75  // Derived stuff
76  const double vmin, vmax;
77  const double denorm, norm;
78 
80  const double N16;
81 
83 
84  unsigned short* mixer[8];
85  unsigned short* summer[5];
86  unsigned short* gain[16];
88 
90  double dac[DAC_BITS];
91 
93 
94  unsigned short vcr_kVg[1 << 16];
95  unsigned short vcr_n_Ids_term[1 << 16];
97 
99  unsigned short opamp_rev[1 << 16];
100 
101 private:
102  double getDacZero(double adjustment) const { return dac_zero - (adjustment - 0.5) * 2.; }
103 
104  FilterModelConfig();
105  ~FilterModelConfig();
106 
107 public:
108  static FilterModelConfig* getInstance();
109 
114  int getVoiceScaleS14() const { return static_cast<int>((norm * ((1 << 14) - 1)) * voice_voltage_range); }
115 
119  int getVoiceDC() const { return static_cast<int>(N16 * (voice_DC_voltage - vmin)); }
120 
121  unsigned short** getGain() { return gain; }
122 
123  unsigned short** getSummer() { return summer; }
124 
125  unsigned short** getMixer() { return mixer; }
126 
135  unsigned short* getDAC(double adjustment) const;
136 
142  std::auto_ptr<Integrator> buildIntegrator();
143 };
144 
145 } // namespace reSIDfp
146 
147 #endif
int getVoiceScaleS14() const
Definition: FilterModelConfig.h:114
Definition: Dac.cpp:25
Definition: Spline.h:37
unsigned short * getDAC(double adjustment) const
Definition: FilterModelConfig.cpp:286
Definition: FilterModelConfig.h:38
std::auto_ptr< Integrator > buildIntegrator()
Definition: FilterModelConfig.cpp:312
int getVoiceDC() const
Definition: FilterModelConfig.h:119