libresidfp  1.2.3
Integrator8580.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2023 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2004, 2010 Dag Lem <resid@nimrod.no>
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 INTEGRATOR8580_H
24 #define INTEGRATOR8580_H
25 
26 #include "Integrator.h"
27 #include "FilterModelConfig8580.h"
28 
29 #include <cstdint>
30 #include <cassert>
31 
32 #include "siddefs-fp.h"
33 
34 namespace reSIDfp
35 {
36 
55 class Integrator8580 : public Integrator
56 {
57  friend class State;
58 
59 private:
60  uint16_t nVgt;
61  uint16_t n_dac;
62 
64 
65 public:
66  explicit Integrator8580(FilterModelConfig8580& new_fmc) :
67  fmc(new_fmc)
68  {
69  setV(1.5);
70  }
71 
75  void setFc(double wl)
76  {
77  // Normalized current factor, 1 cycle at 1MHz.
78  n_dac = fmc.getNormalizedCurrentFactor<17>(wl);
79  }
80 
84  void setV(double v)
85  {
86  // Gate voltage is controlled by the switched capacitor voltage divider
87  // Ua = Ue * v = 4.75v 1<v<2
88  assert(v > 1.0 && v < 2.0);
89  const double Vg = fmc.getVref() * v;
90  const double Vgt = Vg - fmc.getVth();
91 
92  // Vg - Vth, normalized so that translated values can be subtracted:
93  // Vgt - x = (Vgt - t) - (x - t)
94  nVgt = fmc.getNormalizedValue(Vgt);
95  }
96 
97  int32_t solve(int32_t vi) const override;
98 };
99 
100 } // namespace reSIDfp
101 
102 #endif
void setV(double v)
Definition: Integrator8580.h:84
Definition: Dac.cpp:27
Definition: Integrator8580.h:55
Definition: Integrator.h:31
Definition: FilterModelConfig8580.h:40
void setFc(double wl)
Definition: Integrator8580.h:75
Definition: State.h:45