MCPcopy Create free account
hub / github.com/LabSound/LabSound / setHighpassParams

Method setHighpassParams

src/internal/src/Biquad.cpp:118–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void Biquad::setHighpassParams(double cutoff, double resonance)
119{
120 // Limit cutoff to 0 to 1.
121 cutoff = std::max(0.0, std::min(cutoff, 1.0));
122
123 if (cutoff == 1)
124 {
125 // The z-transform is 0.
126 setNormalizedCoefficients(0, 0, 0,
127 1, 0, 0);
128 }
129 else if (cutoff > 0)
130 {
131 // Compute biquad coefficients for highpass filter
132 resonance = std::max(0.0, resonance); // can't go negative
133 double g = pow(10.0, 0.05 * resonance);
134 double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
135
136 double theta = static_cast<double>(LAB_PI) * cutoff;
137 double sn = 0.5 * d * sin(theta);
138 double beta = 0.5 * (1 - sn) / (1 + sn);
139 double gamma = (0.5 + beta) * cos(theta);
140 double alpha = 0.25 * (0.5 + beta + gamma);
141
142 double b0 = 2 * alpha;
143 double b1 = 2 * -2 * alpha;
144 double b2 = 2 * alpha;
145 double a1 = 2 * -gamma;
146 double a2 = 2 * beta;
147
148 setNormalizedCoefficients(b0, b1, b2, 1, a1, a2);
149 }
150 else
151 {
152 // When cutoff is zero, we need to be careful because the above
153 // gives a quadratic divided by the same quadratic, with poles
154 // and zeros on the unit circle in the same place. When cutoff
155 // is zero, the z-transform is 1.
156 setNormalizedCoefficients(1, 0, 0,
157 1, 0, 0);
158 }
159}
160
161void Biquad::setNormalizedCoefficients(double b0, double b1, double b2, double a0, double a1, double a2)
162{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected