1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#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
|