libsidplayfp  1.1.0
FilterModelConfig.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 FILTERMODELCONFIG_H
23 #define FILTERMODELCONFIG_H
24 
25 #include <memory>
26 
27 #define OPAMP_SIZE 22
28 #define DAC_SIZE 11
29 
30 namespace reSIDfp
31 {
32 
33 class Integrator;
34 
38 {
39 private:
40  static std::auto_ptr<FilterModelConfig> instance;
41  // This allows access to the private constructor
42  friend class std::auto_ptr<FilterModelConfig>;
43 
44  static const double opamp_voltage[OPAMP_SIZE][2];
45 
46  const double voice_voltage_range;
47  const double voice_DC_voltage;
48 
49  // Capacitor value.
50  const double C;
51 
52  // Transistor parameters.
53  const double Vdd;
54  const double Vth; // Threshold voltage
55  const double uCox_vcr; // 1/2*u*Cox
56  const double WL_vcr; // W/L for VCR
57  const double uCox_snake; // 1/2*u*Cox
58  const double WL_snake; // W/L for "snake"
59 
60  // DAC parameters.
61  const double dac_zero;
62  const double dac_scale;
63  const double dac_2R_div_R;
64  const bool dac_term;
65 
66  /* Derived stuff */
67  const double vmin, norm;
68  double opamp_working_point;
69  unsigned short* mixer[8];
70  unsigned short* summer[7];
71  unsigned short* gain[16];
72  double dac[DAC_SIZE];
73  unsigned short vcr_Vg[1 << 16];
74  unsigned short vcr_n_Ids_term[1 << 16];
75  int opamp_rev[1 << 16];
76 
77  double evaluateTransistor(double Vw, double vi, double vx);
78 
79  FilterModelConfig();
80  ~FilterModelConfig();
81 
82 public:
83  static FilterModelConfig* getInstance();
84 
85  double getDacZero(double adjustment) const { return dac_zero - (adjustment - 0.5) * 2.; }
86 
87  int getVO_T16() const { return (int)(norm * ((1L << 16) - 1) * vmin); }
88 
89  int getVoiceScaleS14() const { return (int)((norm * ((1L << 14) - 1)) * voice_voltage_range); }
90 
91  int getVoiceDC() const { return (int)((norm * ((1L << 16) - 1)) * (voice_DC_voltage - vmin)); }
92 
93  unsigned short** getGain() { return gain; }
94 
95  unsigned short** getSummer() { return summer; }
96 
97  unsigned short** getMixer() { return mixer; }
98 
107  unsigned int* getDAC(double dac_zero) const;
108 
109  Integrator* buildIntegrator();
110 
124  double estimateFrequency(double dac_zero, int fc);
125 };
126 
127 } // namespace reSIDfp
128 
129 #endif