libsidplayfp  1.1.0
Filter8580.h
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 #ifndef FILTER8580_H
24 #define FILTER8580_H
25 
26 #include <cmath>
27 
28 #include "siddefs-fp.h"
29 
30 #include "Filter.h"
31 
32 namespace reSIDfp
33 {
34 
48 class Filter8580 : public Filter
49 {
50 private:
51  double highFreq;
52  float Vlp, Vbp, Vhp;
53  float w0, _1_div_Q;
54  int ve;
55 
56 public:
57  Filter8580() :
58  highFreq(12500.),
59  Vlp(0.f),
60  Vbp(0.f),
61  Vhp(0.f),
62  w0(0.f),
63  _1_div_Q(0.f),
64  ve(0) {}
65 
66  int clock(int voice1, int voice2, int voice3);
67 
68  void updatedCenterFrequency() { w0 = (float)(2.*M_PI * highFreq * fc / 2047 / 1e6); }
69 
70  void updatedResonance() { _1_div_Q = 1.f / (0.707f + res / 15.f); }
71 
72  void input(int input) { ve = input << 4; }
73 
74  void updatedMixing() {}
75 
76  void setFilterCurve(double curvePosition) { highFreq = curvePosition; }
77 };
78 
79 } // namespace reSIDfp
80 
81 #if RESID_INLINING || defined(FILTER8580_CPP)
82 
83 #include <stdlib.h>
84 #include <math.h>
85 
86 namespace reSIDfp
87 {
88 
89 RESID_INLINE
90 int Filter8580::clock(int voice1, int voice2, int voice3)
91 {
92  voice1 >>= 7;
93  voice2 >>= 7;
94  voice3 >>= 7;
95 
96  int Vi = 0;
97  int Vo = 0;
98 
99  if (filt1)
100  {
101  Vi += voice1;
102  }
103  else
104  {
105  Vo += voice1;
106  }
107 
108  if (filt2)
109  {
110  Vi += voice2;
111  }
112  else
113  {
114  Vo += voice2;
115  }
116 
117  // NB! Voice 3 is not silenced by voice3off if it is routed
118  // through the filter.
119  if (filt3)
120  {
121  Vi += voice3;
122  }
123  else if (!voice3off)
124  {
125  Vo += voice3;
126  }
127 
128  if (filtE)
129  {
130  Vi += ve;
131  }
132  else
133  {
134  Vo += ve;
135  }
136 
137  const float dVbp = w0 * Vhp;
138  const float dVlp = w0 * Vbp;
139  Vbp -= dVbp;
140  Vlp -= dVlp;
141  Vhp = (Vbp * _1_div_Q) - Vlp - Vi + float(rand()) / float(RAND_MAX);
142 
143  float Vof = (float)Vo;
144 
145  if (lp)
146  {
147  Vof += Vlp;
148  }
149 
150  if (bp)
151  {
152  Vof += Vbp;
153  }
154 
155  if (hp)
156  {
157  Vof += Vhp;
158  }
159 
160  return (int) Vof * vol >> 4;
161 }
162 
163 } // namespace reSIDfp
164 
165 #endif
166 
167 #endif
Definition: Filter8580.h:48
bool hp
Definition: Filter.h:85
bool filt1
Definition: Filter.h:75
bool voice3off
Definition: Filter.h:80
int vol
Definition: Filter.h:70
void updatedResonance()
Definition: Filter8580.h:70
void updatedCenterFrequency()
Definition: Filter8580.h:68
int res
Definition: Filter.h:65
int clock(int voice1, int voice2, int voice3)
Definition: Filter8580.h:90
void updatedMixing()
Definition: Filter8580.h:74
Definition: Filter.h:37
int fc
Definition: Filter.h:60