Filter6581.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2013 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 "FilterModelConfig.h"
namespace reSIDfp
{
class Integrator;
class Filter6581 : public Filter
{
private:
unsigned short* currentGain;
unsigned short* currentMixer;
unsigned short* currentSummer;
unsigned short* currentResonance;
const unsigned short* f0_dac;
unsigned short** mixer;
unsigned short** summer;
unsigned short** gain;
int Vhp;
int Vbp;
int Vlp;
int ve;
const int voiceScaleS14;
const int voiceDC;
std::auto_ptr<Integrator> hpIntegrator;
std::auto_ptr<Integrator> bpIntegrator;
public:
Filter6581() :
currentGain(0),
currentMixer(0),
currentSummer(0),
currentResonance(0),
f0_dac(FilterModelConfig::getInstance()->getDAC(0.5)),
mixer(FilterModelConfig::getInstance()->getMixer()),
summer(FilterModelConfig::getInstance()->getSummer()),
gain(FilterModelConfig::getInstance()->getGain()),
Vhp(0),
Vbp(0),
Vlp(0),
ve(0),
voiceScaleS14(FilterModelConfig::getInstance()->getVoiceScaleS14()),
voiceDC(FilterModelConfig::getInstance()->getVoiceDC()),
hpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
bpIntegrator(FilterModelConfig::getInstance()->buildIntegrator())
{
input(0);
}
~Filter6581();
int clock(int voice1, int voice2, int voice3);
void input(int sample) { ve = (sample * voiceScaleS14 * 3 >> 10) + mixer[0][0]; }
void updatedCenterFrequency();
void updatedResonance() { currentResonance = gain[~res & 0xf]; }
void updatedMixing();
public:
void setFilterCurve(double curvePosition);
};
} // namespace reSIDfp
#if RESID_INLINING || defined(FILTER6581_CPP)
#include "Integrator.h"
namespace reSIDfp
{
RESID_INLINE
int Filter6581::clock(int voice1, int voice2, int voice3)
{
voice1 = (voice1 * voiceScaleS14 >> 18) + voiceDC;
voice2 = (voice2 * voiceScaleS14 >> 18) + voiceDC;
voice3 = (voice3 * voiceScaleS14 >> 18) + voiceDC;
int Vi = 0;
int Vo = 0;
(filt1 ? Vi : Vo) += voice1;
(filt2 ? Vi : Vo) += voice2;
// NB! Voice 3 is not silenced by voice3off if it is routed
// through the filter.
if (filt3)
{
Vi += voice3;
}
else if (!voice3off)
{
Vo += voice3;
}
(filtE ? Vi : Vo) += ve;
const int oldVhp = Vhp;
Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vi];
Vlp = bpIntegrator->solve(Vbp);
Vbp = hpIntegrator->solve(oldVhp);
if (lp)
{
Vo += Vlp;
}
if (bp)
{
Vo += Vbp;
}
if (hp)
{
Vo += Vhp;
}
return currentGain[currentMixer[Vo]] - (1 << 15);
}
} // namespace reSIDfp
#endif
#endif
reSIDfp::Filter6581::setFilterCurve
void setFilterCurve(double curvePosition)
Definition: Filter6581.cpp:84
reSIDfp::Filter::filt1
bool filt1
Routing to filter or outside filter.
Definition: Filter.h:45
reSIDfp::Filter
Definition: Filter.h:32
reSIDfp::Filter::hp
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition: Filter.h:51
reSIDfp::Filter6581::updatedCenterFrequency
void updatedCenterFrequency()
Definition: Filter6581.cpp:35
reSIDfp::Filter6581::updatedMixing
void updatedMixing()
Definition: Filter6581.cpp:42
reSIDfp::Filter::voice3off
bool voice3off
Switch voice 3 off.
Definition: Filter.h:48
reSIDfp::Filter::res
unsigned char res
Filter resonance.
Definition: Filter.h:39
reSIDfp::Filter6581::updatedResonance
void updatedResonance()
Definition: Filter6581.h:400
reSIDfp::Filter6581
Definition: Filter6581.h:320
reSIDfp::Filter6581::clock
int clock(int voice1, int voice2, int voice3)
Definition: Filter6581.h:423