libsidplayfp  0.3.5
Filter8580.h
1 #ifndef FILTER8580_H
2 #define FILTER8580_H
3 
4 #include "siddefs-fp.h"
5 
6 #include "Filter.h"
7 
8 namespace reSIDfp
9 {
10 
24 class Filter8580 : public Filter {
25 
26 private:
27  double highFreq;
28  float Vlp, Vbp, Vhp;
29  float ve, w0, _1_div_Q;
30 
31 public:
32  Filter8580() :
33  highFreq(12500.),
34  Vlp(0.f),
35  Vbp(0.f),
36  Vhp(0.f),
37  ve(0.f),
38  w0(0.f),
39  _1_div_Q(0.f) {}
40 
41  int clock(const int voice1, const int voice2, const int voice3);
42 
44 
45  void updatedResonance();
46 
47  void input(const int input);
48 
49  void updatedMixing() {}
50 
51  void setFilterCurve(const double curvePosition);
52 };
53 
54 } // namespace reSIDfp
55 
56 #if RESID_INLINING || defined(FILTER8580_CPP)
57 
58 #include <stdlib.h>
59 #include <math.h>
60 
61 namespace reSIDfp
62 {
63 
64 RESID_INLINE
65 int Filter8580::clock(const int v1, const int v2, const int v3) {
66  const int voice1 = v1 >> 7;
67  const int voice2 = v2 >> 7;
68  const int voice3 = v3 >> 7;
69 
70  int Vi = 0;
71  float Vo = 0.f;
72  if (filt1) {
73  Vi += voice1;
74  } else {
75  Vo += voice1;
76  }
77  if (filt2) {
78  Vi += voice2;
79  } else {
80  Vo += voice2;
81  }
82  // NB! Voice 3 is not silenced by voice3off if it is routed
83  // through the filter.
84  if (filt3) {
85  Vi += voice3;
86  } else if (!voice3off) {
87  Vo += voice3;
88  }
89  if (filtE) {
90  Vi += (int)ve;
91  } else {
92  Vo += ve;
93  }
94 
95  const float dVbp = w0 * Vhp;
96  const float dVlp = w0 * Vbp;
97  Vbp -= dVbp;
98  Vlp -= dVlp;
99  Vhp = (Vbp*_1_div_Q) - Vlp - Vi + float(rand())/float(RAND_MAX);
100 
101  if (lp) {
102  Vo += Vlp;
103  }
104  if (bp) {
105  Vo += Vbp;
106  }
107  if (hp) {
108  Vo += Vhp;
109  }
110 
111  return (int) Vo * vol >> 4;
112 }
113 
114 } // namespace reSIDfp
115 
116 #endif
117 
118 #endif