diff --git a/Makefile b/Makefile index 386eca7..b6af27d 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LADSPA = $(BOTH) VST = $(BOTH) delay_test UTILS = design bench -INCLUDES = util util_def param os6iir os2piir +INCLUDES = util biquad param os6iir os2piir BENCH_AGAINST = eq_const diff --git a/include/util_def.h b/include/biquad.h similarity index 87% rename from include/util_def.h rename to include/biquad.h index b0e4047..421d7a9 100644 --- a/include/util_def.h +++ b/include/biquad.h @@ -1,32 +1,26 @@ -#include -#include -#include - -INNER void -disable_denormals() -{ - #if __SSE2__ - _mm_setcsr(_mm_getcsr() | 0x8040); - #endif -} - -/* via http://www.rgba.org/articles/sfrand/sfrand.htm */ -static unsigned int mirand = 1; - -INNER float -whitenoise() -{ - union either { - float f; - unsigned int i; - } white; - mirand *= 16807; - white.i = (mirand & 0x007FFFFF) | 0x40000000; - return white.f - 3; -} - /* used to resemble https://github.com/swh/ladspa/blob/master/util/biquad.h */ +typedef enum { + FILT_PEAKING, + FILT_LOWSHELF, + FILT_HIGHSHELF, + FILT_LOWPASS, + FILT_HIGHPASS, + FILT_ALLPASS, + FILT_BANDPASS, + FILT_BANDPASS_2, + FILT_NOTCH, + FILT_GAIN +} filter_t; + +typedef struct { + double a1, a2, b0, b1, b2, x1, x2, y1, y2; +} biquad; + +typedef struct { + double b0, b1, b2, a0, a1, a2; +} biquad_interim; + INNER void biquad_init(biquad *bq) { diff --git a/include/util.h b/include/util.h index 3422c33..0500f0a 100644 --- a/include/util.h +++ b/include/util.h @@ -1,4 +1,6 @@ -#include "math.h" +#include +#include +#include #ifdef __SSE2__ #include @@ -20,7 +22,15 @@ typedef unsigned long ulong; // __attribute((aligned(16))); #define V(x) (v2df){(x), (x)} INNER void -disable_denormals(); +disable_denormals() +{ + #if __SSE2__ + _mm_setcsr(_mm_getcsr() | 0x8040); + #endif +} + +/* via http://www.rgba.org/articles/sfrand/sfrand.htm */ +static unsigned int mirand = 1; #define LIMIT(v,l,u) ((v)<(l)?(l):((v)>(u)?(u):(v))) #define DB2LIN(x) ((x) > -90 ? pow(10, (x) * 0.05) : 0) @@ -29,43 +39,16 @@ disable_denormals(); #define ANGULAR(fc, fs) (2 * M_PI / (fs) * (fc)) #define ANGULAR_LIM(fc, fs) (2 * M_PI / (fs) * LIMIT((fc), 1, (fs)/2)) -typedef struct { - double a1, a2, b0, b1, b2, x1, x2, y1, y2; -} biquad; - -typedef struct { - double b0, b1, b2, a0, a1, a2; -} biquad_interim; - INNER float -whitenoise(); +whitenoise() +{ + union either { + float f; + unsigned int i; + } white; + mirand *= 16807; + white.i = (mirand & 0x007FFFFF) | 0x40000000; + return white.f - 3; +} -INNER void -biquad_init(biquad *bq); - -typedef enum { - FILT_PEAKING, - FILT_LOWSHELF, - FILT_HIGHSHELF, - FILT_LOWPASS, - FILT_HIGHPASS, - FILT_ALLPASS, - FILT_BANDPASS, - FILT_BANDPASS_2, - FILT_NOTCH, - FILT_GAIN -} filter_t; - -INNER biquad -biquad_gen(filter_t type, double fc, double gain, double bw, double fs); - -/* s-plane to z-plane */ -static biquad_interim -design(double cw, double sw, - double num0, double num1, double num2, - double den0, double den1, double den2); - -INNER double -biquad_run(biquad *bq, double x); - -#include "util_def.h" +#include "biquad.h"