libsidplayfp  1.4.2
Filter6581.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 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 FILTER6581_H
24 #define FILTER6581_H
25 
26 #include "siddefs-fp.h"
27 
28 #include "Filter.h"
29 #include "FilterModelConfig.h"
30 
31 namespace reSIDfp
32 {
33 
34 class Integrator;
35 
40 class Filter6581 : public Filter
41 {
42 private:
44  int Vhp;
45 
47  int Vbp;
48 
50  int Vlp;
51 
53  int ve;
54 
55  const int voiceScaleS14, voiceDC;
56 
58  unsigned short* currentGain;
59 
61  unsigned short* currentMixer;
62 
64  unsigned short* currentSummer;
65 
67  unsigned short* currentResonance;
68 
70  Integrator* hpIntegrator;
71 
73  Integrator* bpIntegrator;
74 
75  const unsigned short* f0_dac;
76 
77  unsigned short** mixer;
78  unsigned short** summer;
79  unsigned short** gain;
80 
81 public:
82  Filter6581() :
83  Vhp(0),
84  Vbp(0),
85  Vlp(0),
86  ve(0),
87  voiceScaleS14(FilterModelConfig::getInstance()->getVoiceScaleS14()),
88  voiceDC(FilterModelConfig::getInstance()->getVoiceDC()),
89  currentGain(0),
90  currentMixer(0),
91  currentSummer(0),
92  currentResonance(0),
93  hpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
94  bpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
95  f0_dac(FilterModelConfig::getInstance()->getDAC(0.5)),
96  mixer(FilterModelConfig::getInstance()->getMixer()),
97  summer(FilterModelConfig::getInstance()->getSummer()),
98  gain(FilterModelConfig::getInstance()->getGain())
99  {
100  input(0);
101  }
102 
103  ~Filter6581();
104 
105  int clock(int voice1, int voice2, int voice3);
106 
107  void input(int sample) { ve = (sample * voiceScaleS14 * 3 >> 10) + mixer[0][0]; }
108 
112  void updatedCenterFrequency();
113 
119  void updatedResonance() { currentResonance = gain[~res & 0xf]; }
120 
121  void updatedMixing();
122 
123 public:
129  void setFilterCurve(double curvePosition);
130 };
131 
132 } // namespace reSIDfp
133 
134 #if RESID_INLINING || defined(FILTER6581_CPP)
135 
136 #include "Integrator.h"
137 
138 namespace reSIDfp
139 {
140 
141 RESID_INLINE
142 int Filter6581::clock(int voice1, int voice2, int voice3)
143 {
144  voice1 = (voice1 * voiceScaleS14 >> 18) + voiceDC;
145  voice2 = (voice2 * voiceScaleS14 >> 18) + voiceDC;
146  voice3 = (voice3 * voiceScaleS14 >> 18) + voiceDC;
147 
148  int Vi = 0;
149  int Vo = 0;
150 
151  (filt1 ? Vi : Vo) += voice1;
152 
153  (filt2 ? Vi : Vo) += voice2;
154 
155  // NB! Voice 3 is not silenced by voice3off if it is routed
156  // through the filter.
157  if (filt3)
158  {
159  Vi += voice3;
160  }
161  else if (!voice3off)
162  {
163  Vo += voice3;
164  }
165 
166  (filtE ? Vi : Vo) += ve;
167 
168  const int oldVhp = Vhp;
169  Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vi];
170  Vlp = bpIntegrator->solve(Vbp);
171  Vbp = hpIntegrator->solve(oldVhp);
172 
173  if (lp)
174  {
175  Vo += Vlp;
176  }
177 
178  if (bp)
179  {
180  Vo += Vbp;
181  }
182 
183  if (hp)
184  {
185  Vo += Vhp;
186  }
187 
188  return currentGain[currentMixer[Vo]] - (1 << 15);
189 }
190 
191 } // namespace reSIDfp
192 
193 #endif
194 
195 #endif
void updatedMixing()
Definition: Filter6581.cpp:44
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition: Filter.h:61
bool filt1
Routing to filter or outside filter.
Definition: Filter.h:55
int clock(int voice1, int voice2, int voice3)
Definition: Filter6581.h:142
bool voice3off
Switch voice 3 off.
Definition: Filter.h:58
void setFilterCurve(double curvePosition)
Definition: Filter6581.cpp:86
Definition: Integrator.h:152
void updatedCenterFrequency()
Definition: Filter6581.cpp:37
unsigned char res
Filter resonance.
Definition: Filter.h:49
Definition: Filter6581.h:40
void updatedResonance()
Definition: Filter6581.h:119
Definition: Filter.h:32