41 PassType filterPassType,
44 this->resonance = resonance;
45 this->frequency = frequency;
46 this->sampleRate = sampleRate;
47 this->filterPassType = filterPassType;
48 switch (filterPassType)
51 c = 1.0 / tan(
M_PI * frequency / sampleRate);
52 a1 = 1.0 / (1.0 + resonance *
c +
c *
c);
55 b1 = 2.0 * (1.0 -
c *
c) * a1;
56 b2 = (1.0 - resonance *
c +
c *
c) * a1;
59 c = tan(
M_PI * frequency / sampleRate);
60 a1 = 1.0 / (1.0 + resonance *
c +
c *
c);
63 b1 = 2.0 * (
c *
c - 1.0) * a1;
64 b2 = (1.0 - resonance *
c +
c *
c) * a1;
73 armarx::PassType filterPassType,
76 reset(frequency, sampleRate, filterPassType, resonance);
82 for (
auto& v : inputHistory)
86 for (
auto& v : outputHistory)
92 armarx::ParameterTypeList
95 ParameterTypeList result;
109 VariantPtr var = VariantPtr::dynamicCast(value);
110 if (!var->getInitialized())
115 double newInput = 0.0;
116 auto type = var->getType();
119 newInput =
static_cast<double>(var->getFloat());
123 newInput = var->getDouble();
127 newInput =
static_cast<double>(var->getInt());
131 newInput =
static_cast<double>(var->getLong());
141 double newOutput = a1 * newInput + a2 * this->inputHistory[0] + a3 * this->inputHistory[1] -
142 b1 * this->outputHistory[0] - b2 * this->outputHistory[1];
144 this->inputHistory[1] = this->inputHistory[0];
145 this->inputHistory[0] = newInput;
147 this->outputHistory[2] = this->outputHistory[1];
148 this->outputHistory[1] = this->outputHistory[0];
149 this->outputHistory[0] = newOutput;
157 return new Variant(outputHistory[0]);
164 return outputHistory[0];
172 return new Variant(outputHistory[0]);
175 StringFloatDictionary
178 StringFloatDictionary props;
179 props[
"resonance"] = resonance;
180 props[
"frequency"] = frequency;
181 props[
"sampleRate"] = sampleRate;
182 props[
"filterPassType"] = (int)(filterPassType);
190 auto it = newValues.find(
"resonance");
191 if (it != newValues.end())
193 resonance = it->second;
196 it = newValues.find(
"frequency");
197 if (it != newValues.end())
199 frequency = it->second;
202 it = newValues.find(
"sampleRate");
203 if (it != newValues.end())
205 sampleRate = it->second;
208 it = newValues.find(
"filterPassType");
209 if (it != newValues.end())
211 filterPassType =
static_cast<PassType
>(it->second);
213 reset(frequency, sampleRate, filterPassType, resonance);
The Variant class is described here: Variants.
ParameterTypeList getSupportedTypes(const Ice::Current &=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
void update(Ice::Long, const VariantBasePtr &value, const Ice::Current &=Ice::emptyCurrent) override
double getRawValue() const
VariantBasePtr getValue(const Ice::Current &=Ice::emptyCurrent) const override
void setProperties(const StringFloatDictionary &values, const Ice::Current &) override
void setInitialValue(double value)
VariantBasePtr calculate(const Ice::Current &=Ice::emptyCurrent) const override
StringFloatDictionary getProperties(const Ice::Current &) const override
void reset(double frequency, int sampleRate, PassType passType, double resonance)
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
const VariantTypeId Double
const VariantTypeId Float
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr