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/cross_processing.udo | 176 +++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100755 site/udo/twist/transforms/cross_processing.udo (limited to 'site/udo/twist/transforms/cross_processing.udo') diff --git a/site/udo/twist/transforms/cross_processing.udo b/site/udo/twist/transforms/cross_processing.udo new file mode 100755 index 0000000..203c393 --- /dev/null +++ b/site/udo/twist/transforms/cross_processing.udo @@ -0,0 +1,176 @@ +#include "/twist/transform_api.udo" +#include "/mfcc_match.udo" +#include "/fftconvolve.udo" +#include "/chop.udo" + + +instr twst_tf_crossrearrange + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + kminsamples = twst_param:k("minsamples") + kmaxsamples = twst_param:k("maxsamples") + kstereounique = twst_param:k("stereounique") + krate = twst_param:k("rate") + + ktrig metro krate + async init 0 + + if (ktrig == 1) then + kfnLo, kfnRo twst_getrandombuffers kstereounique + ktablen = tableng:k(kfnLo) + klen = min:k(random:k(kminsamples, kmaxsamples), ktablen) + kstart = random:k(0, ktablen - klen) + async = 1 + else + async = 0 + endif + + apos, a_ syncphasor 1 / (klen / sr), async + areadpos = (apos * klen) + kstart + + if (ileft == 1) then + aL tablekt areadpos, kfnLo + endif + if (iright == 1) then + aR tablekt areadpos, kfnRo + endif + + outs aL, aR +endin + +instr twst_tf_directconvolve + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + ifnLo, ifnRo twst_tfi_getcrossfn + kamp = twst_parami("amp") + isizeratio = twst_parami("sizeratio") + if (ileft == 1) then + aL dconv aL * kamp, isizeratio * ftlen(ifnLo), ifnLo + endif + if (iright == 1) then + aR dconv aR * kamp, isizeratio * ftlen(ifnRo), ifnRo + endif + outs aL, aR +endin + +instr twst_tf_blockconvolve + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + aLo, aRo, ilefto, irighto twst_getcrossinput + ifftsize = twst_parami("fftsize") + ioverlap = twst_parami("overlap") + ihopsize = ifftsize / ioverlap + + if (ileft == 1 && ilefto == 1) then + aL blockconvolve aL, aLo, ifftsize, ihopsize + endif + if (iright == 1 && irighto == 1) then + aR blockconvolve aR, aRo, ifftsize, ihopsize + endif + outs aL, aR +endin + +/* not in WASM at current +instr twst_tf_tvconv + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + aLo, aRo, ilefto, irighto twst_getcrossinput + kapply1 = twst_param:k("apply1") + kapply2 = twst_param:k("apply2") + imode = twst_parami("mode") + iparts = twst_parami("parts") + idftfiltersize = twst_parami("dftfiltersize") + ifirfiltersize = twst_parami("firfiltersize") + + if (imode == 1) then + iparts = 1 + ifiltersize = ifirfiltersize + else + ifiltersize = idftfiltersize + endif + + if (ileft == 1 && ilefto == 1) then + aL tvconv aL, aLo, kapply1, kapply2, iparts, ifiltersize + endif + + if (iright == 1 && irighto == 1) then + aR tvconv aR, aRo, kapply1, kapply2, iparts, ifiltersize + endif + outs aL, aR +endin +*/ + +instr twst_tf_crosssynth + $TWST_TRANSFORM + fL, fR, aL, aR, ileft, iright twst_getfinput + fLo, fRo, ilefto, irighto twst_getfcrossinput + kamp1 = twst_param:k("amp1") + kamp2 = twst_param:k("amp2") + + if (ileft == 1 && ilefto == 1) then + foutL pvscross fL, fLo, kamp1, kamp2 + aL twst_tf_fresynth foutL + endif + + if (iright == 1 && irighto == 1) then + foutR pvscross fR, fRo, kamp1, kamp2 + aR twst_tf_fresynth foutR + endif + outs aL, aR +endin + + +instr twst_tf_morph + $TWST_TRANSFORM + fL, fR, aL, aR, ileft, iright twst_getfinput + fLo, fRo, ilefto, irighto twst_getfcrossinput + kamp = twst_param:k("amp") + kfreq = twst_param:k("freq") + + if (ileft == 1 && ilefto == 1) then + foutL pvsmorph fL, fLo, kamp, kfreq + aL twst_tf_fresynth foutL + endif + + if (iright == 1 && irighto == 1) then + foutR pvsmorph fR, fRo, kamp, kfreq + aR twst_tf_fresynth foutR + endif + outs aL, aR +endin + +instr twst_tf_mfccmatch + $TWST_TRANSFORM + aL, aR, ileft, iright twst_getinput + ifnoL, ifnoR twst_tfi_getcrossfn + ifftsize = twst_parami("fftsize") + ifreqmin = twst_parami("freqmin") + ifreqmax = twst_parami("freqmax") + ibands = twst_parami("bands") + kstretch = twst_param:k("stretch") + kauditionreadyL init 0 + kauditionreadyR init 0 + ktimek timeinstk + + if (ileft == 1) then + kdone, ifnAnalysisL mfm_analysecorpus ktimek, ifnoL, ifreqmin, ifreqmax, ifftsize, ibands, -1, 1 + if (kdone == 1) then + kauditionreadyL = 1 + aoutL mfm_matchplay aL, ifnoL, ifnAnalysisL, kstretch, ifreqmin, ifreqmax, ifftsize, ibands + endif + else + kauditionreadyL = 1 + endif + if (iright == 1) then + kdone, ifnAnalysisR mfm_analysecorpus ktimek, ifnoR, ifreqmin, ifreqmax, ifftsize, ibands, -1, 1 + if (kdone == 1) then + kauditionreadyR = 1 + aoutR mfm_matchplay aR, ifnoR, ifnAnalysisR, kstretch, ifreqmin, ifreqmax, ifftsize, ibands + endif + else + kauditionreadyR = 1 + endif + + chnset (kauditionreadyL & kauditionreadyR), "auditionready" + outs aoutL, aoutR +endin -- cgit v1.2.3