#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