libsidplayfp 2.9.0
FilterModelConfig6581.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2020 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 FILTERMODELCONFIG6581_H
24#define FILTERMODELCONFIG6581_H
25
26#include "FilterModelConfig.h"
27
28#include <memory>
29
30#include "Dac.h"
31
32#include "sidcxx11.h"
33
34namespace reSIDfp
35{
36
37class Integrator6581;
38
43{
44private:
45 static constexpr unsigned int DAC_BITS = 11;
46
47private:
48 static std::unique_ptr<FilterModelConfig6581> instance;
49 // This allows access to the private constructor
50 friend std::unique_ptr<FilterModelConfig6581>::deleter_type;
51
53
54 const double WL_vcr;
55 const double WL_snake;
57
59
60 const double dac_zero;
61 const double dac_scale;
63
65 Dac dac;
66
68
69 unsigned short vcr_nVg[1 << 16];
70 double vcr_n_Ids_term[1 << 16];
72
73private:
74 double getDacZero(double adjustment) const { return dac_zero + (1. - adjustment); }
75
77 ~FilterModelConfig6581() = default;
78
79public:
80 static FilterModelConfig6581* getInstance();
81
82 void setFilterRange(double adjustment);
83
92 unsigned short* getDAC(double adjustment) const;
93
99 Integrator* buildIntegrator() override;
100
101 inline unsigned short getVcr_nVg(int i) const { return vcr_nVg[i]; }
102 inline unsigned short getVcr_n_Ids_term(int i) const
103 {
104 const double tmp = vcr_n_Ids_term[i] * uCox;
105 assert(tmp > -0.5 && tmp < 65535.5);
106 return static_cast<unsigned short>(tmp + 0.5);
107 }
108 // only used if SLOPE_FACTOR is defined
109 inline constexpr double getUt() const { return Ut; }
110 inline double getN16() const { return N16; }
111};
112
113} // namespace reSIDfp
114
115#endif
Definition Dac.h:76
Definition FilterModelConfig6581.h:43
unsigned short * getDAC(double adjustment) const
Definition FilterModelConfig6581.cpp:259
Integrator * buildIntegrator() override
Definition FilterModelConfig6581.cpp:274
Definition FilterModelConfig.h:40
double uCox
Transconductance coefficient: u*Cox.
Definition FilterModelConfig.h:53
static constexpr double Ut
Transistor parameters.
Definition FilterModelConfig.h:48
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition FilterModelConfig.h:61
Definition Integrator.h:30