aboutsummaryrefslogtreecommitdiff
path: root/site/udo/oprepare.udo
diff options
context:
space:
mode:
authorRichard <q@1bpm.net>2025-04-13 18:48:02 +0100
committerRichard <q@1bpm.net>2025-04-13 18:48:02 +0100
commit9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 (patch)
tree291bd79ce340e67affa755a8a6b4f6a83cce93ea /site/udo/oprepare.udo
downloadapps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.gz
apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.bz2
apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.zip
initial
Diffstat (limited to 'site/udo/oprepare.udo')
-rwxr-xr-xsite/udo/oprepare.udo93
1 files changed, 93 insertions, 0 deletions
diff --git a/site/udo/oprepare.udo b/site/udo/oprepare.udo
new file mode 100755
index 0000000..f222ad3
--- /dev/null
+++ b/site/udo/oprepare.udo
@@ -0,0 +1,93 @@
+#ifndef UDO_OPREPARE
+#define UDO_OPREPARE ##
+/*
+ Offline preparation system: record a sound in one k-cycle to a ftable for future use
+ May be used where online playback would be too CPU heavy
+ Instruments to be prepared should be prepended with src_
+
+ This file is part of the SONICS UDO collection by Richard Knight 2021
+ License: GPL-2.0-or-later
+ http://1bpm.net
+
+*/
+
+
+/*
+ Internal preparation instrument: loop through gSoprepare
+ p4 index of gSoprepare to process
+ p5 instrument name to schedule when all sounds have been prepared
+*/
+gSoprepare[] init 1 ; filled by oprepare opcode: input instrument names without src_ prepended
+giopreparedfns[] init 1 ; filled by oprepare opcode: output ftable numbers corresponding to above
+instr _oprepare
+ iprepareindex = p4
+ SonComplete = p5
+ if (iprepareindex >= lenarray(gSoprepare)) then
+ event_i "i", SonComplete, 0, 3600
+ turnoff
+ else
+ Sprepareinstr = gSoprepare[iprepareindex]
+ Srcinstr = sprintf("src_%s", Sprepareinstr)
+ ilen = 0.8
+ p3 = ilen
+ ifn ftgen 0, 0, sr*ilen, 7, 0
+ giopreparedfns[iprepareindex] = ifn
+ ktimek timeinstk
+ if (ktimek == 1) then
+ kcycles = ilen * kr
+ kcount init 0
+loop:
+ apos phasor (1/(ftlen(ifn)/sr))
+ aproc subinstr Srcinstr, 1, 0.1
+ tabw aproc, apos, ifn, 1
+ loop_lt kcount, 1, kcycles, loop
+ elseif (ktimek == 5) then
+ scoreline_i sprintf("i\"_oprepare\" 0 1 %d \"%s\"", iprepareindex+1, SonComplete)
+ turnoff
+ endif
+ endif
+
+endin
+
+
+/*
+ Start the offline preparation
+
+ oprepare Snames[], SonComplete
+
+ Snames[] list of instruments to process (instrument name without src_ prepended)
+ SonComplete instrument to be scheduled when preparation process has completed
+*/
+opcode oprepare, 0, S[]S
+ Snames[], SonComplete xin
+ gSoprepare = Snames
+ giopreparedfns[] init lenarray(Snames)
+ scoreline_i sprintf("i\"_oprepare\" 0 1 0 \"%s\"", SonComplete)
+endop
+
+
+/*
+ Get the ftable number of a specified instrument name as originally passed to oprepare
+
+ ifn oprepare_getfn Sname
+
+ ifn the ftable
+ Sname name of offline-prepared instrument
+*/
+opcode oprepare_getfn, i, S
+ Sname xin
+ ifn = -1
+ index = 0
+ while (index < lenarray(gSoprepare)) do
+ if (strcmp(gSoprepare[index], Sname) == 0) then
+ ifn = giopreparedfns[index]
+ endif
+ index += 1
+ od
+complete:
+ xout ifn
+endop
+
+
+#end
+