#ifndef UDO_SAMPLELEVEL #define UDO_SAMPLELEVEL ## /* Sample level block processing This file is part of the SONICS UDO collection by Richard Knight 2024 License: GPL-2.0-or-later http://1bpm.net */ opcode smp_hold, a, ak ain, kratio xin aout init 0 ktrig metro kr * kratio if (ktrig == 1) then kindex = 0 while (kindex < ksmps) do aout[kindex] = ain[kindex] kindex += 1 od endif xout aout endop opcode smp_rearrange, aa, iiiij ichops, ichopmin, ichopmax, ifnL, ifnR xin if (ichopmin > ichopmax) then ichopmin = ichopmax endif ilen = ftlen(ifnL) if (ichopmin > ilen) then ichopmin = round(ilen * 0.1) endif if (ichopmax > ilen) then ichopmax = round(ilen * 0.2) endif ichopfn ftgentmp 0, 0, -(ichops * 3), 2, 0 index = 0 iwriteindex = 0 while (index < ichops) do ichoplen = round(random(ichopmin, ichopmax)) ichopstart = round(random(0, ilen - ichoplen)) tabw_i ichopstart, iwriteindex, ichopfn tabw_i ichoplen, iwriteindex + 1, ichopfn tabw_i round(random(0, ilen - ichoplen)), iwriteindex + 2, ichopfn iwriteindex += 3 index += 1 od apos lphasor 1 kindex1 = 0 kinmove init 0 while (kindex1 < ftlen(ichopfn)) do kstart tab kindex1, ichopfn klen tab kindex1 + 1, ichopfn kdest tab kindex1 + 2, ichopfn koffset = 0 kindex2 = 0 while (kindex2 < ksmps) do if (apos[kindex2] >= kdest) then kinmove = 1 koffset = apos[kindex2] - kdest endif if (apos[kindex2] >= kdest + klen) then kinmove = 0 endif if (kinmove == 1) then apos[kindex2] = kstart + koffset endif kindex2 += 1 od kindex1 += 3 od aL table3 apos, ifnL if (ifnR != -1) then aR table3 apos, ifnR else aR = aL endif xout aL, aR endop opcode smp_rearrange, a, iiii ichops, ichopmin, ichopmax, ifn xin aout, a_ smp_rearrange ichops, ichopmin, ichopmax, ifn xout aout endop #end