Filter.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2024 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2004 Dag Lem <resid@nimrod.no>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FILTER_H
#define FILTER_H
#include "FilterModelConfig.h"
#include "siddefs-fp.h"
namespace reSIDfp
{
class Filter
{
private:
unsigned short** mixer;
unsigned short** summer;
unsigned short** resonance;
unsigned short** volume;
protected:
FilterModelConfig& fmc;
unsigned short* currentMixer = nullptr;
unsigned short* currentSummer = nullptr;
unsigned short* currentResonance = nullptr;
unsigned short* currentVolume = nullptr;
int Vhp = 0;
int Vbp = 0;
int Vlp = 0;
int Ve = 0;
unsigned int fc = 0;
bool filt1 = false;
bool filt2 = false;
bool filt3 = false;
bool filtE = false;
bool voice3off = false;
bool hp = false;
bool bp = false;
bool lp = false;
private:
unsigned char vol = 0;
bool enabled = true;
unsigned char filt = 0;
protected:
virtual void updateCenterFrequency() = 0;
void updateResonance(unsigned char res) { currentResonance = resonance[res]; }
void updateMixing();
unsigned int getFC() const { return fc; }
public:
Filter(FilterModelConfig& fmc);
virtual ~Filter() = default;
virtual unsigned short clock(int v1, int v2, int v3) = 0;
void enable(bool enable);
void reset();
void writeFC_LO(unsigned char fc_lo);
void writeFC_HI(unsigned char fc_hi);
void writeRES_FILT(unsigned char res_filt);
void writeMODE_VOL(unsigned char mode_vol);
void input(short input) { Ve = fmc.getNormalizedVoice(input/32768.f, 0); }
inline int getNormalizedVoice(float value, unsigned int env) const { return fmc.getNormalizedVoice(value, env); }
};
} // namespace reSIDfp
#endif
reSIDfp::FilterModelConfig
Definition FilterModelConfig.h:39
reSIDfp::Filter
Definition Filter.h:37
reSIDfp::Filter::clock
virtual unsigned short clock(int v1, int v2, int v3)=0
reSIDfp::Filter::hp
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition Filter.h:87
reSIDfp::Filter::currentVolume
unsigned short * currentVolume
Current volume amplifier setting.
Definition Filter.h:57
reSIDfp::Filter::Vbp
int Vbp
Filter bandpass state.
Definition Filter.h:63
reSIDfp::Filter::updateResonance
void updateResonance(unsigned char res)
Definition Filter.h:113
reSIDfp::Filter::currentSummer
unsigned short * currentSummer
Filter input summer setting.
Definition Filter.h:51
reSIDfp::Filter::writeFC_LO
void writeFC_LO(unsigned char fc_lo)
Definition Filter.cpp:54
reSIDfp::Filter::writeRES_FILT
void writeRES_FILT(unsigned char res_filt)
Definition Filter.cpp:66
reSIDfp::Filter::voice3off
bool voice3off
Switch voice 3 off.
Definition Filter.h:83
reSIDfp::Filter::currentMixer
unsigned short * currentMixer
Current filter/voice mixer setting.
Definition Filter.h:48
reSIDfp::Filter::writeFC_HI
void writeFC_HI(unsigned char fc_hi)
Definition Filter.cpp:60
reSIDfp::Filter::Vhp
int Vhp
Filter highpass state.
Definition Filter.h:60
reSIDfp::Filter::currentResonance
unsigned short * currentResonance
Filter resonance value.
Definition Filter.h:54
reSIDfp::Filter::filt1
bool filt1
Routing to filter or outside filter.
Definition Filter.h:76
reSIDfp::Filter::Vlp
int Vlp
Filter lowpass state.
Definition Filter.h:66
reSIDfp::Filter::Ve
int Ve
Filter external input.
Definition Filter.h:69
reSIDfp::Filter::enable
void enable(bool enable)
Definition Filter.cpp:104
reSIDfp::Filter::reset
void reset()
Definition Filter.cpp:118
reSIDfp::Filter::updateCenterFrequency
virtual void updateCenterFrequency()=0
reSIDfp::Filter::updateMixing
void updateMixing()
Definition Filter.cpp:30
reSIDfp::Filter::input
void input(short input)
Definition Filter.h:185
reSIDfp::Filter::writeMODE_VOL
void writeMODE_VOL(unsigned char mode_vol)
Definition Filter.cpp:83
reSIDfp::Filter::fc
unsigned int fc
Filter cutoff frequency.
Definition Filter.h:72
reSIDfp::Filter::getFC
unsigned int getFC() const
Definition Filter.h:123