libsidplayfp  2.4.0
FilterModelConfig.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2022 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 <algorithm>
27 #include <cassert>
28 
29 #include "Spline.h"
30 
31 #include "sidcxx11.h"
32 
33 namespace reSIDfp
34 {
35 
37 {
38 protected:
39  const double voice_voltage_range;
40  const double voice_DC_voltage;
41 
43  const double C;
44 
46 
47  const double Vdd;
48  const double Vth;
49  const double Ut;
50  const double uCox;
51  const double Vddt;
53 
54  // Derived stuff
55  const double vmin, vmax;
56  const double denorm, norm;
57 
59  const double N16;
60 
62  const double currFactorCoeff;
63 
65 
66  unsigned short* mixer[8]; //-V730_NOINIT this is initialized in the derived class constructor
67  unsigned short* summer[5]; //-V730_NOINIT this is initialized in the derived class constructor
68  unsigned short* gain_vol[16]; //-V730_NOINIT this is initialized in the derived class constructor
69  unsigned short* gain_res[16]; //-V730_NOINIT this is initialized in the derived class constructor
71 
73  unsigned short opamp_rev[1 << 16]; //-V730_NOINIT this is initialized in the derived class constructor
74 
75 private:
76  FilterModelConfig (const FilterModelConfig&) DELETE;
77  FilterModelConfig& operator= (const FilterModelConfig&) DELETE;
78 
79 protected:
91  double vvr,
92  double vdv,
93  double c,
94  double vdd,
95  double vth,
96  double ucox,
97  const Spline::Point *opamp_voltage,
98  int opamp_size
99  );
100 
102  {
103  for (int i = 0; i < 8; i++)
104  {
105  delete [] mixer[i];
106  }
107 
108  for (int i = 0; i < 5; i++)
109  {
110  delete [] summer[i];
111  }
112 
113  for (int i = 0; i < 16; i++)
114  {
115  delete [] gain_vol[i];
116  delete [] gain_res[i];
117  }
118  }
119 
120 public:
121  unsigned short** getGainVol() { return gain_vol; }
122  unsigned short** getGainRes() { return gain_res; }
123  unsigned short** getSummer() { return summer; }
124  unsigned short** getMixer() { return mixer; }
125 
130  int getVoiceScaleS11() const { return static_cast<int>((norm * ((1 << 11) - 1)) * voice_voltage_range); }
131 
135  int getNormalizedVoiceDC() const { return static_cast<int>(N16 * (voice_DC_voltage - vmin)); }
136 
137  inline unsigned short getOpampRev(int i) const { return opamp_rev[i]; }
138  inline double getVddt() const { return Vddt; }
139  inline double getVth() const { return Vth; }
140  inline double getVoiceDCVoltage() const { return voice_DC_voltage; }
141 
142  // helper functions
143  inline unsigned short getNormalizedValue(double value) const
144  {
145  const double tmp = N16 * (value - vmin);
146  assert(tmp > -0.5 && tmp < 65535.5);
147  return static_cast<unsigned short>(tmp + 0.5);
148  }
149 
150  inline unsigned short getNormalizedCurrentFactor(double wl) const
151  {
152  const double tmp = (1 << 13) * currFactorCoeff * wl;
153  assert(tmp > -0.5 && tmp < 65535.5);
154  return static_cast<unsigned short>(tmp + 0.5);
155  }
156 
157  inline unsigned short getNVmin() const {
158  const double tmp = N16 * vmin;
159  assert(tmp > -0.5 && tmp < 65535.5);
160  return static_cast<unsigned short>(tmp + 0.5);
161  }
162 };
163 
164 } // namespace reSIDfp
165 
166 #endif
Definition: FilterModelConfig.h:37
const double Vdd
Transistor parameters.
Definition: FilterModelConfig.h:47
unsigned short * mixer[8]
Lookup tables for gain and summer op-amps in output stage / filter.
Definition: FilterModelConfig.h:66
const double Ut
Thermal voltage: Ut = kT/q = 8.61734315e-5*T ~ 26mV.
Definition: FilterModelConfig.h:49
int getNormalizedVoiceDC() const
Definition: FilterModelConfig.h:135
const double currFactorCoeff
Current factor coefficient for op-amp integrators.
Definition: FilterModelConfig.h:62
int getVoiceScaleS11() const
Definition: FilterModelConfig.h:130
const double Vddt
Vdd - Vth.
Definition: FilterModelConfig.h:51
const double uCox
Transconductance coefficient: u*Cox.
Definition: FilterModelConfig.h:50
const double C
Capacitor value.
Definition: FilterModelConfig.h:43
unsigned short opamp_rev[1<< 16]
Reverse op-amp transfer function.
Definition: FilterModelConfig.h:73
const double Vth
Threshold voltage.
Definition: FilterModelConfig.h:48
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition: FilterModelConfig.h:59
Definition: Spline.h:42