37 this->resonance = resonance;
38 this->frequency = frequency;
39 this->sampleRate = sampleRate;
40 this->filterPassType = filterPassType;
41 switch (filterPassType)
44 c = 1.0 / tan(
M_PI * frequency / sampleRate);
45 a1 = 1.0 / (1.0 + resonance *
c +
c *
c);
48 b1 = 2.0 * (1.0 -
c *
c) * a1;
49 b2 = (1.0 - resonance *
c +
c *
c) * a1;
52 c = tan(
M_PI * frequency / sampleRate);
53 a1 = 1.0 / (1.0 + resonance *
c +
c *
c);
56 b1 = 2.0 * (
c *
c - 1.0) * a1;
57 b2 = (1.0 - resonance *
c +
c *
c) * a1;
67 reset(frequency, sampleRate, filterPassType, resonance);
72 for (
auto&
v : inputHistory)
76 for (
auto&
v : outputHistory)
84 ParameterTypeList result;
96 if (!var->getInitialized())
101 double newInput = 0.0;
102 auto type = var->getType();
105 newInput =
static_cast<double>(var->getFloat());
109 newInput = var->getDouble();
113 newInput =
static_cast<double>(var->getInt());
117 newInput =
static_cast<double>(var->getLong());
124 std::unique_lock lock(historyMutex);
126 double newOutput = a1 * newInput + a2 * this->inputHistory[0] + a3 * this->inputHistory[1] - b1 * this->outputHistory[0] - b2 * this->outputHistory[1];
128 this->inputHistory[1] = this->inputHistory[0];
129 this->inputHistory[0] = newInput;
131 this->outputHistory[2] = this->outputHistory[1];
132 this->outputHistory[1] = this->outputHistory[0];
133 this->outputHistory[0] = newOutput;
138 std::unique_lock lock(historyMutex);
140 return new Variant(outputHistory[0]);
145 std::unique_lock lock(historyMutex);
146 return outputHistory[0];
151 std::unique_lock lock(historyMutex);
153 return new Variant(outputHistory[0]);
159 StringFloatDictionary props;
160 props[
"resonance"] = resonance;
161 props[
"frequency"] = frequency;
162 props[
"sampleRate"] = sampleRate;
163 props[
"filterPassType"] = (int)(filterPassType);
169 auto it = newValues.find(
"resonance");
170 if (it != newValues.end())
172 resonance = it->second;
175 it = newValues.find(
"frequency");
176 if (it != newValues.end())
178 frequency = it->second;
181 it = newValues.find(
"sampleRate");
182 if (it != newValues.end())
184 sampleRate = it->second;
187 it = newValues.find(
"filterPassType");
188 if (it != newValues.end())
190 filterPassType =
static_cast<PassType
>(it->second);
192 reset(frequency, sampleRate, filterPassType, resonance);