libsidplayfp 2.7.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;
58
60 unsigned short* currentSummer;
61
63 unsigned short* currentResonance;
64
66 unsigned short* currentVolume;
67
69 int Vhp;
70
72 int Vbp;
73
75 int Vlp;
76
78 int Ve;
79
81 unsigned int fc;
82
84 bool filt1, filt2, filt3, filtE;
85
87 bool voice3off;
88
90 bool hp, bp, lp;
91
93 unsigned char vol;
94
96 bool enabled;
97
99 unsigned char filt;
100
101protected:
105 virtual void updateCenterFrequency() = 0;
106
112 void updateResonance(unsigned char res) { currentResonance = resonance[res]; }
113
117 void updateMixing();
118
122 unsigned int getFC() const { return fc; }
123
124public:
126
127 virtual ~Filter();
128
137 unsigned short clock(float v1, float v2, float v3);
138
144 void enable(bool enable);
145
149 void reset();
150
156 void writeFC_LO(unsigned char fc_lo);
157
163 void writeFC_HI(unsigned char fc_hi);
164
170 void writeRES_FILT(unsigned char res_filt);
171
177 void writeMODE_VOL(unsigned char mode_vol);
178
184 void input(int input) { Ve = fmc->getNormalizedVoice(input/65536.f); }
185};
186
187} // namespace reSIDfp
188
189#if RESID_INLINING || defined(FILTER_CPP)
190
191#include "Integrator.h"
192
193namespace reSIDfp
194{
195
196RESID_INLINE
197unsigned short Filter::clock(float voice1, float voice2, float voice3)
198{
199 const int V1 = fmc->getNormalizedVoice(voice1);
200 const int V2 = fmc->getNormalizedVoice(voice2);
201 // Voice 3 is silenced by voice3off if it is not routed through the filter.
202 const int V3 = (filt3 || !voice3off) ? fmc->getNormalizedVoice(voice3) : 0;
203
204 int Vsum = 0;
205 int Vmix = 0;
206
207 (filt1 ? Vsum : Vmix) += V1;
208 (filt2 ? Vsum : Vmix) += V2;
209 (filt3 ? Vsum : Vmix) += V3;
210 (filtE ? Vsum : Vmix) += Ve;
211
212 Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vsum];
213 Vbp = hpIntegrator->solve(Vhp);
214 Vlp = bpIntegrator->solve(Vbp);
215
216 if (lp) Vmix += Vlp;
217 if (bp) Vmix += Vbp;
218 if (hp) Vmix += Vhp;
219
220 return currentVolume[currentMixer[Vmix]];
221}
222
223} // namespace reSIDfp
224
225#endif
226
227#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:112
void writeFC_LO(unsigned char fc_lo)
Definition Filter.cpp:54
unsigned short clock(float v1, float v2, float v3)
Definition Filter.h:197
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:184
void enable(bool enable)
Definition Filter.cpp:132
void reset()
Definition Filter.cpp:146
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:122
Integrator *const hpIntegrator
VCR + associated capacitor connected to highpass output.
Definition Filter.h:50
Definition Integrator.h:30