libresidfp 1.1.1
FilterModelConfig6581.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2026 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 "siddefs-fp.h"
33
34namespace reSIDfp
35{
36
37class Integrator6581;
38
43{
44private:
45 static std::unique_ptr<FilterModelConfig6581> instance;
46 // This allows access to the private constructor
47 friend std::unique_ptr<FilterModelConfig6581>::deleter_type;
48
49public:
50 /*
51 * The ratio of the resistors of the mixer input for filter signals
52 * compared to the voice ones.
53 * See the 6581 filter schematic.
54 */
55 static constexpr double VF_TR_RATIO = 1.07;
56
57private:
58 static constexpr unsigned int DAC_BITS = 11;
59
63 static constexpr double VOLTAGE_SKEW = 1.015;
64
66
67 const double WL_vcr;
68 const double WL_snake;
70
72
73 const double dac_zero;
74 const double dac_scale;
76
78 Dac dac;
79
81
82 uint16_t vcr_nVg[1 << 16];
83 double vcr_n_Ids_term[1 << 16];
85
86 double vcr_mult;
87 bool m_oldCaps;
88
89 // Voice DC offset LUT
90 double voiceDC[256];
91
92private:
93 double getDacZero(double adjustment) const { return dac_zero + 2. * adjustment - 1.; }
94
95 void updateParams();
96
98 ~FilterModelConfig6581() = default;
99
100protected:
105 inline double getVoiceDC(uint8_t env) const override
106 {
107 return voiceDC[env];
108 }
109
110public:
111 static FilterModelConfig6581* getInstance();
112
113 void setFilterRange(double adjustment);
114
115 void enableOldCaps(bool enable);
116
125 uint16_t* getDAC(double adjustment) const;
126
127 inline double getWL_snake() const { return WL_snake; }
128
129 inline uint16_t getVcr_nVg(int i) const { return vcr_nVg[i]; }
130 inline uint16_t getVcr_n_Ids_term(int i) const
131 {
132 return to_uint16(vcr_n_Ids_term[i] * vcr_mult);
133 }
134 // only used if SLOPE_FACTOR is defined
135 static inline constexpr double getUt() { return Ut; }
136 inline double getN16() const { return N16; }
137};
138
139} // namespace reSIDfp
140
141#endif
Definition Dac.h:77
Definition FilterModelConfig6581.h:43
uint16_t * getDAC(double adjustment) const
Definition FilterModelConfig6581.cpp:301
double getVoiceDC(uint8_t env) const override
Definition FilterModelConfig6581.h:105
Definition FilterModelConfig.h:40
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition FilterModelConfig.h:119