FilterModelConfig.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2023 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2004,2010 Dag Lem
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FILTERMODELCONFIG_H
#define FILTERMODELCONFIG_H
#include <algorithm>
#include <cassert>
#include "Spline.h"
#include "sidcxx11.h"
namespace reSIDfp
{
class FilterModelConfig
{
protected:
const double voice_voltage_range;
const double voice_DC_voltage;
const double C;
const double Vdd;
const double Vth;
const double Ut;
const double uCox;
const double Vddt;
// Derived stuff
const double vmin, vmax;
const double denorm, norm;
const double N16;
const double currFactorCoeff;
unsigned short* mixer[8]; //-V730_NOINIT this is initialized in the derived class constructor
unsigned short* summer[5]; //-V730_NOINIT this is initialized in the derived class constructor
unsigned short* gain_vol[16]; //-V730_NOINIT this is initialized in the derived class constructor
unsigned short* gain_res[16]; //-V730_NOINIT this is initialized in the derived class constructor
unsigned short opamp_rev[1 << 16]; //-V730_NOINIT this is initialized in the derived class constructor
private:
FilterModelConfig (const FilterModelConfig&) DELETE;
FilterModelConfig& operator= (const FilterModelConfig&) DELETE;
protected:
FilterModelConfig(
double vvr,
double vdv,
double c,
double vdd,
double vth,
double ucox,
const Spline::Point *opamp_voltage,
int opamp_size
);
~FilterModelConfig()
{
for (int i = 0; i < 8; i++)
{
delete [] mixer[i];
}
for (int i = 0; i < 5; i++)
{
delete [] summer[i];
}
for (int i = 0; i < 16; i++)
{
delete [] gain_vol[i];
delete [] gain_res[i];
}
}
public:
unsigned short** getGainVol() { return gain_vol; }
unsigned short** getGainRes() { return gain_res; }
unsigned short** getSummer() { return summer; }
unsigned short** getMixer() { return mixer; }
int getVoiceScaleS11() const { return static_cast<int>((norm * ((1 << 11) - 1)) * voice_voltage_range); }
int getNormalizedVoiceDC() const { return static_cast<int>(N16 * (voice_DC_voltage - vmin)); }
inline unsigned short getOpampRev(int i) const { return opamp_rev[i]; }
inline double getVddt() const { return Vddt; }
inline double getVth() const { return Vth; }
// helper functions
inline unsigned short getNormalizedValue(double value) const
{
const double tmp = N16 * (value - vmin);
assert(tmp > -0.5 && tmp < 65535.5);
return static_cast<unsigned short>(tmp + 0.5);
}
inline unsigned short getNormalizedCurrentFactor(double wl) const
{
const double tmp = (1 << 13) * currFactorCoeff * wl;
assert(tmp > -0.5 && tmp < 65535.5);
return static_cast<unsigned short>(tmp + 0.5);
}
inline unsigned short getNVmin() const {
const double tmp = N16 * vmin;
assert(tmp > -0.5 && tmp < 65535.5);
return static_cast<unsigned short>(tmp + 0.5);
}
};
} // namespace reSIDfp
#endif
reSIDfp::FilterModelConfig
Definition FilterModelConfig.h:37
reSIDfp::FilterModelConfig::Vdd
const double Vdd
Transistor parameters.
Definition FilterModelConfig.h:47
reSIDfp::FilterModelConfig::mixer
unsigned short * mixer[8]
Lookup tables for gain and summer op-amps in output stage / filter.
Definition FilterModelConfig.h:66
reSIDfp::FilterModelConfig::Ut
const double Ut
Thermal voltage: Ut = kT/q = 8.61734315e-5*T ~ 26mV.
Definition FilterModelConfig.h:49
reSIDfp::FilterModelConfig::getNormalizedVoiceDC
int getNormalizedVoiceDC() const
Definition FilterModelConfig.h:135
reSIDfp::FilterModelConfig::currFactorCoeff
const double currFactorCoeff
Current factor coefficient for op-amp integrators.
Definition FilterModelConfig.h:62
reSIDfp::FilterModelConfig::getVoiceScaleS11
int getVoiceScaleS11() const
Definition FilterModelConfig.h:130
reSIDfp::FilterModelConfig::Vddt
const double Vddt
Vdd - Vth.
Definition FilterModelConfig.h:51
reSIDfp::FilterModelConfig::uCox
const double uCox
Transconductance coefficient: u*Cox.
Definition FilterModelConfig.h:50
reSIDfp::FilterModelConfig::C
const double C
Capacitor value.
Definition FilterModelConfig.h:43
reSIDfp::FilterModelConfig::opamp_rev
unsigned short opamp_rev[1<< 16]
Reverse op-amp transfer function.
Definition FilterModelConfig.h:73
reSIDfp::FilterModelConfig::Vth
const double Vth
Threshold voltage.
Definition FilterModelConfig.h:48
reSIDfp::FilterModelConfig::N16
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition FilterModelConfig.h:59
reSIDfp::Spline::Point
Definition Spline.h:42