Filter6581.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2004,2010 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 FILTER6581_H
#define FILTER6581_H
#include "siddefs-fp.h"
#include <memory>
#include "Filter.h"
#include "FilterModelConfig6581.h"
#include "sidcxx11.h"
namespace reSIDfp
{
class Integrator6581;
class Filter6581 final : public Filter
{
private:
const unsigned short* f0_dac;
unsigned short** mixer;
unsigned short** summer;
unsigned short** gain;
const int voiceScaleS11;
const int voiceDC;
std::unique_ptr<Integrator6581> const hpIntegrator;
std::unique_ptr<Integrator6581> const bpIntegrator;
protected:
void updatedCenterFrequency() override;
void updateResonance(unsigned char res) override { currentResonance = gain[~res & 0xf]; }
void updatedMixing() override;
public:
Filter6581() :
f0_dac(FilterModelConfig6581::getInstance()->getDAC(0.5)),
mixer(FilterModelConfig6581::getInstance()->getMixer()),
summer(FilterModelConfig6581::getInstance()->getSummer()),
gain(FilterModelConfig6581::getInstance()->getGain()),
voiceScaleS11(FilterModelConfig6581::getInstance()->getVoiceScaleS11()),
voiceDC(FilterModelConfig6581::getInstance()->getVoiceDC()),
hpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator()),
bpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator())
{
input(0);
}
~Filter6581();
unsigned short clock(int voice1, int voice2, int voice3) override;
void input(int sample) override { ve = (sample * voiceScaleS11 * 3 >> 11) + mixer[0][0]; }
void setFilterCurve(double curvePosition);
};
} // namespace reSIDfp
#if RESID_INLINING || defined(FILTER6581_CPP)
#include "Integrator6581.h"
namespace reSIDfp
{
RESID_INLINE
unsigned short Filter6581::clock(int voice1, int voice2, int voice3)
{
voice1 = (voice1 * voiceScaleS11 >> 15) + voiceDC;
voice2 = (voice2 * voiceScaleS11 >> 15) + voiceDC;
// Voice 3 is silenced by voice3off if it is not routed through the filter.
voice3 = (filt3 || !voice3off) ? (voice3 * voiceScaleS11 >> 15) + voiceDC : 0;
int Vi = 0;
int Vo = 0;
(filt1 ? Vi : Vo) += voice1;
(filt2 ? Vi : Vo) += voice2;
(filt3 ? Vi : Vo) += voice3;
(filtE ? Vi : Vo) += ve;
Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vi];
Vbp = hpIntegrator->solve(Vhp);
Vlp = bpIntegrator->solve(Vbp);
if (lp) Vo += Vlp;
if (bp) Vo += Vbp;
if (hp) Vo += Vhp;
return currentGain[currentMixer[Vo]];
}
} // namespace reSIDfp
#endif
#endif
reSIDfp::Filter6581
Definition: Filter6581.h:323
reSIDfp::Filter6581::updateResonance
void updateResonance(unsigned char res) override
Definition: Filter6581.h:351
reSIDfp::Filter6581::updatedCenterFrequency
void updatedCenterFrequency() override
Definition: Filter6581.cpp:37
reSIDfp::Filter6581::setFilterCurve
void setFilterCurve(double curvePosition)
Definition: Filter6581.cpp:68
reSIDfp::Filter6581::clock
unsigned short clock(int voice1, int voice2, int voice3) override
Definition: Filter6581.h:393
reSIDfp::Filter6581::updatedMixing
void updatedMixing() override
Definition: Filter6581.cpp:44
reSIDfp::FilterModelConfig6581
Definition: FilterModelConfig6581.h:42
reSIDfp::Filter
Definition: Filter.h:33
reSIDfp::Filter::hp
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition: Filter.h:69
reSIDfp::Filter::currentGain
unsigned short * currentGain
Current volume amplifier setting.
Definition: Filter.h:36
reSIDfp::Filter::Vbp
int Vbp
Filter bandpass state.
Definition: Filter.h:51
reSIDfp::Filter::currentSummer
unsigned short * currentSummer
Filter input summer setting.
Definition: Filter.h:42
reSIDfp::Filter::voice3off
bool voice3off
Switch voice 3 off.
Definition: Filter.h:66
reSIDfp::Filter::currentMixer
unsigned short * currentMixer
Current filter/voice mixer setting.
Definition: Filter.h:39
reSIDfp::Filter::ve
int ve
Filter external input.
Definition: Filter.h:57
reSIDfp::Filter::Vhp
int Vhp
Filter highpass state.
Definition: Filter.h:48
reSIDfp::Filter::currentResonance
unsigned short * currentResonance
Filter resonance value.
Definition: Filter.h:45
reSIDfp::Filter::filt1
bool filt1
Routing to filter or outside filter.
Definition: Filter.h:63
reSIDfp::Filter::Vlp
int Vlp
Filter lowpass state.
Definition: Filter.h:54