18 #include "Properties.h"
20 extern bool globWarningFlag;
21 extern bool globReportFlag;
26 mf_(sqrt(hf_) * sqrt(lf_)),
38 if (lf >= 10.0 && lf <= 10000.0)
41 mf_ = sqrt(hf_) * sqrt(lf_);
44 else if (globWarningFlag)
45 error(
"HiMidLow: Low shelf frequency must be between 10 and 10000 hz.");
47 else if (globWarningFlag)
48 error(
"HiMidLow: Low shelf frequency must be less than high shelf frequency %f.", hf_);
55 if (hf >= 10.0 && hf <= 10000.0)
58 mf_ = sqrt(hf_) * sqrt(lf_);
61 else if (globWarningFlag)
62 error(
"HiMidLow: High shelf frequency must be between 10 and 10000 hz.");
64 else if (globWarningFlag)
65 error(
"HiMidLow: High shelf frequency must be greater than low shelf frequency %f.", lf_);
77 else if (newLg <
MIN_)
89 if (capped && globWarningFlag)
90 post(
"Filter: Low gain capped at %f", lg_);
102 else if (newMg <
MIN_)
114 if (capped && globWarningFlag)
115 post(
"HiMidLow: Mid gain capped at %f", mg_);
127 else if (newHg <
MIN_)
139 if (capped && globWarningFlag)
140 post(
"HiMidLow: High gain capped at %f", hg_);
143 void HiMidLow::init()
145 double f = mf_ *
sr_;
146 double rf = sqrt(hf_) / sqrt(lf_);
147 double l = cos(f) / sin(f);
148 double invHg = 1.0 / hg_;
149 double invLg = 1.0 / lg_;
150 double invMg = 1.0 / mg_;
154 double k4 = k3 * hg_;
155 double k5 = k3 * invHg;
156 double k6 = invLg + k5;
157 double k7 = invMg * k1 + k2 * invLg * invHg * mg_;
158 double k8 = lg_ + k4;
159 double k9 = (mg_ * k1) + (k2 * lg_ * hg_ * invMg);
160 double k10 = 1.0 / (k6 + k7);
162 double tempb2 = k10 * (k7 - k6);
163 double tempb1 = k10 * 2.0 * (k5 - invLg);
164 double tempa2 = k10 * (k8 - k9);
165 double tempa1 = k10 * 2.0 * (lg_ - k4);
166 double tempa0 = k10 * (k8 + k9);
172 double discriminant = tempb1 * tempb1 + 4.0 * tempb2;
173 if (tempb1 <= -1.9999996)
175 else if (tempb1 >= 1.9999996)
178 if (tempb2 <= -0.9999998)
180 else if (tempb2 >= 0.9999998)
183 if (discriminant >= 0.0)
185 if (0.9999998 - tempb1 - tempb2 < 0.0)
186 tempb2 = 0.9999998 - tempb1;
187 if (0.9999998 + tempb1 - tempb2 < 0.0)
188 tempb2 = 0.9999998 + tempb1;
200 post(
"b1: %f, b2: %f, a0: %f, a1: %f, a2: %f, lg: %f, mg: %f, hg: %f",
b1_,
b2_,
a0_,
a1_,
a2_, lg_, mg_, hg_);
virtual void print() const
Prints information about this filter.
void midGain(double newMg)
Sets mid gain.
static const double MAX_
Max gain value.
double a2_
Filter coefficient.
double sr_
Pi divided by the sample rate.
HiMidLow()
Class constructor.
void highGain(double newHg)
Set high gain.
void highShelfFrequency(double hf)
Set high shelf's center frequency.
double percentToGain(double gainPercentage)
Convert percentage to linear gain.
static const double MIN_
Min gain value.
void lowGain(double newLg)
Sets low gain.
void lowShelfFrequency(double lf)
Set low shelf's center frequency.
double b1_
Filter coefficient.
double b2_
Filter coefficient.
double a1_
Filter coefficient.
double a0_
Filter coefficient.