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/fx_autoglitch.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/fx_autoglitch.udo')
-rwxr-xr-x | site/udo/fx_autoglitch.udo | 470 |
1 files changed, 470 insertions, 0 deletions
diff --git a/site/udo/fx_autoglitch.udo b/site/udo/fx_autoglitch.udo new file mode 100755 index 0000000..163110c --- /dev/null +++ b/site/udo/fx_autoglitch.udo @@ -0,0 +1,470 @@ +#ifndef UDO_FXAUTOGLITCH
+#define UDO_FXAUTOGLITCH ##
+/*
+ Autoglitch effects
+
+ This file is part of the SONICS UDO collection by Richard Knight 2022, 2024, 2025
+ License: GPL-2.0-or-later
+ http://1bpm.net
+*/
+
+#include "pvs_tabproc.udo"
+#include "wavetables.udo"
+
+#ifndef AUTOGLITCH_WINSIZE
+#define AUTOGLITCH_WINSIZE #4410#
+#end
+
+#ifndef AUTOGLITCH_WINRAND
+#define AUTOGLITCH_WINRAND #441#
+#end
+
+
+/*
+ Internal autoglitch UDO for actual audio processing
+
+ aout _fx_autoglitch_audio ain, awritepos, areadpos, ibuflensamps, kdo_distortion, kdist, kporttime, kdo_ampchange, kamp, kreadmode
+
+ aout audio output
+ ain audio input
+ awritepos write position for sampler in samples
+ areadpos read position in samples
+ ibuflensamps length of buffer to be created in samples
+ kdo_distortion apply distortion
+ kdist distortion amount
+ kporttime portamento time
+ kdo_ampchange apply amplitude change
+ kamp amplitude
+ kreadmode read mode: 0 = direct table; 1 = sndwarp; 2 = mincer
+*/
+opcode _fx_autoglitch_audio, a, aaaikkkkkk
+ ain, awritepos, areadpos, ibuflensamps, kdo_distortion, kdist, kporttime, kdo_ampchange, kamp, kreadmode xin
+ ibuffer = ftgentmp(0, 0, -ibuflensamps, -2, 0)
+
+ tablew ain, awritepos, ibuffer
+
+ if (kreadmode == 0) then
+ asig table areadpos, ibuffer
+ elseif (kreadmode == 1) then
+ asig sndwarp 1, areadpos / sr, 1, ibuffer, 0, $AUTOGLITCH_WINSIZE, $AUTOGLITCH_WINRAND, 4, gifnHalfSine, 1
+ elseif (kreadmode == 2) then
+ asig mincer areadpos / sr, 1, 1, ibuffer, 1
+ endif
+
+ asig butterhp dcblock(asig), 70
+
+ if (kdo_distortion == 1 && kdist > 1) then
+ asigd distort asig, portk(kdist, kporttime), gifnSquare
+ asig balance asigd, asig
+ endif
+
+ if (kdo_ampchange == 1) then
+ asig *= portk(kamp, kporttime)
+ endif
+
+ asig butterhp dcblock(asig), 100
+ xout asig
+endop
+
+
+/*
+ Internal autoglitch UDO for control
+
+ awritepos, areadpos, ibuflensamps, kamp, kdist _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+
+ awritepos write position for sampler in samples
+ areadpos read position in samples
+ ibuflensamps length of buffer to be created in samples
+ kamp amplitude
+ kdist distortion amount
+ kminratio minimum ratio of sound length to use (0 to 1)
+ kchangerate rate of change in Hz
+ kchangechance chance of changing at change rate (0 to 1)
+ kporttime portamento time in seconds
+ ibuflens required buffer length in seconds
+
+*/
+opcode _fx_autoglitch_control, aaikk, kkkki
+ kminratio, kchangerate, kchangechance, kporttime, ibuflens xin
+
+ kminratio = (kminratio == -1) ? 0.2 : kminratio
+ kchangerate = (kchangerate == -1) ? 0.1 : kchangerate
+ kchangechance = (kchangechance == -1) ? 0.8 : kchangechance
+ kporttime = (kporttime == -1) ? 0.2 : kporttime
+ ibuflens = (ibuflens == -1) ? 2 : ibuflens
+
+ ibuflensamps = sr * ibuflens
+ awritepos lphasor 1, 0, ibuflensamps, 1 ; ,3
+
+ kdist init 0
+ klen init random(256, ibuflensamps * 0.5)
+ kstart init random(0, ibuflensamps * 0.5)
+ kreverse init 0
+ kamp init 0
+
+ kcps = ibuflensamps / klen
+ if (kreverse == 1) then
+ kcps = 0 - kcps
+ endif
+
+ areadindex phasor kcps
+ areadpos = ((areadindex * ibuflensamps) + portk(kstart, kporttime))
+
+ kchanger metro kchangerate
+ if (kchanger == 1 && random:k(0, 1) < kchangechance) then
+ klen = random:k(50, ibuflensamps * kminratio)
+ kstart = random:k(0, ibuflensamps - klen)
+ endif
+
+ if (kchanger == 1 && random:k(0, 1) < kchangechance) then
+ kreverse = round:k(random:k(0, 1))
+ endif
+
+ if (kchanger == 1 && random:k(0, 1) < kchangechance) then
+ kdist = random:k(0, 2)
+ endif
+
+ if (kchanger == 1 && random:k(0, 1) < kchangechance) then
+ kamp = round:k(random:k(0, 1))
+ endif
+
+ xout awritepos, areadpos, ibuflensamps, kamp, kdist
+endop
+
+
+
+/*
+ Mono in, mono out autoglitch
+
+ aout fx_autoglitch ain, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode
+
+ aout audio output
+ ain audio input
+ kminratio minimum ratio of sound length to use (0 to 1)
+ kchangerate rate of change in Hz
+ kchangechance chance of changing at change rate (0 to 1)
+ kporttime portamento time in seconds
+ kdo_distortion apply distortion
+ kdo_ampchange apply amplitude change
+ ibuflens required buffer length in seconds
+ kreadmode read mode: 0 = direct table; 1 = sndwarp; 2 = mincer
+
+*/
+opcode fx_autoglitch, a, aJJJJOOjO
+ ain, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode xin
+
+ awritepos, areadpos, ibuflensamps, kamp, kdist _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ aout _fx_autoglitch_audio ain, awritepos, areadpos, ibuflensamps, kdo_distortion, kdist, kporttime, kdo_ampchange, kamp, kreadmode
+ xout aout
+endop
+
+
+/*
+ Mono in, stereo out autoglitch
+
+ aoutL, aoutR fx_autoglitch ain, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode
+
+ aoutL left audio output
+ aoutR right audio output
+ ain audio input
+ kminratio minimum ratio of sound length to use (0 to 1)
+ kchangerate rate of change in Hz
+ kchangechance chance of changing at change rate (0 to 1)
+ kporttime portamento time in seconds
+ kdo_distortion apply distortion
+ kdo_ampchange apply amplitude change
+ ibuflens required buffer length in seconds
+ kreadmode read mode: 0 = direct table; 1 = sndwarp; 2 = mincer
+
+*/
+opcode fx_autoglitch, aa, aJJJJOOjO
+ ain, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, kreadmode xin
+
+ awriteposL, areadposL, ibuflensamps, kampL, kdistL _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ awriteposR, areadposR, ibuflensamps, kampR, kdistR _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ aL _fx_autoglitch_audio ain, awriteposL, areadposL, ibuflensamps, kdo_distortion, kdistL, kporttime, kdo_ampchange, kampL, kreadmode
+ aR _fx_autoglitch_audio ain, awriteposR, areadposR, ibuflensamps, kdo_distortion, kdistR, kporttime, kdo_ampchange, kampR, kreadmode
+ xout aL, aR
+endop
+
+
+/*
+ Stereo in, stereo out autoglitch
+
+ aoutL, aoutR fx_autoglitch ainL, ainR, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, istereounique, kreadmode
+
+ aoutL left audio output
+ aoutR right audio output
+ ainL left audio input
+ ainR right audio input
+ kminratio minimum ratio of sound length to use (0 to 1)
+ kchangerate rate of change in Hz
+ kchangechance chance of changing at change rate (0 to 1)
+ kporttime portamento time in seconds
+ kdo_distortion apply distortion
+ kdo_ampchange apply amplitude change
+ ibuflens required buffer length in seconds
+ istereounique stereo mode: 0 = left and right read the same positions from buffers; 1 = left and right are unique
+ kreadmode read mode: 0 = direct table; 1 = sndwarp; 2 = mincer
+
+*/
+opcode fx_autoglitch, aa, aaJJJJOOjjO
+ aL, aR, kminratio, kchangerate, kchangechance, kporttime, kdo_distortion, kdo_ampchange, ibuflens, istereounique, kreadmode xin
+
+ if (istereounique == 1) then
+ awriteposL, areadposL, ibuflensamps, kampL, kdistL _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ awriteposR, areadposR, ibuflensamps, kampR, kdistR _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ aL _fx_autoglitch_audio aL, awriteposL, areadposL, ibuflensamps, kdo_distortion, kdistL, kporttime, kdo_ampchange, kampL, kreadmode
+ aR _fx_autoglitch_audio aR, awriteposR, areadposR, ibuflensamps, kdo_distortion, kdistR, kporttime, kdo_ampchange, kampR, kreadmode
+ else
+ awritepos, areadpos, ibuflensamps, kamp, kdist _fx_autoglitch_control kminratio, kchangerate, kchangechance, kporttime, ibuflens
+ aL _fx_autoglitch_audio aL, awritepos, areadpos, ibuflensamps, kdo_distortion, kdist, kporttime, kdo_ampchange, kamp, kreadmode
+ aR _fx_autoglitch_audio aR, awritepos, areadpos, ibuflensamps, kdo_distortion, kdist, kporttime, kdo_ampchange, kamp, kreadmode
+ endif
+
+ xout aL, aR
+endop
+
+
+
+/*
+ Spectral processing autoglitch
+
+ aout fx_spectralautoglitch ain, kchangerate, kchangechance, kdo_pitchalter, kporttime
+
+ aout audio output
+ ain audio input
+ kchangerate rate of change in Hz
+ kchangechance chance of changing at change rate (0 to 1)
+ kdo_pitchalter apply pitch alterations
+ kporttime portamento time in seconds
+ ifftsize fft size
+
+*/
+opcode fx_spectralautoglitch, a, akkkkj
+ ainput, kchangerate, kchangechance, kdo_pitchalter, kporttime, ifftsize xin
+
+ kdo_freeze init 0
+ kdo_average init 0
+ kdo_scramble init 0
+ kdo_scale init 0
+ kdo_shift init 0
+ kdo_blur init 0
+ kdo_delay init 0
+ kdo_bubble init 0
+ kdo_wrap init 0
+
+ kbubblechance init 0
+ kbubblestereo init 0
+ kwrapamp init 0
+ kwrapfreq init 0
+ kfreezetime init 0
+ kaveragetime init 0
+ kscale init 1
+ kshift init 0
+ kblur init 0
+ kdelaytime init 0
+ ktime init 0
+ kpos init 0
+
+ ilength = random(1, 4)
+ ir = (ifftsize == -1) ? 512 : ifftsize
+
+ finput pvsanal ainput, ir, ir/4, ir, 1
+
+ ibuffer, ktime pvsbuffer finput, ilength
+ kchange changed kpos
+ aphasor, asyncout syncphasor a(portk(ktime, kporttime) * ilength), a(kchange)
+ kphasor = k(aphasor) + (portk(kpos, kporttime) * ilength)
+ floop pvsbufread kphasor, ibuffer
+
+
+ kchanger metro kchangerate
+ if (kchanger == 1) then
+ if (random:k(0, 1) < kchangechance) then
+ ktime = random:k(0, 1)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kpos = random:k(0, 1)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kfreezetime = round:k(random:k(0, 20))
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_freeze = 1 - kdo_freeze
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kaveragetime = random:k(0, 10)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_average = 1 - kdo_average
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_scramble = 1 - kdo_scramble
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_bubble = 1 - kdo_bubble
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kbubblechance = random:k(0, 1)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kbubblestereo = round:k(random:k(0, 1))
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_wrap = 1 - kdo_wrap
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kwrapamp = round:k(random:k(0, ir / 2))
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kwrapfreq = round:k(random:k(0, ir / 2))
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kscale = random:k(0.5, 2)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_scale = 1 - kdo_scale
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kshift = random:k(-500, 100)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_shift = 1 - kdo_shift
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kblur = random:k(0, 1)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_blur = 1 - kdo_blur
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdelaytime = random:k(2, 1000)
+ endif
+
+ if (random:k(0, 1) < kchangechance) then
+ kdo_delay = 1 - kdo_delay
+ endif
+
+ endif
+
+ kready, itpv tpv_anal floop
+
+ if (kdo_scramble == 1) then
+ tpv_scramble kready, itpv, 4
+ endif
+
+ if (kdo_freeze == 1) then
+ tpv_freeze1 kready, itpv, portk(kfreezetime, kporttime)
+ endif
+
+ if (kdo_average == 1) then
+ tpv_average kready, itpv, portk(kaveragetime, kporttime)
+ endif
+
+ if (kdo_bubble == 1) then
+ tpv_bubble kready, itpv, kbubblechance, kbubblestereo
+ endif
+
+ if (kdo_wrap == 1) then
+ tpv_wrap kready, itpv, kwrapamp, kwrapfreq
+ endif
+
+ floop tpv_resynth itpv, floop
+
+ if (kdo_blur == 1) then
+ ;floop pvsblur floop, portk(kblur, kporttime), 1
+ endif
+
+ if (kdo_pitchalter == 1 && kdo_scale == 1) then
+ floop pvscale floop, portk(kscale, kporttime)
+ endif
+
+ if (kdo_pitchalter == 1 && kdo_shift == 1) then
+ floop pvshift floop, portk(kshift, kporttime), 150
+ endif
+
+ aout pvsynth floop
+
+ if (kdo_delay == 1) then
+ kdtime = (kdo_pitchalter == 1) ? portk(kdelaytime, kporttime) : kdelaytime
+ aout vdelay aout, kdtime, 1000
+ endif
+
+ xout aout * 2.5 ; is quieter
+endop
+
+
+
+/*
+ Retrigger glitcher
+
+ aout fx_retrigglitch ifn, ktriglen, areadpos[, kpitchratio=1, kapplywindowing=1, kwinfn=gifnHanning]
+
+ aout audio output
+ ifn input audio ftable (mono)
+ ktriglen retrigger length in seconds
+ areadpos read position in seconds; -1 is set randomly upon each retrigger
+ kpitchratio resample ratio; 1 = normal pitch
+ kapplywindowing amplitude enveloping: 0 = none; 1 = apply Hanning window to output
+ kwinfn window function table
+*/
+opcode fx_retrigglitch, a, ikaPPJ
+ ifn, ktriglen, areadpos, kpitchratio, kapplywindowing, kwinfn xin
+ ifnsr = ftsr(ifn)
+ ifnlen = ftlen(ifn)
+ ifnlens = ifnlen / ifnsr
+
+ kfreq = 1 / ktriglen
+ ktrig metro kfreq
+
+ if (ktrig == 1 && k(areadpos) == -1) then
+ kstart random 0, ifnlens - ktriglen
+ areadpos = a(kstart)
+ endif
+
+ areadpos = areadpos / ifnlens
+ irate = 1 / ifnlens
+ areadpos samphold areadpos, ktrig
+ async upsamp ktrig
+ apos, a_ syncphasor irate * kpitchratio, async
+ apos += areadpos
+ apos *= ifnlen
+
+ aout tablei apos, ifn
+ ;aout, a_ mincer (apos / ifnlen) * ifnlens, 1, kpitchratio, ifn, 1
+
+ if (kapplywindowing == 1) then
+ if (kwinfn == -1) then
+ kwinfn = gifnHanning
+ endif
+ aenv oscilikt 1, kfreq, kwinfn
+ aout *= aenv
+ endif
+
+ aout dcblock aout
+ xout aout
+endop
+
+
+#end
+
|