libsidplayfp 2.9.0
Filter.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2024 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2004 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 FILTER_H
24#define FILTER_H
25
26#include "FilterModelConfig.h"
27
28#include "siddefs-fp.h"
29
30namespace reSIDfp
31{
32
33class Integrator;
34
38class Filter
39{
40private:
42
43 unsigned short** mixer;
44 unsigned short** summer;
45 unsigned short** resonance;
46 unsigned short** volume;
47
48protected:
51
54
55private:
57 unsigned short* currentMixer = nullptr;
58
60 unsigned short* currentSummer = nullptr;
61
63 unsigned short* currentResonance = nullptr;
64
66 unsigned short* currentVolume = nullptr;
67
69 int Vhp = 0;
70
72 int Vbp = 0;
73
75 int Vlp = 0;
76
78 int Ve = 0;
79
81 unsigned int fc = 0;
82
84
85 bool filt1 = false;
86 bool filt2 = false;
87 bool filt3 = false;
88 bool filtE = false;
90
92 bool voice3off = false;
93
95
96 bool hp = false;
97 bool bp = false;
98 bool lp = false;
100
102 unsigned char vol = 0;
103
105 bool enabled = true;
106
108 unsigned char filt = 0;
109
110protected:
114 virtual void updateCenterFrequency() = 0;
115
121 void updateResonance(unsigned char res) { currentResonance = resonance[res]; }
122
126 void updateMixing();
127
131 unsigned int getFC() const { return fc; }
132
133public:
135
136 virtual ~Filter();
137
146 unsigned short clock(float v1, float v2, float v3);
147
153 void enable(bool enable);
154
158 void reset();
159
165 void writeFC_LO(unsigned char fc_lo);
166
172 void writeFC_HI(unsigned char fc_hi);
173
179 void writeRES_FILT(unsigned char res_filt);
180
186 void writeMODE_VOL(unsigned char mode_vol);
187
193 void input(int input) { Ve = fmc->getNormalizedVoice(input/65536.f); }
194};
195
196} // namespace reSIDfp
197
198#if RESID_INLINING || defined(FILTER_CPP)
199
200#include "Integrator.h"
201
202namespace reSIDfp
203{
204
205RESID_INLINE
206unsigned short Filter::clock(float voice1, float voice2, float voice3)
207{
208 const int V1 = fmc->getNormalizedVoice(voice1);
209 const int V2 = fmc->getNormalizedVoice(voice2);
210 // Voice 3 is silenced by voice3off if it is not routed through the filter.
211 const int V3 = (filt3 || !voice3off) ? fmc->getNormalizedVoice(voice3) : 0;
212
213 int Vsum = 0;
214 int Vmix = 0;
215
216 (filt1 ? Vsum : Vmix) += V1;
217 (filt2 ? Vsum : Vmix) += V2;
218 (filt3 ? Vsum : Vmix) += V3;
219 (filtE ? Vsum : Vmix) += Ve;
220
221 Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vsum];
222 Vbp = hpIntegrator->solve(Vhp);
223 Vlp = bpIntegrator->solve(Vbp);
224
225 if (lp) Vmix += Vlp;
226 if (bp) Vmix += Vbp;
227 if (hp) Vmix += Vhp;
228
229 return currentVolume[currentMixer[Vmix]];
230}
231
232} // namespace reSIDfp
233
234#endif
235
236#endif
Definition FilterModelConfig.h:40
Definition Filter.h:39
Integrator *const bpIntegrator
VCR + associated capacitor connected to bandpass output.
Definition Filter.h:53
void updateResonance(unsigned char res)
Definition Filter.h:121
void writeFC_LO(unsigned char fc_lo)
Definition Filter.cpp:54
unsigned short clock(float v1, float v2, float v3)
Definition Filter.h:206
void writeRES_FILT(unsigned char res_filt)
Definition Filter.cpp:66
void writeFC_HI(unsigned char fc_hi)
Definition Filter.cpp:60
void input(int input)
Definition Filter.h:193
void enable(bool enable)
Definition Filter.cpp:112
void reset()
Definition Filter.cpp:126
virtual void updateCenterFrequency()=0
void updateMixing()
Definition Filter.cpp:30
void writeMODE_VOL(unsigned char mode_vol)
Definition Filter.cpp:83
unsigned int getFC() const
Definition Filter.h:131
Integrator *const hpIntegrator
VCR + associated capacitor connected to highpass output.
Definition Filter.h:50
Definition Integrator.h:30