1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 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 #include "Filter.h"
24 
25 namespace reSIDfp
26 {
27 
enable(bool enable)28 void Filter::enable(bool enable)
29 {
30     enabled = enable;
31 
32     if (enabled)
33     {
34         writeRES_FILT(filt);
35     }
36     else
37     {
38         filt1 = filt2 = filt3 = filtE = false;
39     }
40 }
41 
reset()42 void Filter::reset()
43 {
44     writeFC_LO(0);
45     writeFC_HI(0);
46     writeMODE_VOL(0);
47     writeRES_FILT(0);
48 }
49 
writeFC_LO(unsigned char fc_lo)50 void Filter::writeFC_LO(unsigned char fc_lo)
51 {
52     fc = (fc & 0x7f8) | (fc_lo & 0x007);
53     updatedCenterFrequency();
54 }
55 
writeFC_HI(unsigned char fc_hi)56 void Filter::writeFC_HI(unsigned char fc_hi)
57 {
58     fc = (fc_hi << 3 & 0x7f8) | (fc & 0x007);
59     updatedCenterFrequency();
60 }
61 
writeRES_FILT(unsigned char res_filt)62 void Filter::writeRES_FILT(unsigned char res_filt)
63 {
64     filt = res_filt;
65 
66     updateResonance((res_filt >> 4) & 0x0f);
67 
68     if (enabled)
69     {
70         filt1 = (filt & 0x01) != 0;
71         filt2 = (filt & 0x02) != 0;
72         filt3 = (filt & 0x04) != 0;
73         filtE = (filt & 0x08) != 0;
74     }
75 
76     updatedMixing();
77 }
78 
writeMODE_VOL(unsigned char mode_vol)79 void Filter::writeMODE_VOL(unsigned char mode_vol)
80 {
81     vol = mode_vol & 0x0f;
82     lp = (mode_vol & 0x10) != 0;
83     bp = (mode_vol & 0x20) != 0;
84     hp = (mode_vol & 0x40) != 0;
85     voice3off = (mode_vol & 0x80) != 0;
86 
87     updatedMixing();
88 }
89 
90 } // namespace reSIDfp
91