From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/udo/twist/transforms/warping.udo | 210 ++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100755 site/udo/twist/transforms/warping.udo (limited to 'site/udo/twist/transforms/warping.udo') diff --git a/site/udo/twist/transforms/warping.udo b/site/udo/twist/transforms/warping.udo new file mode 100755 index 0000000..3eb4e6e --- /dev/null +++ b/site/udo/twist/transforms/warping.udo @@ -0,0 +1,210 @@ +#include "/twist/transform_api.udo" +#include "/sample_level.udo" + +instr twst_tf_smphold + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + kratio = twst_param:k("ratio") + if (ileft == 1) then + aL smp_hold aL, kratio + endif + if (iright == 1) then + aR smp_hold aR, kratio + endif + outs aL, aR +endin + +instr twst_tf_fftpitchscale + $TWST_TRANSFORM + fL, fR, aL, aR, ileft, iright twst_getfinput + kscale = twst_tf_pitchscale() + kformant = twst_param:k("formants") + kcoefs = twst_param:k("formantcoefs") + + if (ileft == 1) then + fL1 pvscale fL, kscale, kformant, 1, kcoefs + aL twst_tf_fresynth fL1 + endif + if (iright == 1) then + fR1 pvscale fR, kscale, kformant, 1, kcoefs + aR twst_tf_fresynth fR1 + endif + outs aL, aR +endin + +opcode _twst_tf_autotune, f, fkkk + fsig, kthreshold, kformant, kcoefs xin + kfreq, kamp pvspitch fsig, kthreshold + if (kfreq > 20) then + knote ftom kfreq + kscale = cpsmidinn:k(int:k(knote)) / kfreq + fsigo pvscale fsig, kscale, kformant, 1, kcoefs + else + fsigo = fsig + endif + xout fsigo +endop + + +instr twst_tf_autotune + $TWST_TRANSFORM + fL, fR, aL, aR, ileft, iright twst_getfinput + kthreshold = twst_param:k("threshold") + kformant = twst_param:k("formants") + kcoefs = twst_param:k("formantcoefs") + + if (ileft == 1) then + fL1 _twst_tf_autotune fL, kthreshold, kformant, kcoefs + aL twst_tf_fresynth fL1 + endif + if (iright == 1) then + fR1 _twst_tf_autotune fR, kthreshold, kformant, kcoefs + aR twst_tf_fresynth fR1 + endif + outs aL, aR +endin + + +instr twst_tf_hilbertpitchscale + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + ifftsize = twst_parami("fftsize") + kscale = twst_tf_pitchscale() + twst_setlatencysamples(ifftsize) + + if (ileft == 1) then + ahL1, ahL2 hilbert2 aL, ifftsize, ifftsize / 4 + amL, afmL fmanal ahL1, ahL2 + aL oscil amL, afmL * kscale + endif + if (iright == 1) then + ahR1, ahR2 hilbert2 aR, ifftsize, ifftsize / 4 + amR, afmR fmanal ahR1, ahR2 + aR oscil amR, afmR * kscale + endif + outs aL, aR +endin + +instr twst_tf_waveset + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + kreps = twst_param:k("reps") + if (ileft == 1) then + aL waveset aL, kreps + endif + if (iright == 1) then + aR waveset aR, kreps + endif + outs aL, aR +endin + +instr twst_tf_freeze + $TWST_TRANSFORM + fL, fR, aL, aR, ileft, iright twst_getfinput + kfreezeamp = twst_param:k("freezeamp") + kfreezefreq = twst_param:k("freezefreq") + if (ileft == 1) then + fL1 pvsfreeze fL, kfreezeamp, kfreezefreq + aL twst_tf_fresynth fL1 + endif + if (iright == 1) then + fR1 pvsfreeze fR, kfreezeamp, kfreezefreq + aR twst_tf_fresynth fR1 + endif + outs aL, aR +endin + +instr twst_tfi_sndwarp + $TWST_TRANSFORM + ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate + ireadmode = twst_parami("readmode") + kpitchscale = twst_tf_pitchscale() + iwinsize = twst_parami("winsize") + irandwin = twst_parami("randwin") + ioverlap = twst_parami("overlap") + ifnWindow = twst_tf_getwintype() + + p3 = ilength + if (ireadmode == 0) then + atime linseg 0, p3, ilength + elseif (ireadmode == 1) then + ktime = twst_param:k("readtime") + twst_tf_setplayposition ktime + atime = a(ktime * ilength) + elseif (ireadmode == 2) then + itimescale = twst_parami("timescale") + p3 = ilength * itimescale + atime linseg 0, p3, ilength + elseif (ireadmode == 3) then + atime linseg ilength, p3, 0 + endif + + ifnL, ifnR twst_tfi_getfn + + kpitchscale *= ftsr(ifnL) / sr + apitchscale = a(kpitchscale) + if (ileft == 1) then + aL sndwarp 1, atime, apitchscale, ifnL, 0, iwinsize, irandwin, ioverlap, ifnWindow, 1 + endif + if (iright == 1) then + aR sndwarp 1, atime, apitchscale, ifnR, 0, iwinsize, irandwin, ioverlap, ifnWindow, 1 + endif + outs aL, aR +endin + +instr twst_tfi_mincer + $TWST_TRANSFORM + ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate + ifftsize = twst_parami("fftsize") + kpitchscale = twst_tf_pitchscale() + klock = twst_param:k("phaselock") + ireadmode = twst_parami("readmode") + idecimation = twst_parami("decimation") + + p3 = ilength + if (ireadmode == 0) then + atime linseg 0, p3, ilength + elseif (ireadmode == 1) then + ktime = twst_param:k("readtime") + twst_tf_setplayposition ktime + atime = a(ktime * ilength) + elseif (ireadmode == 2) then + itimescale = twst_parami("timescale") + p3 = ilength * itimescale + atime linseg 0, p3, ilength + elseif (ireadmode == 3) then + atime linseg ilength, p3, 0 + endif + + twst_setlatencysamples(ifftsize) + ifnL, ifnR twst_tfi_getfn + if (ileft == 1) then + aL mincer atime, 1, kpitchscale, ifnL, klock, ifftsize, idecimation + endif + if (iright == 1) then + aR mincer atime, 1, kpitchscale, ifnR, klock, ifftsize, idecimation + endif + outs aL, aR +endin + +instr twst_tfi_paulstretch + $TWST_TRANSFORM + ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate + + istretch = twst_parami("stretch") + iwinsize = twst_parami("winsize") + iduration = ilength * istretch + p3 = iduration + + twst_setlatencyseconds iwinsize + + ifnL, ifnR twst_tfi_getfn + + if (ileft == 1) then + aL paulstretch istretch, iwinsize, ifnL + endif + if (iright == 1) then + aR paulstretch istretch, iwinsize, ifnR + endif + outs aL, aR +endin -- cgit v1.2.3