#include "/twist/transform_api.udo" #include "/frequency_tools.udo" opcode _twst_tf_normalise_analyse, i, iii ifn, istartsamp, iendsamp xin iscale = 0 imaxpos = 0 imaxneg = 0 while (istartsamp < iendsamp) do ival table istartsamp, ifn if (ival > 0 && ival > imaxpos) then imaxpos = ival elseif (ival < 0 && ival < imaxneg) then imaxneg = ival endif istartsamp += 1 od iscale = ((1 / max(abs(imaxneg), abs(imaxpos)))) xout iscale endop instr twst_tf_normalise $TWST_TRANSFORM i_, i_, istartsamp, iendsamp, idocut, ilength twst_tf_getstate aL, aR, ileft, iright twst_getinput istereoequal = twst_parami("equal") kuserscale = twst_param:k("scale") if (ileft == 1) then iscalingL _twst_tf_normalise_analyse gitwst_bufferL[gitwst_instanceindex], istartsamp, iendsamp endif if (iright == 1) then iscalingR _twst_tf_normalise_analyse gitwst_bufferR[gitwst_instanceindex], istartsamp, iendsamp endif if (istereoequal == 1 && ileft == 1 && iright == 1) then iscaling = min(iscalingL, iscalingR) aL *= iscaling * kuserscale aR *= iscaling * kuserscale elseif (ileft == 1) then aL *= iscalingL * kuserscale elseif (iright == 1) then aR *= iscalingR * kuserscale endif outs aL, aR endin instr twst_tf_amplitude $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kgain = twst_param:k("gain") kbalance = twst_param:k("balance") if (ileft == 1) then kb = max:k(1, (1 - kbalance) * 2) aL *= kgain * kb endif if (iright == 1) then kb = max:k(1, kbalance * 2) aR *= kgain * kb endif outs aL, aR endin instr twst_tf_strobe $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput krate = twst_param:k("rate") kholdtime = twst_param:k("holdtime") kwindowed = twst_param:k("windowed") ktrig metro krate ktrig trighold ktrig, kholdtime kamp = 1 - ktrig if (kwindowed == 1) then kenv portk kamp, kholdtime * 0.5 else kenv = kamp endif if (ileft == 1) then aL *= kenv endif if (iright == 1) then aR *= kenv endif outs aL, aR endin instr twst_tf_bitcrush $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kcrush = twst_param:k("crush") if (ileft == 1) then aL bitcrush aL, kcrush elseif (iright == 1) then aR bitcrush aR, kcrush endif outs aL, aR endin instr twst_tf_suppress $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kmode = twst_param:k("mode") kthreshold = twst_param:k("threshold") if (ileft == 1) then if (kmode == 0) then aL limit aL, -kthreshold, kthreshold elseif (kmode == 1) then aL wrap aL, -kthreshold, kthreshold elseif (kmode == 2) then aL mirror aL, -kthreshold, kthreshold endif endif if (iright == 1) then if (kmode == 0) then aR limit aR, -kthreshold, kthreshold elseif (kmode == 1) then aR wrap aR, -kthreshold, kthreshold elseif (kmode == 2) then aR mirror aR, -kthreshold, kthreshold endif endif outs aL, aR endin instr twst_tf_pdclip $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kwidth = twst_param:k("width") kcentre = twst_param:k("centre") ibipolar = twst_parami("bipolar") ifullscale = twst_parami("fullscale") if (ileft == 1) then aL pdclip aL, kwidth, kcentre, ibipolar, ifullscale endif if (iright == 1) then aR pdclip aR, kwidth, kcentre, ibipolar, ifullscale endif outs aL, aR endin instr twst_tf_distort $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kamount = twst_param:k("amount") ihp = twst_parami("halfpower") ifn twst_tf_getwaveform if (ileft == 1) then aL distort aL, kamount, ifn, ihp endif if (iright == 1) then aL distort aR, kamount, ifn, ihp endif outs aL, aR endin instr twst_tf_distort1 $TWST_TRANSFORM aL, aR, ileft, iright twst_getinput kpregain = twst_param:k("pregain") kpostgain = twst_param:k("postgain") kshape1 = twst_param:k("shape1") kshape2 = twst_param:k("shape2") if (ileft == 1) then aL distort1 aL, kpregain, kpostgain, kshape1, kshape2, 1 endif if (iright == 1) then aL distort1 aR, kpregain, kpostgain, kshape1, kshape2, 1 endif outs aL, aR endin