Created
May 18, 2021 17:30
-
-
Save jpcima/f75a57aae70202fe1b9432b5aa3acf6b to your computer and use it in GitHub Desktop.
Pitch shifter G09.pitchshift.pd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: ISC | |
import("stdfaust.lib"); | |
// | |
// shift: transposition in semitones | |
// wt: window time | |
// dt: delay time | |
// | |
mspShifter(shift, wt, dt, sig) = mix with { | |
// speed change | |
sc = exp(.0577622650*shift); // 2^(shift/12.0) | |
// tape head rotation frequency | |
tf = sc : -(1.0) : ma.neg : /(wt); | |
// phasors | |
ph(0) = x letrec { 'x = bidiWrap(x+tf/ma.SR); }; | |
ph(1) = ph(0) : +(0.5) : uniWrap; | |
// crossfades | |
xf(i) = xfWave(0.5*(ph(i)-0.5)); /* cos((ph(i)-0.5)*ma.PI) */ | |
xfWave(x) = si.interpolate(fp,y1,y2) with { | |
size = 128; | |
table = rdtable(size, os.coswaveform(size)); | |
pos = bidiWrap(x)*size; | |
y1 = table(int(pos)); | |
y2 = table((int(pos)+1)%size); | |
fp = pos-int(pos); | |
}; | |
// delay times | |
delt(i) = wt*ph(i)+dt; | |
// delay lines | |
dell(i) = sig : de.fdelay(65536, delt(i)*ma.SR); | |
// mix | |
mix = sum(i, 2, dell(i)*xf(i)); | |
// utility | |
uniWrap(p) = p-int(p); | |
bidiWrap(p) = ba.if(p>0, p, 1.0+p) : uniWrap; | |
}; | |
process = par(i, 2, mspShifter(s, w, 0.0)) with { | |
s = hslider("[1] shift (semitones)", 0.0, -12.0, 12.0, 0.1); | |
w = hslider("[2] window (ms)", 120.0, 1.0, 200.0, 1.0) : *(1e-3); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment