37 using namespace Nsound;
54 frequency_(frequency),
55 percent_ripple_(percent_ripple),
97 n_poles_(copy.n_poles_),
98 frequency_(copy.frequency_),
99 percent_ripple_(copy.percent_ripple_),
120 FilterStageIIR::KernelCache::iterator itor =
kernel_cache_.begin();
121 FilterStageIIR::KernelCache::iterator end =
kernel_cache_.end();
197 if(
this == &rhs)
return *
this;
222 Kernel new_kernel(static_cast<uint32>(itor->frequency_));
302 for(
float64 * a =
a_ + 1; a !=
a_ + n_poles_ + 1; ++a)
345 Kernel new_kernel(static_cast<uint32>(frequency));
350 KernelCache::const_iterator itor =
kernel_cache_.find(new_kernel);
410 memset(B,0,
sizeof(
float64) * 23);
411 memset(A,0,
sizeof(
float64) * 23);
412 memset(TB,0,
sizeof(
float64) * 23);
413 memset(TA,0,
sizeof(
float64) * 23);
424 memcpy(TB,B,
sizeof(
float64) * 23);
425 memcpy(TA,A,
sizeof(
float64) * 23);
427 for(
uint32 i = 2; i <= 22; ++i)
429 B[i] = b[0] * TB[i] + b[1] * TB[i - 1] + b[2] * TB[i - 2];
430 A[i] = TA[i] - a[1] * TA[i - 1] - a[2] * TA[i - 2];
435 for(
uint32 i = 0; i <= 20; ++i)
438 A[i] = -1.0 * A[i + 2];
444 for(
int32 i = 0; i <= 22; ++i)
453 sumB += B[i] * pow(-1.0,i);
454 sumA += A[i] * pow(-1.0,i);
457 float64 gain = sumB / (1.0 - sumA);
459 for(
uint32 i = 0; i <= 22; ++i)
482 float64 RP = -1.0 * cos(
M_PI / (n_poles * 2.0) + (p - 1) * (
M_PI / n_poles));
493 ES = sqrt(temp * temp - 1.0);
495 VX = (1.0 / n_poles) * log((1.0 / ES) + sqrt((1.0 /(ES * ES)) + 1.0));
496 KX = (1.0 / n_poles) * log((1.0 / ES) + sqrt((1.0 /(ES * ES)) - 1.0));
497 KX = (exp(KX) + exp(-KX)) / 2.0;
498 RP = RP * ( (exp(VX) - exp(-1.0 * VX) ) / 2.0) / KX;
499 IP = IP * ( (exp(VX) + exp(-1.0 * VX) ) / 2.0) / KX;
518 float64 D = 4.0 - (4.0 * RP * T) + (M * T * T);
522 float64 Y1 = (8.0 - 2.0 * M * T * T) / D;
523 float64 Y2 = (-4.0 - (4.0 * RP * T) - M * T * T) / D;
546 K = sin(0.5 - W / 2.0) / sin(0.5 + W / 2.0);
552 K = -1.0 * cos(W / 2.0 + 0.5) / cos(W / 2.0 - 0.5);
555 D = 1.0 + Y1 * K - Y2 * K * K;
556 b[0] = (X0 - X1 * K + X2 * K * K) / D;
557 b[1] = (-2.0 * X0 *K + X1 + X1 * K * K - 2.0 * X2 * K) / D;
558 b[2] = (X0 * K * K - X1 * K + X2) / D;
559 a[1] = (2.0 * K + Y1 + Y1 * K * K - 2.0 * Y2 * K) / D;
560 a[2] = (-1.0 * K * K - Y1 * K + Y2) / D;
601 frequency_(frequency)
AudioStream filter(const AudioStream &x)
Kernel(const uint32 &frequency)
A class for filtering audio in the frequecy domain.
bool operator<(const Kernel &rhs) const
A class to store calculated kernels.
KernelCache kernel_cache_
uint32 getLength() const
Returns the number of samples in the Buffer.
FilterStageIIR & operator=(const FilterStageIIR &rhs)
Base class for IIR Filters, defines the interface.
iterator end()
Retruns the itreator at the end of the Buffer.
FilterStageIIR(Type type, const float64 &sample_rate, uint32 n_poles, const float64 &frequency, const float64 &percent_ripple)
FloatVector::const_iterator const_iterator
iterator begin()
Retruns the itreator at the start of the Buffer.
AudioStream filter(const AudioStream &x)
A Buffer for storing audio samples.
virtual ~FilterStageIIR()
void makeIIRKernelHelper(const float64 &frequency, float64 *a, float64 *b, uint32 p)
void makeKernel(const float64 &frequency)