Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created May 16, 2021 15:19
Show Gist options
  • Save jpcima/5e0c948127ff6becd4477aebf524f27e to your computer and use it in GitHub Desktop.
Save jpcima/5e0c948127ff6becd4477aebf524f27e to your computer and use it in GitHub Desktop.
Pitch-shifter 3 délais foireux
import("stdfaust.lib");
// Transposer with 3 delay lines
// w: Window length (samples)
// s: Detune amount (semitones)
// t: Tuning adjustment factor
GenericTransposer3(w, s, t, sig) =
sum(i, 3, mix(i)*del(w*(mod(i)*ov+(i/2.)*(1.-ov)))) : *(0.5)
with {
ov = 2./3.;
//f = hslider("[0] mod frequency", 0.0, -20.0, 20.0, 0.01); // tune me
f = (1.-pow(2.,s/12.)) : *(tune*ma.SR/w) with {
//tune = hslider("[0] tune adjust", 1.0, 0.0, 5.0, 0.001);
tune = t;
};
del(t) = sig : de.fdelay(262144, t);
phase(0) = p letrec { 'p=wrap(1.0+p+f/ma.SR); };
phase(i) = wrap(phase(0)+i/3.0);
mod(i) = phase(i);
mix(i) = 1.0-cos(2.0*ma.PI*phase(i)); // optimize me
wrap(p) = p-int(p);
};
Transposer3_30ms(w, s) = GenericTransposer3(30e-3*ma.SR, s, 1.572);
Transposer3_35ms(w, s) = GenericTransposer3(35e-3*ma.SR, s, 1.540);
Transposer3_40ms(w, s) = GenericTransposer3(40e-3*ma.SR, s, 1.467);
Transposer3_45ms(w, s) = GenericTransposer3(45e-3*ma.SR, s, 1.415);
Transposer3_50ms(w, s) = GenericTransposer3(50e-3*ma.SR, s, 1.375);
process(l, r) = par(i, 2, ba.if(b, in(i), (in(i) : transp))) with {
in(0) = l;
in(1) = r;
transp = /*aalpf :*/ Transposer3_50ms(t*ma.SR, s);
aalpf = filter(fc : smooth) with { // experiment
filter(fc) = fi.lowpass(4, fc);
smooth = si.smooth(ba.tau2pole(t60/6.91)) with { t60 = 10e-3; };
fc = (fmax / pow(2.,s/12.)) : min(fmax) with { fmax = 20000; };
};
b = checkbox("[0] bypass");
t = hslider("[1] window", 50e-3, 1e-3, 500e-3, 10e-3);
s = hslider("[2] tune", 0, -12, 12, 0.1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment