libsidplayfp 2.11.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
36class Filter
37{
38private:
39 unsigned short** mixer;
40 unsigned short** summer;
41 unsigned short** resonance;
42 unsigned short** volume;
43
44protected:
46
48 unsigned short* currentMixer = nullptr;
49
51 unsigned short* currentSummer = nullptr;
52
54 unsigned short* currentResonance = nullptr;
55
57 unsigned short* currentVolume = nullptr;
58
60 int Vhp = 0;
61
63 int Vbp = 0;
64
66 int Vlp = 0;
67
69 int Ve = 0;
70
72 unsigned int fc = 0;
73
75
76 bool filt1 = false;
77 bool filt2 = false;
78 bool filt3 = false;
79 bool filtE = false;
81
83 bool voice3off = false;
84
86
87 bool hp = false;
88 bool bp = false;
89 bool lp = false;
91
92private:
94 unsigned char vol = 0;
95
97 bool enabled = true;
98
100 unsigned char filt = 0;
101
102protected:
106 virtual void updateCenterFrequency() = 0;
107
113 void updateResonance(unsigned char res) { currentResonance = resonance[res]; }
114
118 void updateMixing();
119
123 unsigned int getFC() const { return fc; }
124
125public:
127
128 virtual ~Filter() = default;
129
138 virtual unsigned short clock(int v1, int v2, int v3) = 0;
139
145 void enable(bool enable);
146
150 void reset();
151
157 void writeFC_LO(unsigned char fc_lo);
158
164 void writeFC_HI(unsigned char fc_hi);
165
171 void writeRES_FILT(unsigned char res_filt);
172
178 void writeMODE_VOL(unsigned char mode_vol);
179
185 void input(short input) { Ve = fmc.getNormalizedVoice(input/32768.f, 0); }
186
187 inline int getNormalizedVoice(float value, unsigned int env) const { return fmc.getNormalizedVoice(value, env); }
188};
189
190} // namespace reSIDfp
191
192#endif
Definition FilterModelConfig.h:39
Definition Filter.h:37
virtual unsigned short clock(int v1, int v2, int v3)=0
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition Filter.h:87
unsigned short * currentVolume
Current volume amplifier setting.
Definition Filter.h:57
int Vbp
Filter bandpass state.
Definition Filter.h:63
void updateResonance(unsigned char res)
Definition Filter.h:113
unsigned short * currentSummer
Filter input summer setting.
Definition Filter.h:51
void writeFC_LO(unsigned char fc_lo)
Definition Filter.cpp:54
void writeRES_FILT(unsigned char res_filt)
Definition Filter.cpp:66
bool voice3off
Switch voice 3 off.
Definition Filter.h:83
unsigned short * currentMixer
Current filter/voice mixer setting.
Definition Filter.h:48
void writeFC_HI(unsigned char fc_hi)
Definition Filter.cpp:60
int Vhp
Filter highpass state.
Definition Filter.h:60
unsigned short * currentResonance
Filter resonance value.
Definition Filter.h:54
bool filt1
Routing to filter or outside filter.
Definition Filter.h:76
int Vlp
Filter lowpass state.
Definition Filter.h:66
int Ve
Filter external input.
Definition Filter.h:69
void enable(bool enable)
Definition Filter.cpp:104
void reset()
Definition Filter.cpp:118
virtual void updateCenterFrequency()=0
void updateMixing()
Definition Filter.cpp:30
void input(short input)
Definition Filter.h:185
void writeMODE_VOL(unsigned char mode_vol)
Definition Filter.cpp:83
unsigned int fc
Filter cutoff frequency.
Definition Filter.h:72
unsigned int getFC() const
Definition Filter.h:123