X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=filter.cpp;h=0cb0180d8c4ce4f673112422708f68f5608f9b4d;hp=d737cb086565170a286bb27f9312e4a84a80c0de;hb=703e00da89118df9be0354dda621bed023e6030e;hpb=9b9f5c84113b8a818f296467fd2150ce6a095fbe diff --git a/filter.cpp b/filter.cpp index d737cb0..0cb0180 100644 --- a/filter.cpp +++ b/filter.cpp @@ -1,9 +1,11 @@ +#include #include #include #include -#include -#include #include +#include + +#include "defs.h" #ifdef __SSE__ #include @@ -36,6 +38,7 @@ Filter::Filter() { omega = M_PI; resonance = 0.01f; + A = 1.0f; init(FILTER_NONE, 1); update(); @@ -131,6 +134,33 @@ void Filter::update() // a2 = 1 - alpha; break; + case FILTER_PEAKING_EQ: + b0 = 1 + alpha * A; + b1 = -2*cs; + b2 = 1 - alpha * A; + a0 = 1 + alpha / A; + // a1 = -2*cs; + a2 = 1 - alpha / A; + break; + + case FILTER_LOW_SHELF: + b0 = A * ((A + 1) - (A - 1)*cs + 2 * sqrt(A) * alpha); + b1 = 2 * A * ((A - 1) - (A + 1)*cs ); + b2 = A * ((A + 1) - (A - 1)*cs - 2 * sqrt(A) * alpha); + a0 = (A + 1) + (A - 1)*cs + 2 * sqrt(A) * alpha ; + a1 = -2 * ((A - 1) + (A + 1)*cs ); + a2 = (A + 1) + (A - 1)*cs - 2 * sqrt(A) * alpha ; + break; + + case FILTER_HIGH_SHELF: + b0 = A * ((A + 1) + (A - 1)*cs + 2 * sqrt(A) * alpha); + b1 = -2 * A * ((A - 1) + (A + 1)*cs ); + b2 = A * ((A + 1) + (A - 1)*cs - 2 * sqrt(A) * alpha); + a0 = (A + 1) - (A - 1)*cs + 2 * sqrt(A) * alpha ; + a1 = 2 * ((A - 1) - (A + 1)*cs ); + a2 = (A + 1) - (A - 1)*cs - 2 * sqrt(A) * alpha ; + break; + default: //unknown filter type assert(false); @@ -261,12 +291,12 @@ void StereoFilter::init(FilterType type, int new_order) memset(feedback, 0, sizeof(feedback)); #else for (unsigned i = 0; i < 2; ++i) { - filters[i].init(type, 0, new_order, 0); + filters[i].init(type, new_order); } #endif } -void StereoFilter::render(float *inout_left_ptr, unsigned n_samples, float cutoff, float resonance) +void StereoFilter::render(float *inout_left_ptr, unsigned n_samples, float cutoff, float resonance, float dbgain_normalized) { #ifdef __SSE__ if (parm_filter.filtertype == FILTER_NONE || parm_filter.filter_order == 0) @@ -277,6 +307,7 @@ void StereoFilter::render(float *inout_left_ptr, unsigned n_samples, float cutof parm_filter.set_linear_cutoff(cutoff); parm_filter.set_resonance(resonance); + parm_filter.set_dbgain_normalized(dbgain_normalized); parm_filter.update(); __m128 b0 = _mm_set1_ps(parm_filter.b0);