libsidplayfp 2.6.0
Filter6581.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2022 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_res;
330 unsigned short** gain_vol;
331
332 const int voiceScaleS11;
333 const int voiceDC;
334
336 std::unique_ptr<Integrator6581> const hpIntegrator;
337
339 std::unique_ptr<Integrator6581> const bpIntegrator;
340
341protected:
345 void updatedCenterFrequency() override;
346
352 void updateResonance(unsigned char res) override { currentResonance = gain_res[res]; }
353
354 void updatedMixing() override;
355
356public:
357 Filter6581() :
358 f0_dac(FilterModelConfig6581::getInstance()->getDAC(0.5)),
359 mixer(FilterModelConfig6581::getInstance()->getMixer()),
360 summer(FilterModelConfig6581::getInstance()->getSummer()),
361 gain_res(FilterModelConfig6581::getInstance()->getGainRes()),
362 gain_vol(FilterModelConfig6581::getInstance()->getGainVol()),
363 voiceScaleS11(FilterModelConfig6581::getInstance()->getVoiceScaleS11()),
364 voiceDC(FilterModelConfig6581::getInstance()->getNormalizedVoiceDC()),
365 hpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator()),
366 bpIntegrator(FilterModelConfig6581::getInstance()->buildIntegrator())
367 {
368 input(0);
369 }
370
371 ~Filter6581();
372
373 unsigned short clock(int voice1, int voice2, int voice3) override;
374
375 void input(int sample) override { ve = (sample * voiceScaleS11 * 3 >> 11) + mixer[0][0]; }
376
382 void setFilterCurve(double curvePosition);
383};
384
385} // namespace reSIDfp
386
387#if RESID_INLINING || defined(FILTER6581_CPP)
388
389#include "Integrator6581.h"
390
391namespace reSIDfp
392{
393
394RESID_INLINE
395unsigned short Filter6581::clock(int voice1, int voice2, int voice3)
396{
397 voice1 = (voice1 * voiceScaleS11 >> 15) + voiceDC;
398 voice2 = (voice2 * voiceScaleS11 >> 15) + voiceDC;
399 // Voice 3 is silenced by voice3off if it is not routed through the filter.
400 voice3 = (filt3 || !voice3off) ? (voice3 * voiceScaleS11 >> 15) + voiceDC : 0;
401
402 int Vi = 0;
403 int Vo = 0;
404
405 (filt1 ? Vi : Vo) += voice1;
406 (filt2 ? Vi : Vo) += voice2;
407 (filt3 ? Vi : Vo) += voice3;
408 (filtE ? Vi : Vo) += ve;
409
411 Vbp = hpIntegrator->solve(Vhp);
412 Vlp = bpIntegrator->solve(Vbp);
413
414 if (lp) Vo += Vlp;
415 if (bp) Vo += Vbp;
416 if (hp) Vo += Vhp;
417
418 return currentGain[currentMixer[Vo]];
419}
420
421} // namespace reSIDfp
422
423#endif
424
425#endif
Definition Filter6581.h:323
void updateResonance(unsigned char res) override
Definition Filter6581.h:352
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:395
void updatedMixing() override
Definition Filter6581.cpp:44
Definition FilterModelConfig6581.h:43
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