libsidplayfp  2.11.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 
34 namespace reSIDfp
35 {
36 
37 class Integrator6581;
38 
43 {
44 private:
45  static std::unique_ptr<FilterModelConfig6581> instance;
46  // This allows access to the private constructor
47  friend std::unique_ptr<FilterModelConfig6581>::deleter_type;
48 
49 private:
50  static constexpr unsigned int DAC_BITS = 11;
51 
55  static constexpr double VOLTAGE_SKEW = 1.015;
56 
58 
59  const double WL_vcr;
60  const double WL_snake;
62 
64 
65  const double dac_zero;
66  const double dac_scale;
68 
70  Dac dac;
71 
73 
74  unsigned short vcr_nVg[1 << 16];
75  double vcr_n_Ids_term[1 << 16];
77 
78  // Voice DC offset LUT
79  double voiceDC[256];
80 
81 private:
82  double getDacZero(double adjustment) const { return dac_zero + (1. - adjustment); }
83 
85  ~FilterModelConfig6581() = default;
86 
87 protected:
92  double getVoiceDC(unsigned int env) const override
93  {
94  return voiceDC[env];
95  }
96 
97 public:
98  static FilterModelConfig6581* getInstance();
99 
100  void setFilterRange(double adjustment);
101 
110  unsigned short* getDAC(double adjustment) const;
111 
112  inline double getWL_snake() const { return WL_snake; }
113 
114  inline unsigned short getVcr_nVg(int i) const { return vcr_nVg[i]; }
115  inline unsigned short getVcr_n_Ids_term(int i) const
116  {
117  const double tmp = vcr_n_Ids_term[i] * uCox;
118  assert(tmp > -0.5 && tmp < 65535.5);
119  return static_cast<unsigned short>(tmp + 0.5);
120  }
121  // only used if SLOPE_FACTOR is defined
122  inline constexpr double getUt() const { return Ut; }
123  inline double getN16() const { return N16; }
124 };
125 
126 } // namespace reSIDfp
127 
128 #endif
Definition: Dac.h:76
Definition: FilterModelConfig6581.h:43
double getVoiceDC(unsigned int env) const override
Definition: FilterModelConfig6581.h:92
unsigned short * getDAC(double adjustment) const
Definition: FilterModelConfig6581.cpp:276
Definition: FilterModelConfig.h:39
double uCox
Transconductance coefficient: u*Cox.
Definition: FilterModelConfig.h:79
static constexpr double Ut
Transistor parameters.
Definition: FilterModelConfig.h:74
const double N16
Fixed point scaling for 16 bit op-amp output.
Definition: FilterModelConfig.h:87