23#ifndef FILTERMODELCONFIG_H
24#define FILTERMODELCONFIG_H
34#include "siddefs-fp.h"
46 static constexpr int value =
summer_offset<i - 1>::value + ((2 + i - 1) << 16);
53 static constexpr int value =
mixer_offset<i - 1>::value + ((i - 1) << 16);
57 static inline unsigned short to_ushort_dither(
double x,
double d_noise)
59 const int tmp =
static_cast<int>(x + d_noise);
60 assert((tmp >= 0) && (tmp <= USHRT_MAX));
61 return static_cast<unsigned short>(tmp);
64 static inline unsigned short to_ushort(
double x)
66 return to_ushort_dither(x, 0.5);
84 mutable int index = 0;
88 std::uniform_real_distribution<double> unif(0., 1.);
89 std::default_random_engine re;
90 for (
int i=0; i<1024; i++)
93 double getNoise()
const { index = (index + 1) & 0x3ff;
return buffer[index]; }
103 static constexpr double k = 1.380649e-23;
104 static constexpr double q = 1.602176634e-19;
105 static constexpr double temp = 27;
106 static constexpr double Ut = (
k * (temp + 273.15)) / q;
115 const double vmin, vmax;
116 const double denorm, norm;
121 const double voice_voltage_range;
129 unsigned short* summer;
130 unsigned short* volume;
131 unsigned short* resonance;
144 inline double getVoiceVoltage(
float value,
unsigned int env)
const
146 return value * voice_voltage_range + getVoiceDC(env);
165 const Spline::Point *opamp_voltage,
171 void setUCox(
double new_uCox);
173 virtual double getVoiceDC(
unsigned int env)
const = 0;
186 const double r_N16 = 1. /
N16;
189 for (
int i = 0; i < 5; i++)
191 const int idiv = 2 + i;
192 const int size = idiv << 16;
193 const double n = idiv;
194 const double r_idiv = 1. / idiv;
197 for (
int vi = 0; vi < size; vi++)
199 const double vin = vmin + vi * r_N16 * r_idiv;
200 summer[idx++] = getNormalizedValue(opampModel.
solve(n, vin));
215 const double r_N16 = 1. /
N16;
218 for (
int i = 0; i < 8; i++)
220 const int idiv = (i == 0) ? 1 : i;
221 const int size = (i == 0) ? 1 : i << 16;
222 const double n = i * nRatio;
223 const double r_idiv = 1. / idiv;
226 for (
int vi = 0; vi < size; vi++)
228 const double vin = vmin + vi * r_N16 * r_idiv;
229 mixer[idx++] = getNormalizedValue(opampModel.
solve(n, vin));
243 const double r_N16 = 1. /
N16;
246 for (
int n8 = 0; n8 < 16; n8++)
248 constexpr int size = 1 << 16;
249 const double n = n8 / nDivisor;
252 for (
int vi = 0; vi < size; vi++)
254 const double vin = vmin + vi * r_N16;
255 volume[idx++] = getNormalizedValue(opampModel.
solve(n, vin));
269 const double r_N16 = 1. /
N16;
272 for (
int n8 = 0; n8 < 16; n8++)
274 constexpr int size = 1 << 16;
277 for (
int vi = 0; vi < size; vi++)
279 const double vin = vmin + vi * r_N16;
280 resonance[idx++] = getNormalizedValue(opampModel.
solve(resonance_n[n8], vin));
286 unsigned short* getVolume() {
return volume; }
287 unsigned short* getResonance() {
return resonance; }
288 unsigned short* getSummer() {
return summer; }
289 unsigned short* getMixer() {
return mixer; }
291 inline unsigned short getOpampRev(
int i)
const {
return opamp_rev[i]; }
292 inline double getVddt()
const {
return Vddt; }
293 inline double getVth()
const {
return Vth; }
297 inline unsigned short getNormalizedValue(
double value)
const
299 return to_ushort_dither(
N16 * (value - vmin), rnd.getNoise());
303 inline unsigned short getNormalizedCurrentFactor(
double wl)
const
308 inline unsigned short getNVmin()
const
310 return to_ushort(
N16 * vmin);
313 inline int getNormalizedVoice(
float value,
unsigned int env)
const
315 return static_cast<int>(getNormalizedValue(getVoiceVoltage(value, env)));
322 static constexpr int value = 0;
328 static constexpr int value = 1;
334 static constexpr int value = 0;
Definition FilterModelConfig.h:40
void buildVolumeTable(const OpAmp &opampModel, double nDivisor)
Definition FilterModelConfig.h:241
const double Vdd
Positive supply voltage.
Definition FilterModelConfig.h:108
void buildResonanceTable(const OpAmp &opampModel, const double resonance_n[16])
Definition FilterModelConfig.h:267
unsigned short * mixer
Lookup tables for gain and summer op-amps in output stage / filter.
Definition FilterModelConfig.h:128
double uCox
Transconductance coefficient: u*Cox.
Definition FilterModelConfig.h:111
const double Vddt
Vdd - Vth.
Definition FilterModelConfig.h:110
static constexpr double k
Transistor parameters.
Definition FilterModelConfig.h:103
double currFactorCoeff
Current factor coefficient for op-amp integrators.
Definition FilterModelConfig.h:124
const double C
Capacitor value.
Definition FilterModelConfig.h:98
unsigned short opamp_rev[1<< 16]
Reverse op-amp transfer function.
Definition FilterModelConfig.h:135
const double Vth
Threshold voltage.
Definition FilterModelConfig.h:109
void buildMixerTable(const OpAmp &opampModel, double nRatio)
Definition FilterModelConfig.h:213
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition FilterModelConfig.h:119
void buildSummerTable(const OpAmp &opampModel)
Definition FilterModelConfig.h:184
double solve(double n, double vi) const
Definition OpAmp.cpp:33
void reset() const
Definition OpAmp.h:102
Definition FilterModelConfig.h:52
Definition FilterModelConfig.h:45