From 46a4d07e5873c73cbbc97ff7156da256dd727088 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 18 Jun 2014 04:38:47 -0700 Subject: [PATCH] move tube oversampling to its own file --- crap/tube.h | 32 +------------------------------- include/os6iir.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 include/os6iir.h diff --git a/crap/tube.h b/crap/tube.h index ff4e20b..5515c9d 100644 --- a/crap/tube.h +++ b/crap/tube.h @@ -3,6 +3,7 @@ #include "util.h" #include "param.h" +#include "os6iir.h" #define ID 0x50F7BA11 #define LABEL "crap_tube" @@ -52,37 +53,6 @@ distort(double x) return (27*x + 9) / (9*x*x + 6*x + 19) - 9/19.; } -#define BQSHIFT(i) \ - h[i*2 + 1] = h[i*2 + 0]; \ - h[i*2 + 0] = x; - -// b0 and b2 are equivalent and factored out -// b0 and a0 are factored out as overall gain -#define LOWPASS(i, b1, a1, a2) \ - y = x + b1*h[i*2 + 0] + h[i*2 + 1] \ - - a1*h[i*2 + 2] - a2*h[i*2 + 3]; \ - BQSHIFT(i); \ - x = y; - -static double -oversample(double h[HIST_SIZE_2], double x) -{ - /* Fp = 20000.62 - os = 6; N = 8*2; Gp = 0.0135; Gs = 120; - */ - double y; - LOWPASS(0,-1.7310964991540,-1.7686201550064,+0.9924894080401); - LOWPASS(1,-1.7228987922703,-1.7591070571963,+0.9756664940293); - LOWPASS(2,-1.7030928294094,-1.7508784553758,+0.9530819894740); - LOWPASS(3,-1.6623628189757,-1.7420481292930,+0.9206849371458); - LOWPASS(4,-1.5767803723821,-1.7314029454409,+0.8755898544307); - LOWPASS(5,-1.3754954625889,-1.7189289035735,+0.8193999703446); - LOWPASS(6,-0.7934216412437,-1.7066722500921,+0.7627918423024); - LOWPASS(7,+1.1176227011686,-1.6987049565355,+0.7256338727337); - BQSHIFT(8); - return y*0.000005162322938; -} - static double process_one(double x, double drive, double wet) { diff --git a/include/os6iir.h b/include/os6iir.h new file mode 100644 index 0000000..7b8992a --- /dev/null +++ b/include/os6iir.h @@ -0,0 +1,37 @@ +/* IIR filter + Fp = 20000.62 + os = 6; N = 8*2; Gp = 0.0135; Gs = 120; + overall delay: ~5 samples +*/ + +#define BQSHIFT(i) \ + h[i*2 + 1] = h[i*2 + 0]; \ + h[i*2 + 0] = x; + +// b0 and b2 are equivalent and factored out +// b0 and a0 are factored out as overall gain +#define LOWPASS(i, b1, a1, a2) \ + y = x + b1*h[i*2 + 0] + h[i*2 + 1] \ + - a1*h[i*2 + 2] - a2*h[i*2 + 3]; \ + BQSHIFT(i); \ + x = y; + +static double +oversample(double *h, double x) +{ + // h[] should be at least 18 doubles long + double y; + LOWPASS(0,-1.7310964991540,-1.7686201550064,+0.9924894080401); + LOWPASS(1,-1.7228987922703,-1.7591070571963,+0.9756664940293); + LOWPASS(2,-1.7030928294094,-1.7508784553758,+0.9530819894740); + LOWPASS(3,-1.6623628189757,-1.7420481292930,+0.9206849371458); + LOWPASS(4,-1.5767803723821,-1.7314029454409,+0.8755898544307); + LOWPASS(5,-1.3754954625889,-1.7189289035735,+0.8193999703446); + LOWPASS(6,-0.7934216412437,-1.7066722500921,+0.7627918423024); + LOWPASS(7,+1.1176227011686,-1.6987049565355,+0.7256338727337); + BQSHIFT(8); + return y*0.000005162322938; +} + +#undef BQSHIFT +#undef LOWPASS