Skip to content

Commit

Permalink
finalboss: fine tune some features and add gain slider
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Dec 22, 2023
1 parent 4741a0c commit 99a9019
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,44 +185,60 @@ function pitchlibUpdateFall(N)
// Binary search was slower than straightforward loop.
function pitchlibDetermineMaxACF(B1, B2, buffer_size)
local(idx, cmax, cmax_position, current, correction,
yc, yl, yr)
yc, yl, yr, acf_size, two_side)
global(poox)
instance()
(
fft_real(B1, buffer_size);
fft_real(B2, buffer_size);
two_side = 1;
acf_size = buffer_size;
two_side ? (acf_size *= 2;);

fft_real(B1, acf_size);
fft_real(B2, acf_size);

idx = 0;
loop(4,
B1[idx] = 0;
B2[idx] = 0;
idx += 1;
);
/*
loop(buffer_size - 2,
B1[idx] /= (1 + idx);
B2[idx] /= (1 + idx);
idx += 1;
);
*/

idx = 1;
loop(buffer_size*.5,
idx = 3;
loop(acf_size*.5,
B2[idx] = -B2[idx];
idx += 2;
);

convolve_c(B1, B2, buffer_size);
ifft_real(B1, buffer_size);

convolve_c(B1, B2, acf_size);
ifft_real(B1, acf_size);

/*
two_side ? (
idx = 0;
loop(buffer_size,
B1[idx] = B1[idx];
idx += 1;
);
);
*/

// Find the maximum of the ACF
cmax = -10000000;
idx = 0;
loop(.75*buffer_size-8,
current = B1[idx] + B1[idx+1];
idx = 1;
loop(buffer_size,
current = B1[idx] + 0.9 * (B1[idx - 1] + B1[idx + 1]);// + B1[idx+1];
current > cmax ? (
cmax_position = idx;
cmax = current;
);
idx += 2;
idx += 1;
);

poox = cmax_position;
Expand All @@ -232,9 +248,15 @@ instance()
yl = B1[cmax_position-2] + B1[cmax_position-1];
yr = B1[cmax_position+2] + B1[cmax_position+3];
correction = (-2*cmax_position*yc + cmax_position*yl + cmax_position*yr + yl - yr)/(-2*yc + yl + yr) - cmax_position;

abs(correction) < 4 ? cmax_position += correction;
cmax_position = max(cmax_position, 0);

two_side ? (
memset(B1, 0, acf_size);
memset(B2, 0, acf_size);
);

cmax_position
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ global(
active ? (
gfx_set(1, 0.2, 0.1, 0.1 + smooth_highlight);
) : (
gfx_set(0.1, 0.1, 0.1, 0.1);
gfx_set(0.1, 0.1, 0.1, 0.3);
);
gfx_rect(x, y, w, h);
unfilled_rect(x, y, w, h);
Expand Down
158 changes: 142 additions & 16 deletions FinalBoss/saike_allpass_dependencies/saike_allpass_toy_cabs.jsfx-inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@init
function svf1(cutoff, res, g1, g2, g3)
instance(a11, a12, a13, g11, g12, g13)
instance(a11, a12, a13, g11, g12, g13, k1)
global(srate)
local(g, k)
local(g)
(
g = tan(.5 * $pi * cutoff / srate);
k = 2.0 - 2.0 * res;
k1 = 2.0 - 2.0 * res;

a11 = 1.0 / (1.0 + g * (g + k));
a11 = 1.0 / (1.0 + g * (g + k1));
a12 = g * a11;
a13 = g * a12;

Expand All @@ -17,14 +17,14 @@ local(g, k)
);

function svf2(cutoff, res, g1, g2, g3)
instance(a21, a22, a23, g21, g22, g23)
instance(a21, a22, a23, g21, g22, g23, k2)
global(srate)
local(g, k)
local(g)
(
g = tan(.5 * $pi * cutoff / srate);
k = 2.0 - 2.0 * res;
k2 = 2.0 - 2.0 * res;

a21 = 1.0 / (1.0 + g * (g + k));
a21 = 1.0 / (1.0 + g * (g + k2));
a22 = g * a21;
a23 = g * a22;

Expand All @@ -34,14 +34,14 @@ local(g, k)
);

function svf3(cutoff, res, g1, g2, g3)
instance(a31, a32, a33, g31, g32, g33)
instance(a31, a32, a33, g31, g32, g33, k3)
global(srate)
local(g, k)
local(g)
(
g = tan(.5 * $pi * cutoff / srate);
k = 2.0 - 2.0 * res;
k3 = 2.0 - 2.0 * res;

a31 = 1.0 / (1.0 + g * (g + k));
a31 = 1.0 / (1.0 + g * (g + k3));
a32 = g * a31;
a33 = g * a32;

Expand All @@ -51,14 +51,14 @@ local(g, k)
);

function svf4(cutoff, res, g1, g2, g3)
instance(a41, a42, a43, g41, g42, g43)
instance(a41, a42, a43, g41, g42, g43, k4)
global(srate)
local(g, k)
local(g)
(
g = tan(.5 * $pi * cutoff / srate);
k = 2.0 - 2.0 * res;
k4 = 2.0 - 2.0 * res;

a41 = 1.0 / (1.0 + g * (g + k));
a41 = 1.0 / (1.0 + g * (g + k4));
a42 = g * a41;
a43 = g * a42;

Expand Down Expand Up @@ -94,6 +94,35 @@ global()
g21 * x + g22 * v1 + g23 * v2
);


function eval2_ap(x)
instance(a11, a12, a13,
a21, a22, a23,
g11, g12, g13,
g21, g22, g23,
ic11eq, ic12eq
ic21eq, ic22eq,
k1, k2)
local(v1, v2, v3)
global()
(
v3 = x - ic12eq;
v1 = a11 * ic11eq + a12 * v3;
v2 = ic12eq + a12 * ic11eq + a13 * v3;
ic11eq = 2.0 * v1 - ic11eq;
ic12eq = 2.0 * v2 - ic12eq;

x = x - 2 * k1 * v1;

v3 = x - ic22eq;
v1 = a21 * ic21eq + a22 * v3;
v2 = ic22eq + a22 * ic21eq + a23 * v3;
ic21eq = 2.0 * v1 - ic21eq;
ic22eq = 2.0 * v2 - ic22eq;

x - 2 * k2 * v1
);

function eval3(x)
instance(a11, a12, a13,
a21, a22, a23,
Expand Down Expand Up @@ -129,6 +158,42 @@ global()
g31 * x + g32 * v1 + g33 * v2
);

function eval3_ap(x)
instance(a11, a12, a13,
a21, a22, a23,
a31, a32, a33,
g11, g12, g13,
g21, g22, g23,
g31, g32, g33,
ic11eq, ic12eq
ic21eq, ic22eq
ic31eq, ic32eq
k1, k2, k3)
local(v1, v2, v3)
global()
(
v3 = x - ic12eq;
v1 = a11 * ic11eq + a12 * v3;
v2 = ic12eq + a12 * ic11eq + a13 * v3;
ic11eq = 2.0 * v1 - ic11eq;
ic12eq = 2.0 * v2 - ic12eq;
x = x - 2 * k1 * v1;

v3 = x - ic22eq;
v1 = a21 * ic21eq + a22 * v3;
v2 = ic22eq + a22 * ic21eq + a23 * v3;
ic21eq = 2.0 * v1 - ic21eq;
ic22eq = 2.0 * v2 - ic22eq;
x = x - 2 * k2 * v1;

v3 = x - ic32eq;
v1 = a31 * ic31eq + a32 * v3;
v2 = ic32eq + a32 * ic31eq + a33 * v3;
ic31eq = 2.0 * v1 - ic31eq;
ic32eq = 2.0 * v2 - ic32eq;
x - 2 * k3 * v1
);

function eval4(x)
instance(a11, a12, a13,
a21, a22, a23,
Expand Down Expand Up @@ -174,6 +239,52 @@ global()
g41 * x + g42 * v1 + g43 * v2
);

function eval4_ap(x)
instance(a11, a12, a13,
a21, a22, a23,
a31, a32, a33,
a41, a42, a43,
g11, g12, g13,
g21, g22, g23,
g31, g32, g33,
g41, g42, g43,
ic11eq, ic12eq
ic21eq, ic22eq
ic31eq, ic32eq
ic41eq, ic42eq,
k1, k2, k3, k4)
local(v1, v2, v3)
global()
(
v3 = x - ic12eq;
v1 = a11 * ic11eq + a12 * v3;
v2 = ic12eq + a12 * ic11eq + a13 * v3;
ic11eq = 2.0 * v1 - ic11eq;
ic12eq = 2.0 * v2 - ic12eq;
x = x - 2 * k1 * v1;

v3 = x - ic22eq;
v1 = a21 * ic21eq + a22 * v3;
v2 = ic22eq + a22 * ic21eq + a23 * v3;
ic21eq = 2.0 * v1 - ic21eq;
ic22eq = 2.0 * v2 - ic22eq;
x = x - 2 * k2 * v1;

v3 = x - ic32eq;
v1 = a31 * ic31eq + a32 * v3;
v2 = ic32eq + a32 * ic31eq + a33 * v3;
ic31eq = 2.0 * v1 - ic31eq;
ic32eq = 2.0 * v2 - ic32eq;
x = x - 2 * k3 * v1;

v3 = x - ic42eq;
v1 = a41 * ic41eq + a42 * v3;
v2 = ic42eq + a42 * ic41eq + a43 * v3;
ic41eq = 2.0 * v1 - ic41eq;
ic42eq = 2.0 * v2 - ic42eq;
x - 2 * k4 * v1;
);

function clear_mem(chl, chr)
instance(ic11eq, ic12eq
ic21eq, ic22eq
Expand Down Expand Up @@ -385,4 +496,19 @@ instance(N, outL, outR)
outR=2*this.R.eval4(r);
);
);
function update_cabs_matcher(model, l, r)
local()
global()
instance(N, outL, outR)
(
this.select_model(model, l, r);

N == 3 ? (
outL=2*this.L.eval3_ap(l);
outR=2*this.R.eval3_ap(r);
) : ( N == 4 ) ? (
outL=2*this.L.eval4_ap(l);
outR=2*this.R.eval4_ap(r);
);
);

44 changes: 38 additions & 6 deletions FinalBoss/saike_allpass_dependencies/saike_allpass_toy_fx.jsfx-inc
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ instance(
ia0, b0, b1, b2, b3, b4, a0, a1, a2, a3, a4,
ic, icOut, Iin, iR9, TdivC7, C7divT
dx1, dx2, dx3, dx4, dy1, dy2, dy3, dy4, sgn,
ptr, ptr2
ptr, ptr2,
xk, yk, xkm1, ykm1, xkm2, ykm2, c0, c1, c2,
)
global(kot_LUT_x, kot_LUT_y)
local(y, Vc, vout, x1, x2, y1, y2)
Expand Down Expand Up @@ -873,8 +874,17 @@ local(y, Vc, vout, x1, x2, y1, y2)

vout = ((y2-y1) / (x2-x1)) * (icOut - x1) + y1;
);

xk = vout*sgn*.2;
yk = c0 * (xk - xkm1 - xkm1 + xkm2) + c1 * yk + c2 * ykm2;

ykm2 = ykm1;
ykm1 = yk;

vout*sgn*.2
xkm2 = xkm1;
xkm1 = xk;

yk
);

function kot_reset()
Expand Down Expand Up @@ -1044,10 +1054,23 @@ instance()
2/(1+exp(-2*x)) - 1
);

