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/addsub.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/addsub.udo')
-rwxr-xr-x | site/udo/addsub.udo | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/site/udo/addsub.udo b/site/udo/addsub.udo new file mode 100755 index 0000000..b95ef0c --- /dev/null +++ b/site/udo/addsub.udo @@ -0,0 +1,170 @@ +#ifndef UDO_ADDSUB
+#define UDO_ADDSUB ##
+/*
+ Stochastic additive and subtractive instruments
+
+ This file is part of the SONICS UDO collection by Richard Knight 2024
+ License: GPL-2.0-or-later
+ http://1bpm.net
+*/
+
+
+/*
+ Subtractive synthesiser
+ Operating between ifreq and ifreqmax, this recurses with a frequency step of *ifreqstepmult*ifreqstepmultrand and amplitude multiplier iampmult with each step
+
+ aout as_subtractive asrc, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult
+
+ aout output audio
+ asrc source sound, can be noise or anything less
+ ifreq minimum frequency
+ ifreqmax maximum frequency
+ ifreqstepmult frequency multiplier for each step
+ ifreqstepmultrand frequency multiplier random for each step
+ iamp amplitude
+ iampmult amplitude multiplier random for each step
+*/
+opcode as_subtractive, a, aiiiiii
+ asrc, ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult xin
+ if (random(0, 1) >= 0.5) then
+ afreqmult linseg random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1)
+ else
+ afreqmult init 1
+ endif
+
+ if (random(0, 1) >= 0.5) then
+ istartmult = random(0.9, 1.1)
+ iendmult = random(0.9, 1.1)
+ if (random(0, 1) >= 0.5) then
+ afreqmult2 linseg istartmult, p3, iendmult
+ else
+ afreqmult2 expseg istartmult, p3, iendmult
+ endif
+ afreqmult *= afreqmult2
+ endif
+
+ aamp linseg random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9)
+
+ if (random(0, 1) >= 0.5) then
+ if (random(0, 1) >= 0.5) then
+ if (random(0, 1) >= 0.5) then
+ aamp2 linseg 1, p3, 0
+ else
+ aamp2 expseg 1, p3, 0.00001
+ endif
+ else
+ if (random(0, 1) >= 0.5) then
+ aamp2 linseg 0, p3, 1
+ else
+ aamp2 expseg 0.00001, p3, 1
+ endif
+ endif
+ aamp *= aamp2
+ endif
+
+ abw linseg random(1, 10), p3*0.1, random(1, 10), p3*0.1, \
+ random(1, 10), p3*0.1, random(1, 10), p3*0.1, \
+ random(1, 10), p3*0.1, random(1, 10), p3*0.1, \
+ random(1, 10), p3*0.1, random(1, 10), p3*0.1, \
+ random(1, 10), p3*0.1, random(1, 10)
+
+ amin init 50
+ amax init 22000
+ afreq = max:a(min:a(ifreq * afreqmult, amax), amin)
+
+ asub butterbp asrc, afreq, abw
+ asub butterbp asub, afreq, abw
+ asub balance asub, asrc
+ asub *= iamp * aamp
+
+ istep = ifreq * ifreqstepmult * random(1, ifreqstepmultrand)
+ if (istep <= ifreqmax) then
+ asubr as_subtractive asrc, istep, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp * iampmult, iampmult
+ asub += asubr
+ endif
+
+ xout asub
+endop
+
+
+/*
+ Additive synthesiser
+ Operating between ifreq and ifreqmax, this recurses with a frequency step of *ifreqstepmult*ifreqstepmultrand and amplitude multiplier iampmult with each step
+
+ aout as_additive ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult [, index=0]
+
+ aout output audio
+ ifreq minimum frequency
+ ifreqmax maximum frequency
+ ifreqstepmult frequency multiplier for each step
+ ifreqstepmultrand frequency multiplier random for each step
+ iamp amplitude
+ iampmult amplitude multiplier random for each step
+ index internal recursion tracking
+*/
+opcode as_additive, a, iiiiiio
+ ifreq, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp, iampmult, index xin
+ if (random(0, 1) >= 0.5) then
+ kfreqmult linseg random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1), p3*0.1, \
+ random(0.9, 1.1), p3*0.1, random(0.9, 1.1)
+ else
+ kfreqmult init 1
+ endif
+
+
+ kamp linseg random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9), p3*0.1, \
+ random(0.1, 0.9), p3*0.1, random(0.1, 0.9)
+
+ if (random(0, 1) >= 0.5) then
+ if (random(0, 1) >= 0.5) then
+ if (random(0, 1) >= 0.5) then
+ kamp2 linseg 1, p3, 0
+ else
+ kamp2 expseg 1, p3, 0.00001
+ endif
+ else
+ if (random(0, 1) >= 0.5) then
+ kamp2 linseg 0, p3, 1
+ else
+ kamp2 expseg 0.00001, p3, 1
+ endif
+ endif
+ kamp *= kamp2
+ endif
+
+ if (random(0, 1) >= 0.5) then
+ istartmult = random(0.9, 1.1)
+ iendmult = random(0.9, 1.1)
+ if (random(0, 1) >= 0.5) then
+ kfreqmult2 linseg istartmult, p3, iendmult
+ else
+ kfreqmult2 expseg istartmult, p3, iendmult
+ endif
+ kfreqmult *= kfreqmult2
+ endif
+
+ aosc oscil iamp * kamp, ifreq * kfreqmult
+
+ istep = ifreq * ifreqstepmult * random(1, ifreqstepmultrand)
+ if (istep <= ifreqmax && index < 256) then ; 256 max recursion guard
+ aoscr as_additive istep, ifreqmax, ifreqstepmult, ifreqstepmultrand, iamp * iampmult, iampmult, index + 1
+ aosc += aoscr
+ endif
+ xout aosc
+endop
+
+#end
|