libsidplayfp  1.2.1
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 namespace reSIDfp
28 {
29 
30 class Integrator;
31 
35 {
36 private:
37  static const unsigned int OPAMP_SIZE = 22;
38  static const unsigned int DAC_BITS = 11;
39 
40 private:
41  static std::auto_ptr<FilterModelConfig> instance;
42  // This allows access to the private constructor
43  friend class std::auto_ptr<FilterModelConfig>;
44 
45  static const double opamp_voltage[OPAMP_SIZE][2];
46 
47  const double voice_voltage_range;
48  const double voice_DC_voltage;
49 
50  // Capacitor value.
51  const double C;
52 
53  // Transistor parameters.
54  const double Vdd;
55  const double Vth; // Threshold voltage
56  const double uCox_vcr; // 1/2*u*Cox
57  const double WL_vcr; // W/L for VCR
58  const double uCox_snake; // 1/2*u*Cox
59  const double WL_snake; // W/L for "snake"
60 
61  // DAC parameters.
62  const double dac_zero;
63  const double dac_scale;
64 
65  /* Derived stuff */
66  const double vmin, norm;
67  double opamp_working_point;
68  unsigned short* mixer[8];
69  unsigned short* summer[7];
70  unsigned short* gain[16];
71  double dac[DAC_BITS];
72  unsigned short vcr_Vg[1 << 16];
73  unsigned short vcr_n_Ids_term[1 << 16];
74  int opamp_rev[1 << 16];
75 
76 private:
77  double evaluateTransistor(double Vw, double vi, double vx);
78 
79  double getDacZero(double adjustment) const { return dac_zero - (adjustment - 0.5) * 2.; }
80 
81  FilterModelConfig();
82  ~FilterModelConfig();
83 
84 public:
85  static FilterModelConfig* getInstance();
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 adjustment) const;
108 
109  Integrator* buildIntegrator();
110 
124  double estimateFrequency(double dac_zero, int fc);
125 };
126 
127 } // namespace reSIDfp
128 
129 #endif
Definition: Integrator.h:42
Definition: FilterModelConfig.h:34
unsigned int * getDAC(double adjustment) const
Definition: FilterModelConfig.cpp:265
double estimateFrequency(double dac_zero, int fc)
Definition: FilterModelConfig.cpp:298