Use a flexible array for the active effect slots
[openal-soft.git] / Alc / filters / splitter.cpp
blob9e13c188db352d032ea3048e79eda186ea2189cb
2 #include "config.h"
4 #include "splitter.h"
6 #include <cmath>
7 #include <limits>
8 #include <algorithm>
10 #include "math_defs.h"
12 template<typename Real>
13 void BandSplitterR<Real>::init(Real f0norm)
15 const Real w{f0norm * al::MathDefs<Real>::Tau()};
16 const Real cw{std::cos(w)};
17 if(cw > std::numeric_limits<float>::epsilon())
18 coeff = (std::sin(w) - 1.0f) / cw;
19 else
20 coeff = cw * -0.5f;
22 lp_z1 = 0.0f;
23 lp_z2 = 0.0f;
24 ap_z1 = 0.0f;
27 template<typename Real>
28 void BandSplitterR<Real>::process(Real *RESTRICT hpout, Real *RESTRICT lpout, const Real *input, int count)
30 ASSUME(count > 0);
32 const Real ap_coeff{this->coeff};
33 const Real lp_coeff{this->coeff*0.5f + 0.5f};
34 Real lp_z1{this->lp_z1};
35 Real lp_z2{this->lp_z2};
36 Real ap_z1{this->ap_z1};
37 auto proc_sample = [ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1,&lpout](const Real in) noexcept -> Real
39 /* Low-pass sample processing. */
40 Real d{(in - lp_z1) * lp_coeff};
41 Real lp_y{lp_z1 + d};
42 lp_z1 = lp_y + d;
44 d = (lp_y - lp_z2) * lp_coeff;
45 lp_y = lp_z2 + d;
46 lp_z2 = lp_y + d;
48 *(lpout++) = lp_y;
50 /* All-pass sample processing. */
51 Real ap_y{in*ap_coeff + ap_z1};
52 ap_z1 = in - ap_y*ap_coeff;
54 /* High-pass generated from removing low-passed output. */
55 return ap_y - lp_y;
57 std::transform(input, input+count, hpout, proc_sample);
58 this->lp_z1 = lp_z1;
59 this->lp_z2 = lp_z2;
60 this->ap_z1 = ap_z1;
63 template class BandSplitterR<float>;
64 template class BandSplitterR<double>;
67 template<typename Real>
68 void SplitterAllpassR<Real>::init(Real f0norm)
70 const Real w{f0norm * al::MathDefs<Real>::Tau()};
71 const Real cw{std::cos(w)};
72 if(cw > std::numeric_limits<float>::epsilon())
73 coeff = (std::sin(w) - 1.0f) / cw;
74 else
75 coeff = cw * -0.5f;
77 z1 = 0.0f;
80 template<typename Real>
81 void SplitterAllpassR<Real>::process(Real *RESTRICT samples, int count)
83 ASSUME(count > 0);
85 const Real coeff{this->coeff};
86 Real z1{this->z1};
87 auto proc_sample = [coeff,&z1](const Real in) noexcept -> Real
89 Real out{in*coeff + z1};
90 z1 = in - out*coeff;
91 return out;
93 std::transform(samples, samples+count, samples, proc_sample);
94 this->z1 = z1;
97 template class SplitterAllpassR<float>;
98 template class SplitterAllpassR<double>;