libsidplayfp  0.3.5
Filter6581.h
1 #ifndef FILTER6581_H
2 #define FILTER6581_H
3 
4 #include "siddefs-fp.h"
5 
6 #include "Filter.h"
7 #include "FilterModelConfig.h"
8 
9 namespace reSIDfp
10 {
11 
12 class Integrator;
13 
25 class Filter6581 : public Filter {
26 
27 private:
29  int Vhp;
30 
32  int Vbp;
33 
35  int Vlp;
36 
38  unsigned short* currentGain;
39 
41  unsigned short* currentMixer;
42 
44  unsigned short* currentSummer;
45 
47  unsigned short* currentResonance;
48 
50  Integrator* hpIntegrator;
51 
53  Integrator* bpIntegrator;
54 
56  int ve;
57 
58  const int voiceScaleS14, voiceDC, vo_T16;
59 
60  const unsigned int* f0_dac;
61 
62  unsigned short** mixer;
63  unsigned short** summer;
64  unsigned short** gain;
65 
66 public:
67  Filter6581() :
68  Vhp(0),
69  Vbp(0),
70  Vlp(0),
71  currentGain(0),
72  currentMixer(0),
73  currentSummer(0),
74  currentResonance(0),
75  hpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
76  bpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
77  ve(0),
78  voiceScaleS14(FilterModelConfig::getInstance()->getVoiceScaleS14()),
79  voiceDC(FilterModelConfig::getInstance()->getVoiceDC()),
80  vo_T16(FilterModelConfig::getInstance()->getVO_T16()),
81  f0_dac(FilterModelConfig::getInstance()->getDAC(FilterModelConfig::getInstance()->getDacZero(0.5))),
82  mixer(FilterModelConfig::getInstance()->getMixer()),
83  summer(FilterModelConfig::getInstance()->getSummer()),
84  gain(FilterModelConfig::getInstance()->getGain()) {
85 
86  input(0);
87  }
88 
89  ~Filter6581();
90 
91  int clock(const int voice1, const int voice2, const int voice3);
92 
93  void input(const int sample);
94 
99 
106  void updatedResonance();
107 
108  void updatedMixing();
109 
110 public:
116  void setFilterCurve(const double curvePosition);
117 };
118 
119 } // namespace reSIDfp
120 
121 #if RESID_INLINING || defined(FILTER6581_CPP)
122 
123 #include "Integrator.h"
124 
125 namespace reSIDfp
126 {
127 
128 RESID_INLINE
129 int Filter6581::clock(const int voice1, const int voice2, const int voice3) {
130  const int v1 = (voice1 * voiceScaleS14 >> 18) + voiceDC;
131  const int v2 = (voice2 * voiceScaleS14 >> 18) + voiceDC;
132  const int v3 = (voice3 * voiceScaleS14 >> 18) + voiceDC;
133 
134  int Vi = 0;
135  int Vo = 0;
136 
137  if (filt1) {
138  Vi += v1;
139  } else {
140  Vo += v1;
141  }
142  if (filt2) {
143  Vi += v2;
144  } else {
145  Vo += v2;
146  }
147  // NB! Voice 3 is not silenced by voice3off if it is routed
148  // through the filter.
149  if (filt3) {
150  Vi += v3;
151  } else if (!voice3off) {
152  Vo += v3;
153  }
154  if (filtE) {
155  Vi += ve;
156  } else {
157  Vo += ve;
158  }
159 
160  const int oldVhp = Vhp;
161  Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vi];
162  Vlp = bpIntegrator->solve(Vbp + vo_T16) - vo_T16;
163  Vbp = hpIntegrator->solve(oldVhp + vo_T16) - vo_T16;
164 
165  if (lp) {
166  Vo += Vlp;
167  }
168  if (bp) {
169  Vo += Vbp;
170  }
171  if (hp) {
172  Vo += Vhp;
173  }
174  return currentGain[currentMixer[Vo]] - (1 << 15);
175 }
176 
177 } // namespace reSIDfp
178 
179 #endif
180 
181 #endif