libsidplayfp 2.3.1
Filter6581.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2004,2010 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 FILTER6581_H
24#define FILTER6581_H
25
26#include "siddefs-fp.h"
27
28#include <memory>
29
30#include "Filter.h"
31#include "FilterModelConfig6581.h"
32
33#include "sidcxx11.h"
34
35namespace reSIDfp
36{
37
38class Integrator6581;
39
322class Filter6581 final : public Filter
323{
324private:
325 const unsigned short* f0_dac;
326
327 unsigned short** mixer;
328 unsigned short** summer;
329 unsigned short** gain;
330
331 const int voiceScaleS11;
332 const int voiceDC;
333
335 std::unique_ptr<Integrator6581> const hpIntegrator;
336
338 std::unique_ptr<Integrator6581> const bpIntegrator;
339
340protected:
344 void updatedCenterFrequency() override;
345
351 void updateResonance(unsigned char res) override { currentResonance = gain[~res & 0xf]; }
352
353 void updatedMixing() override;
354
355public:
356 Filter6581() :
357 f0_dac(FilterModelConfig6581::getInstance()->getDAC(0.5)),
358 mixer(FilterModelConfig6581::getInstance()->getMixer()),
359 summer(FilterModelConfig6581::getInstance()->getSummer()),
360 gain(FilterModelConfig6581::getInstance()->getGain()),
361 voiceScaleS11(FilterModelConfig6581::getInstance()->getVoiceScaleS11()),
362 voiceDC(FilterModelConfig6581::getInstance()->getVoiceDC()),
363 hpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator()),
364 bpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator())
365 {
366 input(0);
367 }
368
369 ~Filter6581();
370
371 unsigned short clock(int voice1, int voice2, int voice3) override;
372
373 void input(int sample) override { ve = (sample * voiceScaleS11 * 3 >> 11) + mixer[0][0]; }
374
380 void setFilterCurve(double curvePosition);
381};
382
383} // namespace reSIDfp
384
385#if RESID_INLINING || defined(FILTER6581_CPP)
386
387#include "Integrator6581.h"
388
389namespace reSIDfp
390{
391
392RESID_INLINE
393unsigned short Filter6581::clock(int voice1, int voice2, int voice3)
394{
395 voice1 = (voice1 * voiceScaleS11 >> 15) + voiceDC;
396 voice2 = (voice2 * voiceScaleS11 >> 15) + voiceDC;
397 // Voice 3 is silenced by voice3off if it is not routed through the filter.
398 voice3 = (filt3 || !voice3off) ? (voice3 * voiceScaleS11 >> 15) + voiceDC : 0;
399
400 int Vi = 0;
401 int Vo = 0;
402
403 (filt1 ? Vi : Vo) += voice1;
404 (filt2 ? Vi : Vo) += voice2;
405 (filt3 ? Vi : Vo) += voice3;
406 (filtE ? Vi : Vo) += ve;
407
409 Vbp = hpIntegrator->solve(Vhp);
410 Vlp = bpIntegrator->solve(Vbp);
411
412 if (lp) Vo += Vlp;
413 if (bp) Vo += Vbp;
414 if (hp) Vo += Vhp;
415
416 return currentGain[currentMixer[Vo]];
417}
418
419} // namespace reSIDfp
420
421#endif
422
423#endif
Definition: Filter6581.h:323
void updateResonance(unsigned char res) override
Definition: Filter6581.h:351
void updatedCenterFrequency() override
Definition: Filter6581.cpp:37
void setFilterCurve(double curvePosition)
Definition: Filter6581.cpp:68
unsigned short clock(int voice1, int voice2, int voice3) override
Definition: Filter6581.h:393
void updatedMixing() override
Definition: Filter6581.cpp:44
Definition: FilterModelConfig6581.h:42
Definition: Filter.h:33
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition: Filter.h:69
unsigned short * currentGain
Current volume amplifier setting.
Definition: Filter.h:36
int Vbp
Filter bandpass state.
Definition: Filter.h:51
unsigned short * currentSummer
Filter input summer setting.
Definition: Filter.h:42
bool voice3off
Switch voice 3 off.
Definition: Filter.h:66
unsigned short * currentMixer
Current filter/voice mixer setting.
Definition: Filter.h:39
int ve
Filter external input.
Definition: Filter.h:57
int Vhp
Filter highpass state.
Definition: Filter.h:48
unsigned short * currentResonance
Filter resonance value.
Definition: Filter.h:45
bool filt1
Routing to filter or outside filter.
Definition: Filter.h:63
int Vlp
Filter lowpass state.
Definition: Filter.h:54