libsidplayfp  1.2.2
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  (filt1 ? Vi : Vo) += voice1;
100 
101  (filt2 ? Vi : Vo) += voice2;
102 
103  // NB! Voice 3 is not silenced by voice3off if it is routed
104  // through the filter.
105  if (filt3)
106  {
107  Vi += voice3;
108  }
109  else if (!voice3off)
110  {
111  Vo += voice3;
112  }
113 
114  (filtE ? Vi : Vo) += ve;
115 
116  const float dVbp = w0 * Vhp;
117  const float dVlp = w0 * Vbp;
118  Vbp -= dVbp;
119  Vlp -= dVlp;
120  Vhp = (Vbp * _1_div_Q) - Vlp - Vi + float(rand()) / float(RAND_MAX);
121 
122  float Vof = (float)Vo;
123 
124  if (lp)
125  {
126  Vof += Vlp;
127  }
128 
129  if (bp)
130  {
131  Vof += Vbp;
132  }
133 
134  if (hp)
135  {
136  Vof += Vhp;
137  }
138 
139  return (int) Vof * vol >> 4;
140 }
141 
142 } // namespace reSIDfp
143 
144 #endif
145 
146 #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