Debian Codegraph @

src/resid-fp/filterfp.cpp

raw symbols SCIP
1 // ---------------------------------------------------------------------------cxx . . $ `<file>/src/resid-fp/filterfp.cpp`/
2 // This file is part of reSID, a MOS6581 SID emulator engine.
3 // Copyright (C) 2004 Dag Lem <[email protected]>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ---------------------------------------------------------------------------
19 // Filter distortion code written by Antti S. Lankila 2007 - 2009.
20
21 #include "filterfp.h"cxx . . $ `<file>/src/resid-fp/filterfp.h`/
22 #include "sidfp.h"cxx . . $ `<file>/src/resid-fp/sidfp.h`/
23
24 // ----------------------------------------------------------------------------
25 // Constructor.
26 // ----------------------------------------------------------------------------
27 FilterFPcxx . . $ FilterFP#::FilterFPcxx . . $ FilterFP#FilterFP(49f6e7a06ebc5aa8).()
28 {
29 modelcxx . . $ FilterFP#model. = (chip_modelcxx . . $ chip_model#) 0; // neither 6581/8580; init time only
30 enable_filtercxx . . $ FilterFP#enable_filter(b45ddcbc8423892c).(true);
31 /* approximate; sid.cc calls us when set_sampling_parameters() occurs. */
32 set_clock_frequencycxx . . $ FilterFP#set_clock_frequency(9364e6e7bff7660).(1e6f);
33 /* these parameters are a work-in-progress. */
34 set_distortion_propertiescxx . . $ FilterFP#set_distortion_properties(bd1040fe176e0786).(0.5f, 3.3e6f, 3.0e-4f);
35 /* sound similar to alankila6581r4ar3789 */
36 set_type3_propertiescxx . . $ FilterFP#set_type3_properties(7e9a355db6148521).(1299501.5675945764f, 284015710.29875594f, 1.0065089724604026f, 18741.324073610594f);
37 /* sound similar to trurl8580r5_3691 */
38 set_type4_propertiescxx . . $ FilterFP#set_type4_properties(5102ef758adc0ae7).(6.55f, 20.f);
39 resetcxx . . $ FilterFP#reset(49f6e7a06ebc5aa8).();
40 set_chip_modelcxx . . $ FilterFP#set_chip_model(cea143c94d31b99f).(MOS6581cxx . . $ MOS6581.);
41 }
42
43
44 // ----------------------------------------------------------------------------
45 // Enable filter.
46 // ----------------------------------------------------------------------------
47 void FilterFPcxx . . $ FilterFP#::enable_filtercxx . . $ FilterFP#enable_filter(b45ddcbc8423892c).(bool enable)
48 {
49 enabledcxx . . $ FilterFP#enabled. = enable;
50 if (! enabledcxx . . $ FilterFP#enabled.)
51 filtcxx . . $ FilterFP#filt. = 0; // XXX should also restore this...
52 }
53
54 // ----------------------------------------------------------------------------
55 // Set chip model.
56 // ----------------------------------------------------------------------------
57 void FilterFPcxx . . $ FilterFP#::set_chip_modelcxx . . $ FilterFP#set_chip_model(cea143c94d31b99f).(chip_modelcxx . . $ chip_model# model)
58 {
59 this->modelcxx . . $ FilterFP#model. = model;
60 set_Qcxx . . $ FilterFP#set_Q(49f6e7a06ebc5aa8).();
61 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
62 }
63
64 void FilterFPcxx . . $ FilterFP#::set_nonlinearitycxx . . $ FilterFP#set_nonlinearity(9364e6e7bff7660).(float nl)
65 {
66 nonlinearitycxx . . $ FilterFP#nonlinearity. = nl;
67 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
68 }
69
70 /* dist_CT eliminates 1/x at hot spot */
71 void FilterFPcxx . . $ FilterFP#::set_clock_frequencycxx . . $ FilterFP#set_clock_frequency(9364e6e7bff7660).(float clock) {
72 clock_frequencycxx . . $ FilterFP#clock_frequency. = clock;
73 distortion_CTcxx . . $ FilterFP#distortion_CT. = 1.f / (sidcaps_6581cxx . . $ sidcaps_6581. * clock_frequencycxx . . $ FilterFP#clock_frequency.);
74 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
75 }
76
77 void FilterFPcxx . . $ FilterFP#::set_distortion_propertiescxx . . $ FilterFP#set_distortion_properties(bd1040fe176e0786).(float a, float nl, float il)
78 {
79 attenuationcxx . . $ FilterFP#attenuation. = a;
80 distortion_nonlinearitycxx . . $ FilterFP#distortion_nonlinearity. = nl;
81 intermixing_leakscxx . . $ FilterFP#intermixing_leaks. = il;
82 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
83 }
84
85 void FilterFPcxx . . $ FilterFP#::set_type4_propertiescxx . . $ FilterFP#set_type4_properties(5102ef758adc0ae7).(float k, float b)
86 {
87 type4_kcxx . . $ FilterFP#type4_k. = k;
88 type4_bcxx . . $ FilterFP#type4_b. = b;
89 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
90 }
91
92 void FilterFPcxx . . $ FilterFP#::set_type3_propertiescxx . . $ FilterFP#set_type3_properties(7e9a355db6148521).(float br, float o, float s, float mfr)
93 {
94 type3_baseresistancecxx . . $ FilterFP#type3_baseresistance. = br;
95 type3_offsetcxx . . $ FilterFP#type3_offset. = o;
96 type3_steepnesscxx . . $ FilterFP#type3_steepness. = -logf(s) / FC_TO_OSCcxx . . $ FC_TO_OSC.; /* s^x to e^(x*ln(s)), 1/e^x == e^-x. */
97 type3_minimumfetresistancecxx . . $ FilterFP#type3_minimumfetresistance. = mfr;
98 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
99 }
100
101 // ----------------------------------------------------------------------------
102 // SID reset.
103 // ----------------------------------------------------------------------------
104 void FilterFPcxx . . $ FilterFP#::resetcxx . . $ FilterFP#reset(49f6e7a06ebc5aa8).()
105 {
106 fccxx . . $ FilterFP#fc. = 0;
107 rescxx . . $ FilterFP#res. = filtcxx . . $ FilterFP#filt. = voice3offcxx . . $ FilterFP#voice3off. = hp_bp_lpcxx . . $ FilterFP#hp_bp_lp. = 0;
108 volcxx . . $ FilterFP#vol. = 0;
109 volfcxx . . $ FilterFP#volf. = Vhpcxx . . $ FilterFP#Vhp. = Vbpcxx . . $ FilterFP#Vbp. = Vlpcxx . . $ FilterFP#Vlp. = 0;
110 type3_fc_kink_expcxx . . $ FilterFP#type3_fc_kink_exp. = 0;
111 type4_w0_cachecxx . . $ FilterFP#type4_w0_cache. = 0;
112 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
113 set_Qcxx . . $ FilterFP#set_Q(49f6e7a06ebc5aa8).();
114 }
115
116 // ----------------------------------------------------------------------------
117 // Register functions.
118 // ----------------------------------------------------------------------------
119 void FilterFPcxx . . $ FilterFP#::writeFC_LOcxx . . $ FilterFP#writeFC_LO(cb2f890c2fdad230).(reg8cxx . . $ reg8# fc_lo)
120 {
121 fccxx . . $ FilterFP#fc. = (fccxx . . $ FilterFP#fc. & 0x7f8) | (fc_lo & 0x007);
122 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
123 }
124
125 void FilterFPcxx . . $ FilterFP#::writeFC_HIcxx . . $ FilterFP#writeFC_HI(cb2f890c2fdad230).(reg8cxx . . $ reg8# fc_hi)
126 {
127 fccxx . . $ FilterFP#fc. = ((fc_hi << 3) & 0x7f8) | (fccxx . . $ FilterFP#fc. & 0x007);
128 set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).();
129 }
130
131 void FilterFPcxx . . $ FilterFP#::writeRES_FILTcxx . . $ FilterFP#writeRES_FILT(cb2f890c2fdad230).(reg8cxx . . $ reg8# res_filt)
132 {
133 rescxx . . $ FilterFP#res. = (res_filt >> 4) & 0x0f;
134 set_Qcxx . . $ FilterFP#set_Q(49f6e7a06ebc5aa8).();
135 filtcxx . . $ FilterFP#filt. = enabledcxx . . $ FilterFP#enabled. ? res_filt & 0x0f : 0;
136 }
137
138 void FilterFPcxx . . $ FilterFP#::writeMODE_VOLcxx . . $ FilterFP#writeMODE_VOL(cb2f890c2fdad230).(reg8cxx . . $ reg8# mode_vol)
139 {
140 voice3offcxx . . $ FilterFP#voice3off. = mode_vol & 0x80;
141
142 hp_bp_lpcxx . . $ FilterFP#hp_bp_lp. = mode_vol >> 4;
143
144 volcxx . . $ FilterFP#vol. = mode_vol & 0x0f;
145 volfcxx . . $ FilterFP#volf. = static_cast<float>(volcxx . . $ FilterFP#vol.) / 15.f;
146 }
147
148 // Set filter cutoff frequency.
149 void FilterFPcxx . . $ FilterFP#::set_w0cxx . . $ FilterFP#set_w0(49f6e7a06ebc5aa8).()
150 {
151 if (modelcxx . . $ FilterFP#model. == MOS6581cxx . . $ MOS6581.) {
152 float type3_fc_kink = SIDFPcxx . . $ SIDFP#::kinked_daccxx . . $ SIDFP#kinked_dac(7555465bc4331e8c).(fccxx . . $ FilterFP#fc., nonlinearitycxx . . $ FilterFP#nonlinearity., 11);
153 type3_fc_kink_expcxx . . $ FilterFP#type3_fc_kink_exp. = type3_offsetcxx . . $ FilterFP#type3_offset. * expf(type3_fc_kink * type3_steepnesscxx . . $ FilterFP#type3_steepness. * FC_TO_OSCcxx . . $ FC_TO_OSC.);
154 }
155 if (modelcxx . . $ FilterFP#model. == MOS8580cxx . . $ MOS8580.) {
156 type4_w0_cachecxx . . $ FilterFP#type4_w0_cache. = type4_w0cxx . . $ FilterFP#type4_w0(9b8c9e39889c762c).();
157 }
158 }
159
160 // Set filter resonance.
161 void FilterFPcxx . . $ FilterFP#::set_Qcxx . . $ FilterFP#set_Q(49f6e7a06ebc5aa8).()
162 {
163 if (modelcxx . . $ FilterFP#model. == MOS6581cxx . . $ MOS6581.) {
164 _1_div_Qcxx . . $ FilterFP#_1_div_Q. = 1.f / (0.5f + rescxx . . $ FilterFP#res. / 20.f);
165 } else {
166 _1_div_Qcxx . . $ FilterFP#_1_div_Q. = 1.f / (0.707f + rescxx . . $ FilterFP#res. / 15.f);
167 }
168 }