Skip to content

Commit

Permalink
added first prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
dariosanfilippo committed May 5, 2020
1 parent a5ea3b6 commit f34c59b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions prototype1.dsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import("stdfaust.lib");
// NAN-safe division
div(x1, x2) = ba.if(x2 == 0, 0, x1 / x2);
// Backwards Euler's integrator with cut-off frequency.
integrator(cf, x) = x * w(cf) : (+ : (min(1, max(0))))
~ _
with {
w(f) = 2 * ma.PI * f / ma.SR;
};
// Averaging function based on a 1-pole lowpass filter and the T19 time
// constant, that is, the system decays by 1/e^2.2 in "frame" seconds.
avg_t19(frame, x) = si.smooth(ba.tau2pole(frame / 2.2), x);
// N-th-order Butterworth crossover. N must be known at compile-time.
xover(N, cf, x) = fi.lowpass(N, cf1, x) ,
fi.highpass(N, cf1, x)
with {
cf1 = min(max(cf, 20), ma.SR / 2 - 20);
};
// Spectral centroid through N-th-order recursive adaptive filtering. Analysis
// frame in seconds.
sc(N, frame, x) = ( (_ ,
x) : xover(N) : ro.cross(2) : (rms(frame) - rms(frame)) :
div(_, rms(frame, x)) ^ 3 : integrator(1 / frame) ^ 2)
~ *(ma.SR / 2);
// Root mean square. Averaging frame in seconds.
rms(frame, x) = x * x : avg_t19(frame) : sqrt;
// Faust's notch filter for clarity
notch(bw, cf, x) = fi.notchw(bw, cf, x);
gain = hslider("Input gain[scale:exp]", 1, 0, 64, .001);
on = checkbox("Activate");
process(x) = (x * gain : notch(1000, detect) * on + x * gain * (1 - on) <: _ , _) , detect
with {
detect = sc(1, .1, x) * ma.SR / 2;
};

0 comments on commit f34c59b

Please sign in to comment.