function init_dc_block(freq)
local(omega, sqh)
global(srate)
instance(c0, c1, c2)
(
omega = 2.0 * $pi * freq / srate;
sqh = sqrt(0.5);
c0 = 1.0 - sqh * omega;
c1 = 2.0 - sqrt(2) * omega - 0.5 * omega * omega;
c2 = (1.0 - sqh * omega);
c2 *= -c2;
);

function heavyDistortion(x)
local(dt, dl)
local(dt, dl, legacy)
global(srate, oversampling)
instance(lastin, lastx, intx)
instance(lastin, lastx, intx, xk, yk, xkm1, ykm1, xkm2, ykm2, c0, c1, c2)
(
/* Power */
dt = 44100 / oversampling / srate;
Expand All @@ -1061,8 +1084,17 @@ instance(lastin, lastx, intx)
// Determine the slow and the fast response
lastx = lastx + .1*(dl-lastx)/overSampling;
intx = intx + .01625*dt*(.25*x-intx)*(1+5.5*abs(intx));

x - 2*lastx+intx

xk = 2*lastx+intx;
yk = c0 * (xk - xkm1 - xkm1 + xkm2) + c1 * yk + c2 * ykm2;

ykm2 = ykm1;
ykm1 = yk;

xkm2 = xkm1;
xkm1 = xk;

yk
);

higain_factor = 1.0 / (2.5*tanh(.5)*1.007);
Expand Down
Loading

0 comments on commit 99a9019

Please sign in to comment.