aboutsummaryrefslogtreecommitdiff
path: root/site/udo/convolutiondb.udo
diff options
context:
space:
mode:
Diffstat (limited to 'site/udo/convolutiondb.udo')
-rwxr-xr-xsite/udo/convolutiondb.udo110
1 files changed, 110 insertions, 0 deletions
diff --git a/site/udo/convolutiondb.udo b/site/udo/convolutiondb.udo
new file mode 100755
index 0000000..55f0aef
--- /dev/null
+++ b/site/udo/convolutiondb.udo
@@ -0,0 +1,110 @@
+#ifndef UDO_CONVOLUTIONDB
+#define UDO_CONVOLUTIONDB ##
+/*
+ SQL database interface to convolution impulse usage
+
+ This file is part of the SONICS UDO collection by Richard Knight 2023
+ License: GPL-2.0-or-later
+ http://1bpm.net
+
+*/
+
+
+#include "pgdb.udo"
+#include "host_tools.udo"
+
+gSconvdbPaths[] init 1
+gSconvdbNames[] init 1
+giconvdbChannels[] init 1
+
+opcode convdb_getimpulses, 0, 0
+ Squery = {{
+ select f.id, f_localpath(%d, path), replace(basename(f.path), '.wav', '') as name, s.channels
+ from file f
+ join sound s on f.id = s.file_id
+ join filecollectionrelation fcr on fcr.file_id = f.id
+ join filecollection fc on fc.id = fcr.filecollection_id
+ where fc.name = 'Impulses'
+ order by f.path;
+ }}
+ Sres[][] dbarray gidb, sprintf(Squery, gihost_type)
+ ilen = lenarray(Sres)
+ gSconvdbPaths[] init ilen
+ gSconvdbNames[] init ilen
+ giconvdbChannels[] init ilen
+ index = 0
+ while (index < ilen) do
+ gSconvdbPaths[index] = Sres[index][1]
+ gSconvdbNames[index] = Sres[index][2]
+ giconvdbChannels[index] = strtod(Sres[index][3])
+ index += 1
+ od
+endop
+
+opcode convdb_getnames, S[], 0
+ xout gSconvdbNames
+endop
+
+opcode convdb_getindexbyname, i, S
+ Sname xin
+ index = 0
+ while (index < lenarray(gSconvdbNames)) do
+ if (strcmp(gSconvdbNames[index], Sname) == 0) then
+ goto complete
+ endif
+ index += 1
+ od
+
+complete:
+ xout index
+endop
+
+opcode convdb_randomimpulseindex, i, 0
+ xout round(random(0, lenarray(gSconvdbPaths)))
+endop
+
+opcode convdb_convolve, aa, ai
+ ain, iimpulseindex xin
+ SimpulsePath = gSconvdbPaths[iimpulseindex]
+ aL pconvolve ain, SimpulsePath, -1, 1
+ if (giconvdbChannels[iimpulseindex] == 2) then
+ aR pconvolve ain, SimpulsePath, -1, 2
+ else
+ aR = aL
+ endif
+ xout aL, aR
+endop
+
+
+opcode convdb_convolve, aa, aai
+ ainL, ainR, iimpulseindex xin
+ SimpulsePath = gSconvdbPaths[iimpulseindex]
+ aL pconvolve ainL, SimpulsePath, -1, 1
+ if (giconvdbChannels[iimpulseindex] == 2) then
+ aR pconvolve ainR, SimpulsePath, -1, 2
+ else
+ aL pconvolve ainR, SimpulsePath, -1, 1
+ endif
+ xout aL, aR
+endop
+
+
+opcode convdb_convolve, aa, aS
+ ain, Sname xin
+ impulseindex convdb_getindexbyname Sname
+ aL, aR convdb_convolve ain, impulseindex
+ xout aL, aR
+endop
+
+opcode convdb_convolve, aa, aaS
+ ainL, ainR, Sname xin
+ impulseindex convdb_getindexbyname Sname
+ aL, aR convdb_convolve ainL, ainR, impulseindex
+ xout aL, aR
+endop
+
+
+convdb_getimpulses()
+
+
+#end