tube: another better oversampler (6x now)

This commit is contained in:
Connor Olding 2014-02-24 13:22:42 -08:00
parent c0ef645404
commit 85774c0341

View File

@ -11,7 +11,8 @@
#define COPYRIGHT "MIT"
#define PARAMETERS 2
#define HIST_SIZE_2 (2 + 2*11)
#define OVERSAMPLING 6
#define HIST_SIZE_2 (2 + 2*8)
#define HIST_SIZE (HIST_SIZE_2*2)
typedef struct {
@ -55,35 +56,31 @@ distort(double x)
h[i*2 + 1] = h[i*2 + 0]; \
h[i*2 + 0] = x;
// b2 is always b0 with lowpasses
// a0 is already factored into the rest of the coefficients
#define LOWPASS(i, b0, b1, a1, a2) \
y = b0*x + b1*h[i*2 + 0] + b0*h[i*2 + 1] \
- a1*h[i*2 + 2] - a2*h[i*2 + 3]; \
// 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)
{
/* designed with <https://coewww.rutgers.edu/~orfanidi/hpeq/>
fs = 44100; OS = 4; Gs = -120; f2 = 18544/fs/OS; f2s = 22050/fs/OS;
N = hpeqord(-Inf,0,Gs,-6,2*pi*f2s,2*pi*f2,2) % 21.9986847697467
/* Fp = 20000.62
os = 6; N = 8*2; Gp = 0.0135; Gs = 120;
*/
double y;
LOWPASS( 0,+0.68211844,-0.96291784,-1.54972173,+0.95104078);
LOWPASS( 1,+0.64259794,-0.89367078,-1.46615406,+0.85767914);
LOWPASS( 2,+0.59754712,-0.80432534,-1.37570293,+0.76647184);
LOWPASS( 3,+0.54606830,-0.69425498,-1.27603271,+0.67391434);
LOWPASS( 4,+0.48770451,-0.56343052,-1.16582052,+0.57779902);
LOWPASS( 5,+0.42283783,-0.41357065,-1.04538942,+0.47749444);
LOWPASS( 6,+0.35328311,-0.24971266,-0.91771844,+0.37457200);
LOWPASS( 7,+0.28296589,-0.08195448,-0.78962026,+0.27359756);
LOWPASS( 8,+0.21832227,+0.07351444,-0.67243388,+0.18259286);
LOWPASS( 9,+0.16778186,+0.19566401,-0.58109077,+0.11231849);
LOWPASS(10,+0.13979560,+0.26348229,-0.53059324,+0.07366673);
BQSHIFT(11);
return 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
@ -100,11 +97,13 @@ process_os(personal *data, double x, int right)
double y;
#define doit(SAMP) \
oversample(h1, process_one(4*oversample(h0, SAMP), \
oversample(h1, process_one(OVERSAMPLING*oversample(h0, SAMP), \
smooth(&data->drive), smooth(&data->wet)))
doit(x);
doit(0);
doit(0);
doit(0);
doit(0);
y = doit(0);
#undef doit
@ -186,8 +185,8 @@ adjust(personal *data, param *params, unsigned long fs_long)
data->wet.desired = params[1].value;
data->drive.actual = data->drive.desired;
data->wet.actual = data->wet.desired;
data->drive.speed = 1 + 20/fs/4;
data->wet.speed = 20/fs/4;
data->drive.speed = 1 + 20/fs/OVERSAMPLING;
data->wet.speed = 20/fs/OVERSAMPLING;
data->drive.log = 1;
data->wet.log = 0;
}