#include "/twist/transform_api.udo" #include "/pvs_tabproc.udo" #include "/spectral_transforms.udo" #include "/fx_autoglitch.udo" #include "/host_platform.udo" #include "/addsub.udo" instr twst_tf_tpvinvert $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kinvertamp = twst_param:k("invertamp") kinvertfreq = twst_param:k("invertfreq") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_invert kreadyL, itpvdataL, kinvertamp, kinvertfreq fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_invert kreadyR, itpvdataR, kinvertamp, kinvertfreq fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvbubble $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kchance = twst_param:k("chance") kstereounique = twst_param:k("stereounique") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_bubble kreadyL, itpvdataL, kchance, kstereounique fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_bubble kreadyR, itpvdataR, kchance, kstereounique fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvsmear $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput imaxframes = twst_parami("maxframes") kframes = twst_param:k("frames") kavgfreqs = twst_param:k("avgfreqs") kincludeoriginal = twst_param:k("includeoriginal") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_smear kreadyL, itpvdataL, imaxframes, kframes, kavgfreqs, kincludeoriginal fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_smear kreadyR, itpvdataR, imaxframes, kframes, kavgfreqs, kincludeoriginal fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvscramble $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kstep = twst_param:k("step") kdoamp = twst_param:k("scrambleamp") kdofreq = twst_param:k("scramblefreq") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_scramble kreadyL, itpvdataL, kstep, kdoamp, kdofreq fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_scramble kreadyR, itpvdataR, kstep, kdoamp, kdofreq fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvthreshold $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kthreshold = twst_param:k("threshold") kdirection = twst_param:k("direction") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_threshold kreadyL, itpvdataL, kthreshold, kdirection fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_threshold kreadyR, itpvdataR, kthreshold, kdirection fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvfreeze $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kfreeze = twst_param:k("freeze") kfreezeamp = twst_param:k("freezeamp") kfreezefreq = twst_param:k("freezefreq") kcrossfade = twst_param:k("crossfade") if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_freeze1 kreadyL, itpvdataL, kfreeze, kfreezeamp, kfreezefreq, kcrossfade fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_freeze1 kreadyR, itpvdataR, kfreeze, kfreezeamp, kfreezefreq, kcrossfade fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvwrap $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kwrapampbin = twst_param:k("wrapampbin") kwrapfreqbin = twst_param:k("wrapfreqbin") if (ileft == 1) then i_, inumbins, i_, i_ pvsinfo fL kreadyL, itpvdataL tpv_anal fL tpv_wrap kreadyL, itpvdataL, kwrapampbin * inumbins, kwrapfreqbin * inumbins fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then i_, inumbins, i_, i_ pvsinfo fR kreadyR, itpvdataR tpv_anal fR tpv_wrap kreadyR, itpvdataR, kwrapampbin * inumbins, kwrapfreqbin * inumbins fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvswap $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kampStart = twst_param:k("ampstart") kampLength = twst_param:k("amplength") kampTarget = twst_param:k("amptarget") kfreqStart = twst_param:k("freqstart") kfreqLength = twst_param:k("freqlength") kfreqTarget = twst_param:k("freqtarget") kwrapmode = twst_param:k("wrapmode") if (ileft == 1) then i_, inumbins, i_, i_ pvsinfo fL kreadyL, itpvdataL tpv_anal fL tpv_swap kreadyL, itpvdataL, kampStart * inumbins, kampLength * inumbins, kampTarget * inumbins, kfreqStart * inumbins, kfreqLength * inumbins, kfreqTarget * inumbins, kwrapmode fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then i_, inumbins, i_, i_ pvsinfo fR kreadyR, itpvdataR tpv_anal fR tpv_swap kreadyR, itpvdataR, kampStart * inumbins, kampLength * inumbins, kampTarget * inumbins, kfreqStart * inumbins, kfreqLength * inumbins, kfreqTarget * inumbins, kwrapmode fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin instr twst_tf_tpvaverage $TWST_TRANSFORM setksmps(64) fL, fR, aL, aR, ileft, iright twst_getfinput kmax = twst_param:k("maxframes") kavgamp = twst_param:k("avgamp") kavgfreq = twst_param:k("avgfreq") krate = twst_param:k("rate") ktrig metro krate if (ileft == 1) then kreadyL, itpvdataL tpv_anal fL tpv_average kreadyL, itpvdataL, kmax, kavgamp, kavgfreq, ktrig fL tpv_resynth itpvdataL, fL aL twst_tf_fresynth fL endif if (iright == 1) then kreadyR, itpvdataR tpv_anal fR tpv_average kreadyR, itpvdataR, kmax, kavgamp, kavgfreq, ktrig fR tpv_resynth itpvdataR, fR aR twst_tf_fresynth fR endif outs aL, aR endin /* instr twst_tf_stencil $TWST_TRANSFORM Spvx = strcat(host_tempdir(), "twist_stencil.pvx") ifftsize = twst_parami("fftsize") kran init 0 ktimek timeinstk if (ktimek == 1) then ifnL, ifnR, istart, ilen, ileft, iright twst_getcrossdata ikcycles = round(ilen / kr) kcount = 1 while (kcount < ikcycles) do aLo, aRo, ileft, iright twst_getcrossinput if (ileft == 1 && iright == 1) then ain = (aLo + aRo) * 0.5 elseif (ileft == 1) then ain = aLo elseif (iright == 1) then ain = aRo endif f1 pvsanal ain, ifftsize, ifftsize/4, ifftsize, 1 pvsfwrite f1, Spvx kcount += 1 od elseif (ktimek == 1) then schedulek("_twst_tf_stencilplayback", 0, p3, p4, Spvx) ; TODO : won't work offline endif aL, aR bus_read "stencilplayback" kreleasing init 0 if (kreleasing == 0 && release:k() == 1) then turnoff2 "_twst_tf_stencilplayback", 0, 1 kreleasing = 1 endif outs aL, aR endin instr _twst_tf_stencilplayback $TWST_TRANSFORM Spvx = strget(p5) fL, fR, aL, aR, ileft, iright twst_getfinput ifftsize = twst_parami("fftsize") kgain = twst_param:k("gain") klevel = twst_param:k("level") ifn ftgentmp 0, 0, (ifftsize * 2) + 1, 43, Spvx, 1 if (ileft == 1) then fpsL pvstencil fL, kgain, klevel, ifn aL twst_tf_fresynth fpsL endif if (iright == 1) then fpsR pvstencil fR, kgain, klevel, ifn aR twst_tf_fresynth fpsR endif bus_mix("stencilplayback", aL, aR) endin */ instr twst_tf_spectralshift $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kfreqincr = twst_param:k("freqincr") kporttime = twst_param:k("porttime") kfreqscale = twst_tf_pitchscale() istart = twst_parami("start") iend = twst_parami("end") ifn = twst_tf_getwaveform() if (ileft == 1) then aL spc_shift fL, kfreqincr, istart, iend, kfreqscale, kporttime, ifn endif if (iright == 1) then aR spc_shift fR, kfreqincr, istart, iend, kfreqscale, kporttime, ifn endif outs aL, aR endin instr twst_tf_spectraldelay $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kdeltime = twst_param:k("time") kdeladd = twst_param:k("add") kporttime = twst_param:k("porttime") kfreqscale = twst_tf_pitchscale() istart = twst_parami("start") iend = twst_parami("end") ifn = twst_tf_getwaveform() if (ileft == 1) then aL spc_delay fL, kdeltime, kdeladd, istart, iend, kfreqscale, kporttime, ifn endif if (iright == 1) then aR spc_delay fR, kdeltime, kdeladd, istart, iend, kfreqscale, kporttime, ifn endif outs aL, aR endin instr twst_tf_spectralgate $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kthresh = twst_param:k("threshold") khold = twst_param:k("hold") kporttime = twst_param:k("porttime") kfreqscale = twst_tf_pitchscale() istart = twst_parami("start") iend = twst_parami("end") ifn = twst_tf_getwaveform() if (ileft == 1) then aL spc_gate fL, kthresh, khold, istart, iend, kfreqscale, kporttime, ifn endif if (iright == 1) then aR spc_gate fR, kthresh, khold, istart, iend, kfreqscale, kporttime, ifn endif outs aL, aR endin instr twst_tfi_spectralgrain1 $TWST_TRANSFORM ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate ifnL, ifnR twst_tfi_getfn ireadmode = twst_parami("readmode") if (ireadmode == 0) then ktime linseg 0, p3, ilength elseif (ireadmode == 1) then ktime = twst_param:k("readtime") twst_tf_setplayposition ktime ktime *= ilength elseif (ireadmode == 2) then itimescale = twst_parami("timescale") p3 = ilength * itimescale ktime linseg 0, p3, ilength elseif (ireadmode == 3) then ktime linseg ilength, p3, 0 endif kgraindur = twst_param:k("graindur") ifftsize = twst_parami("fftsize") ilayers = twst_parami("layers") kporttime = twst_param:k("porttime") kfreqscale = twst_tf_pitchscale() kfreqrand = twst_param:k("freqrand") kdurrand = twst_param:k("durrand") kpitchrand = twst_param:k("pitchrand") istart = twst_parami("start") iend = twst_parami("end") ifn = twst_tf_getwaveform() twst_setlatencysamples(ifftsize) if (ileft == 1) then aL spc_grain1 ifnL, ktime, kgraindur, ifftsize, ilayers, istart, iend, kfreqscale, kfreqrand, kdurrand, kpitchrand, kporttime, ifn endif if (iright == 1) then aR spc_grain1 ifnR, ktime, kgraindur, ifftsize, ilayers, istart, iend, kfreqscale, kfreqrand, kdurrand, kpitchrand, kporttime, ifn endif outs aL, aR endin instr twst_tf_spectralread $TWST_TRANSFORM ileft, iright, istartsamp, iendsamp, idocut, ilength twst_tf_getstate ifftsize = twst_parami("fftsize") ktime = twst_param:k("readtime") * ilength twst_tf_setplayposition ktime twst_setlatencysamples(ifftsize) ktimek timeinstk ilensamps = iendsamp - istartsamp ikcycles = ilength * kr kcount init 0 if (ktimek == 1) then while (kcount < ikcycles) do apos linseg 0, ilength, iendsamp if (ileft == 1 && iright == 1) then aL table3 apos, gitwst_bufferL[gitwst_instanceindex] aR table3 apos, gitwst_bufferR[gitwst_instanceindex] asig = (aL + aR) * 0.5 elseif (ileft == 1) then asig table3 apos, gitwst_bufferL[gitwst_instanceindex] elseif (iright == 1) then asig table3 apos, gitwst_bufferR[gitwst_instanceindex] endif fsig pvsanal asig, ifftsize, ifftsize/4, ifftsize, 1 ipbuf, k_ pvsbuffer fsig, ilength kcount += 1 od else if (ileft == 1) then fL pvsbufread ktime, ipbuf aL twst_tf_fresynth fL endif if (iright == 1) then fR pvsbufread ktime, ipbuf aR twst_tf_fresynth fR endif endif outs aL, aR endin instr twst_tf_centroidoscillator $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kporttime = twst_param:k("porttime") kfreqscale = twst_tf_pitchscale() kfn twst_tf_getwaveformk if (ileft == 1) then kcent pvscent fL kfreq portk kcent * kfreqscale, kporttime aL oscilikt 1, kfreq, kfn endif if (iright == 1) then kcent pvscent fR kfreq portk kcent * kfreqscale, kporttime aR oscilikt 1, kfreq, kfn endif outs aL, aR endin instr twst_tf_binoscillator $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kporttime = twst_param:k("porttime") kbin = twst_param:k("bin") kfreqscale = twst_tf_pitchscale() kfn twst_tf_getwaveformk if (ileft == 1) then i_, inumbins, i_, i_ pvsinfo fL kamp, kfreqbase pvsbin fL, round:k(kbin * inumbins) kfreq portk kfreqbase * kfreqscale, kporttime aL oscilikt 1, kfreq, kfn endif if (iright == 1) then i_, inumbins, i_, i_ pvsinfo fR kamp, kfreqbase pvsbin fL, round:k(kbin * inumbins) kfreq portk kfreqbase * kfreqscale, kporttime aR oscilikt 1, kfreq, kfn endif outs aL, aR endin opcode _twst_tf_partialreconstruction, a, aikkkikkki ain, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn xin ffreq, fphase pvsifd ain, ifftsize, ifftsize/4, 1 ftrks partials ffreq, fphase, kthresh, kminpoints, kmaxgap, imaxtracks aout resyn ftrks, kampscale, kfreqscale, kmaxtracks, ifn aout dcblock aout xout aout endop instr twst_tf_partialreconstruction $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput ifftsize = twst_parami("fftsize") kthresh = twst_param:k("threshold") kminpoints = twst_param:k("minpoints") kmaxgap = twst_param:k("maxgap") imaxtracks = round(twst_parami("anlmaxtracks") * ifftsize * 0.5) kampscale = twst_param:k("ampscale") kfreqscale = twst_tf_pitchscale() kmaxtracks = round:k(twst_param:k("resmaxtracks") * ifftsize * 0.5) ifn = twst_tf_getwaveform() twst_setlatencysamples(ifftsize) if (ileft == 1) then aL _twst_tf_partialreconstruction aL, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn endif if (iright == 1) then aR _twst_tf_partialreconstruction aR, ifftsize, kthresh, kminpoints, kmaxgap, imaxtracks, kampscale, kfreqscale, kmaxtracks, ifn endif outs aL, aR endin opcode _twst_tf_residual, a, aii ain, ifftsize, ihsize xin ffr, fphs pvsifd ain, ifftsize, ihsize, 1 ftrk partials ffr, fphs, 0, 1, 3, 500 aout sinsyn ftrk, 2, 500, gifnSine asd delayr ifftsize / sr asig deltapn ifftsize - ihsize delayw ain xout asig - aout endop instr twst_tf_residual $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput ifftsize = twst_parami("fftsize") twst_setlatencysamples(ifftsize) ihsize = ifftsize / 4 if (ileft == 1) then aL _twst_tf_residual aL, ifftsize, ihsize endif if (iright == 1) then aR _twst_tf_residual aR, ifftsize, ihsize endif outs aL, aR endin /* not in WASM instr twst_tf_trace $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput inumbins = twst_parami("fftsize") / 2 kbins = twst_param("bins") * inumbins if (ileft == 1) then foutL pvstrace fL, kbins aL twst_tf_fresynth foutL endif if (iright == 1) then foutR pvstrace fR, kbins aR twst_tf_fresynth foutR endif outs aL, aR endin */ instr twst_tf_isolator $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput kbin = twst_param("bin") kattenuation = twst_param("attenuation") kgain = twst_param("accentuation") if (ileft == 1) then foutL pvsarp fL, kbin, kattenuation, kgain aL twst_tf_fresynth foutL endif if (iright == 1) then foutR pvsarp fR, kbin, kattenuation, kgain aR twst_tf_fresynth foutR endif outs aL, aR endin instr twst_tf_blur $TWST_TRANSFORM fL, fR, aL, aR, ileft, iright twst_getfinput ktime = twst_param:k("time") if (ileft == 1) then fL1 pvsblur fL, ktime, 3 aL twst_tf_fresynth fL1 endif if (iright == 1) then fR1 pvsblur fR, ktime, 3 aR twst_tf_fresynth fR1 endif outs aL, aR endin instr twst_tf_spectralautoglitch $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kchangerate = twst_param:k("changerate") kchangechance = twst_param:k("changechance") kporttime = twst_param:k("porttime") kdo_pitchalter = twst_param:k("pitchalter") ifftsize = twst_parami("fftsize") twst_setlatencysamples ifftsize if (ileft == 1) then aL fx_spectralautoglitch aL, kchangerate, kchangechance, kdo_pitchalter, kporttime, ifftsize endif if (iright == 1) then aR fx_spectralautoglitch aR, kchangerate, kchangechance, kdo_pitchalter, kporttime, ifftsize endif outs aL, aR endin instr twst_tf_subtractive $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput ifreq = twst_parami("minfreq") ifreqmax = twst_parami("maxfreq") ifreqstepmult = twst_parami("step") ifreqstepmultrand = twst_parami("steprand") iamp = twst_parami("amp") iampmult = twst_parami("ampmult") if (ileft == 1) then aL as_subtractive aL, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult endif if (iright == 1) then aR as_subtractive aR, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult endif outs aL, aR endin instr twst_tf_phasemash $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput ifftsize = twst_parami("fftsize") kphasemode = twst_param:k("phasereplace") kphasevalue = twst_param:k("phasevalue") if (kphasemode == 0) then kphasevalue *= 7 else kphasevalue = ((kphasevalue * 2) - 1) * 3.141 endif if (ileft == 1) then aL spc_phasemash aL, kphasemode, kphasevalue, ifftsize endif if (iright == 1) then aR spc_phasemash aR, kphasemode, kphasevalue, ifftsize endif outs aL, aR endin