From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/udo/spectral_sampler.udo | 126 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 site/udo/spectral_sampler.udo (limited to 'site/udo/spectral_sampler.udo') diff --git a/site/udo/spectral_sampler.udo b/site/udo/spectral_sampler.udo new file mode 100755 index 0000000..04f1f4d --- /dev/null +++ b/site/udo/spectral_sampler.udo @@ -0,0 +1,126 @@ +#ifndef UDO_SPECTRALSAMPLER +#define UDO_SPECTRALSAMPLER ## +/* + Spectral sampler + + This file is part of the SONICS UDO collection by Richard Knight 2021 + License: GPL-2.0-or-later + http://1bpm.net +*/ + + +/* + ; pvs buffer handle and length storage +gipvsBuffers[] init 8 +gipvsBufferLengths[] init lenarray(gipvsBuffers) + +; record to a spectral sampling buffer +; ibuffer spectralsamplerecord ain, iduration, ifftsize +opcode spectralsamplerrecord, i, aio + ain, iduration, ifftsize xin + if (ifftsize == 0) then + ifftsize = 1024 + endif + kamp linseg 0, iduration * 0.01, 1, iduration * 0.98, 1, iduration * 0.01, 0 + ain1 = ain * kamp + ilength = iduration + (ifftsize / sr) + fanal pvsanal ain1, ifftsize, ifftsize/4, ifftsize, 1 + ibuffer, ktim pvsbuffer fanal, ilength + xout ibuffer +endop + + +; play back from a spectral sampling buffer +; aL, aR spectralsamplerplay ibuffer, ilength, ktime, kpos +opcode spectralsamplerplay, aa, iikk + ibuffer, ilength, ktime, kpos xin + kchange changed kpos + aphasor, asyncout syncphasor a(ktime * ilength), a(kchange) + kphasor = k(aphasor) + (kpos * ilength) + fL pvsbufread kphasor, ibuffer + fR pvsbufread kphasor*0.95, ibuffer + aL pvsynth fL + aR pvsynth fR + xout aL, aR +endop + + +*/ +; ABOVE ARE LEGACY AND TO BE DEPRECATED + + +/* + Spectral sampling and playback + + Can't sub-opcode the f in the a for some reason, doesn't work - so some duplication here +*/ + +opcode spectralsampler, f, fkkio + fanal, ktime, kpos, ilength, icontinuous xin + + ksampling init 1 + if (icontinuous == 1 || ksampling == 1) then + ibuffer, ktime pvsbuffer fanal, ilength + if (icontinuous == 0 && timeinsts() >= ilength) then + ksampling = 0 + endif + endif + + kchange changed kpos + aphasor, asyncout syncphasor a(ktime * ilength), a(kchange) + kphasor = k(aphasor) + (kpos * ilength) + fread pvsbufread kphasor, ibuffer + xout fread +endop + + + +opcode spectralsampler, a, akkioo + ain, ktime, kpos, ilength, ifftsize, icontinuous xin + + ifftsize = (ifftsize == 0) ? 1024 : ifftsize + ksampling init 1 + if (icontinuous == 1 || ksampling == 1) then + fanal pvsanal ain, ifftsize, ifftsize/4, ifftsize, 1 + ibuffer, ktime pvsbuffer fanal, ilength + if (icontinuous == 0 && timeinsts() >= ilength) then + ksampling = 0 + endif + endif + + kchange changed kpos + aphasor, asyncout syncphasor a(ktime * ilength), a(kchange) + kphasor = k(aphasor) + (kpos * ilength) + fread pvsbufread kphasor, ibuffer + aout pvsynth fread + xout aout +endop + + + +opcode spectralsampler, aa, aakkioo + ainL, ainR, ktime, kpos, ilength, ifftsize, icontinuous xin + + ifftsize = (ifftsize == 0) ? 1024 : ifftsize + ksampling init 1 + if (icontinuous == 1 || ksampling == 1) then + fanalL pvsanal ainL, ifftsize, ifftsize/4, ifftsize, 1 + fanalR pvsanal ainR, ifftsize, ifftsize/4, ifftsize, 1 + ibufferL, ktime pvsbuffer fanalL, ilength + ibufferR, ktime pvsbuffer fanalR, ilength + if (icontinuous == 0 && timeinsts() >= ilength) then + ksampling = 0 + endif + endif + + kchange changed kpos + aphasor, asyncout syncphasor a(ktime * ilength), a(kchange) + kphasor = k(aphasor) + (kpos * ilength) + freadL pvsbufread kphasor, ibufferL + freadR pvsbufread kphasor, ibufferR + aoutL pvsynth freadL + aoutR pvsynth freadR + xout aoutL, aoutR +endop + +#end -- cgit v1.2.3