tube: another better oversampler (6x now)
This commit is contained in:
parent
c0ef645404
commit
85774c0341
1 changed files with 24 additions and 25 deletions
49
crap/tube.h
49
crap/tube.h
|
@ -11,7 +11,8 @@
|
||||||
#define COPYRIGHT "MIT"
|
#define COPYRIGHT "MIT"
|
||||||
#define PARAMETERS 2
|
#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)
|
#define HIST_SIZE (HIST_SIZE_2*2)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -55,35 +56,31 @@ distort(double x)
|
||||||
h[i*2 + 1] = h[i*2 + 0]; \
|
h[i*2 + 1] = h[i*2 + 0]; \
|
||||||
h[i*2 + 0] = x;
|
h[i*2 + 0] = x;
|
||||||
|
|
||||||
// b2 is always b0 with lowpasses
|
// b0 and b2 are equivalent and factored out
|
||||||
// a0 is already factored into the rest of the coefficients
|
// b0 and a0 are factored out as overall gain
|
||||||
#define LOWPASS(i, b0, b1, a1, a2) \
|
#define LOWPASS(i, b1, a1, a2) \
|
||||||
y = b0*x + b1*h[i*2 + 0] + b0*h[i*2 + 1] \
|
y = x + b1*h[i*2 + 0] + h[i*2 + 1] \
|
||||||
- a1*h[i*2 + 2] - a2*h[i*2 + 3]; \
|
- a1*h[i*2 + 2] - a2*h[i*2 + 3]; \
|
||||||
BQSHIFT(i); \
|
BQSHIFT(i); \
|
||||||
x = y;
|
x = y;
|
||||||
|
|
||||||
static double
|
static double
|
||||||
oversample(double h[HIST_SIZE_2], double x)
|
oversample(double h[HIST_SIZE_2], double x)
|
||||||
{
|
{
|
||||||
/* designed with <https://coewww.rutgers.edu/~orfanidi/hpeq/>
|
/* Fp = 20000.62
|
||||||
fs = 44100; OS = 4; Gs = -120; f2 = 18544/fs/OS; f2s = 22050/fs/OS;
|
os = 6; N = 8*2; Gp = 0.0135; Gs = 120;
|
||||||
N = hpeqord(-Inf,0,Gs,-6,2*pi*f2s,2*pi*f2,2) % 21.9986847697467
|
|
||||||
*/
|
*/
|
||||||
double y;
|
double y;
|
||||||
LOWPASS( 0,+0.68211844,-0.96291784,-1.54972173,+0.95104078);
|
LOWPASS(0,-1.7310964991540,-1.7686201550064,+0.9924894080401);
|
||||||
LOWPASS( 1,+0.64259794,-0.89367078,-1.46615406,+0.85767914);
|
LOWPASS(1,-1.7228987922703,-1.7591070571963,+0.9756664940293);
|
||||||
LOWPASS( 2,+0.59754712,-0.80432534,-1.37570293,+0.76647184);
|
LOWPASS(2,-1.7030928294094,-1.7508784553758,+0.9530819894740);
|
||||||
LOWPASS( 3,+0.54606830,-0.69425498,-1.27603271,+0.67391434);
|
LOWPASS(3,-1.6623628189757,-1.7420481292930,+0.9206849371458);
|
||||||
LOWPASS( 4,+0.48770451,-0.56343052,-1.16582052,+0.57779902);
|
LOWPASS(4,-1.5767803723821,-1.7314029454409,+0.8755898544307);
|
||||||
LOWPASS( 5,+0.42283783,-0.41357065,-1.04538942,+0.47749444);
|
LOWPASS(5,-1.3754954625889,-1.7189289035735,+0.8193999703446);
|
||||||
LOWPASS( 6,+0.35328311,-0.24971266,-0.91771844,+0.37457200);
|
LOWPASS(6,-0.7934216412437,-1.7066722500921,+0.7627918423024);
|
||||||
LOWPASS( 7,+0.28296589,-0.08195448,-0.78962026,+0.27359756);
|
LOWPASS(7,+1.1176227011686,-1.6987049565355,+0.7256338727337);
|
||||||
LOWPASS( 8,+0.21832227,+0.07351444,-0.67243388,+0.18259286);
|
BQSHIFT(8);
|
||||||
LOWPASS( 9,+0.16778186,+0.19566401,-0.58109077,+0.11231849);
|
return y*0.000005162322938;
|
||||||
LOWPASS(10,+0.13979560,+0.26348229,-0.53059324,+0.07366673);
|
|
||||||
BQSHIFT(11);
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static double
|
static double
|
||||||
|
@ -100,11 +97,13 @@ process_os(personal *data, double x, int right)
|
||||||
double y;
|
double y;
|
||||||
|
|
||||||
#define doit(SAMP) \
|
#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)))
|
smooth(&data->drive), smooth(&data->wet)))
|
||||||
doit(x);
|
doit(x);
|
||||||
doit(0);
|
doit(0);
|
||||||
doit(0);
|
doit(0);
|
||||||
|
doit(0);
|
||||||
|
doit(0);
|
||||||
y = doit(0);
|
y = doit(0);
|
||||||
#undef doit
|
#undef doit
|
||||||
|
|
||||||
|
@ -186,8 +185,8 @@ adjust(personal *data, param *params, unsigned long fs_long)
|
||||||
data->wet.desired = params[1].value;
|
data->wet.desired = params[1].value;
|
||||||
data->drive.actual = data->drive.desired;
|
data->drive.actual = data->drive.desired;
|
||||||
data->wet.actual = data->wet.desired;
|
data->wet.actual = data->wet.desired;
|
||||||
data->drive.speed = 1 + 20/fs/4;
|
data->drive.speed = 1 + 20/fs/OVERSAMPLING;
|
||||||
data->wet.speed = 20/fs/4;
|
data->wet.speed = 20/fs/OVERSAMPLING;
|
||||||
data->drive.log = 1;
|
data->drive.log = 1;
|
||||||
data->wet.log = 0;
|
data->wet.log = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue