libresidfp 1.2.1
ExternalFilter.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2025 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2004 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 EXTERNALFILTER_H
24#define EXTERNALFILTER_H
25
26#include "siddefs-fp.h"
27
28#include <cstdint>
29
30namespace reSIDfp
31{
32
87{
88 friend class State;
89
90private:
92 int32_t Vlp;
93
95 int32_t Vhp;
96
97 int32_t w0lp_1_s7 = 0;
98
99 int32_t w0hp_1_s17 = 0;
100
101 double m_frequency;
102
103 double m_ext_res = 10e3;
104
105private:
106 void recalcParams();
107
108public:
115 int32_t clock(int32_t input);
116
121
127 void setClockFrequency(double frequency);
128
134 void setExtResistance(double res);
135
139 void reset();
140};
141
142} // namespace reSIDfp
143
144#if RESIDFP_INLINING || defined(EXTERNALFILTER_CPP)
145
146namespace reSIDfp
147{
148
149RESIDFP_INLINE
150int32_t ExternalFilter::clock(int32_t input)
151{
152 const int32_t Vi = input << 11;
153 const int32_t dVlp = (w0lp_1_s7 * (Vi - Vlp)) >> 7;
154 const int32_t dVhp = (w0hp_1_s17 * (Vlp - Vhp)) >> 17;
155 Vlp += dVlp;
156 Vhp += dVhp;
157 return (Vlp - Vhp) >> 11;
158}
159
160} // namespace reSIDfp
161
162#endif
163
164#endif
Definition ExternalFilter.h:87
void reset()
Definition ExternalFilter.cpp:71
void setClockFrequency(double frequency)
Definition ExternalFilter.cpp:46
int32_t clock(int32_t input)
Definition ExternalFilter.h:150
ExternalFilter()
Definition ExternalFilter.cpp:41
void setExtResistance(double res)
Definition ExternalFilter.cpp:52
Definition State.h:46