diff options
author | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
---|---|---|
committer | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
commit | 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 (patch) | |
tree | 291bd79ce340e67affa755a8a6b4f6a83cce93ea /site/udo/convolutiondb.udo | |
download | apps.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/convolutiondb.udo')
-rwxr-xr-x | site/udo/convolutiondb.udo | 110 |
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
|