#ifndef UDO_PVSFPROC #define UDO_PVSFPROC ## /* Full table based PVS processing, for reading a complete file to a series of frames in tables ksmps must be 64 or lower: setksmps(64) can be set in the calling instrument if required This file is part of the SONICS UDO collection by Richard Knight 2024 License: GPL-2.0-or-later http://1bpm.net */ opcode tpvf_destroy, 0, i itpvHandle xin ifnamp tab_i 2, itpvHandle ifnfreq tab_i 3, itpvHandle if (ifnamp > 0) then ftfree ifnamp, 0 endif if (ifnfreq > 0) then ftfree ifnfreq, 0 endif ftfree itpvHandle, 0 endop opcode tpvf_clone, i, i itpvHandle xin ifnamp tab_i 2, itpvHandle ifnfreq tab_i 3, itpvHandle ilen = ftlen(ifnamp) ifnampNew ftgen 0, 0, -ilen, -2, 0 ifnfreqNew ftgen 0, 0, -ilen, -2, 0 itpvHandleNew ftgen 0, 0, -5, -2, tab_i(0, itpvHandle), tab_i(1, itpvHandle), ifnampNew, ifnfreqNew, tab_i(4, itpvHandle) tableicopy ifnampNew, ifnamp tableicopy itpvHandleNew, ifnfreq xout itpvHandleNew endop opcode tpvf_tablen, i, iii ifnaudiolen, ifftsize, ifftdecimation xin xout round(ifnaudiolen / (ifftsize / ifftdecimation)) * (ifftsize / 2) endop opcode tpvf_framecount, i, i itpvHandle xin ifftsize tab_i 0, itpvHandle ifnamp tab_i 2, itpvHandle xout ftlen(ifnamp) / (ifftsize / 2) endop opcode tpvf_analyse, ki, ijj ifn, ifftsize, ifftdecimation xin istatus = 1 itpvHandle = -1 ifftsize = (ifftsize == -1) ? 512: ifftsize ifftdecimation = (ifftdecimation == -1) ? 8: ifftdecimation ifnlen = ftlen(ifn) ifnsr = ftsr(ifn) ifoutlen = tpvf_tablen(ifnlen, ifftsize, ifftdecimation) itpvHandle ftgen 0, 0, -5, -2, ifftsize, ifftdecimation, -1, -1, -1 ifnampTemp ftgentmp 0, 0, -(ifftsize / 2), -2, 0 ifnfreqTemp ftgentmp 0, 0, -(ifftsize / 2), -2, 0 ifnamp ftgen 0, 0, -ifoutlen, -2, 0 ifnfreq ftgen 0, 0, -ifoutlen, -2, 0 tabw_i ifnamp, 2, itpvHandle tabw_i ifnfreq, 3, itpvHandle tabw_i (ifnlen / ifnsr), 4, itpvHandle ikcycles = ifnlen / ksmps kcycle init 0 ktimek timeinstk if (ktimek == 1) then kwriteindex = 0 while (kcycle < ikcycles) do apos lphasor 1 asig table3 apos, ifn fsig pvsanal asig, ifftsize, ifftsize / ifftdecimation, ifftsize, 1 kready pvsftw fsig, ifnampTemp, ifnfreqTemp if (kready == 1) then kreadindex = 0 while (kreadindex < ftlen(ifnampTemp)) do tablew tab:k(kreadindex, ifnampTemp), kwriteindex, ifnamp ; overshoots write tablew tab:k(kreadindex, ifnfreqTemp), kwriteindex, ifnfreq ; overshoots write kwriteindex += 1 kreadindex += 1 od endif kcycle += 1 od else kdone = 1 endif xout kdone, itpvHandle endop opcode tpvf_resynth, aak, ijojo itpvHandle, ifnBinSelection, iuseadsyn, isplitselection, istartframe xin ifftsize tab_i 0, itpvHandle ifftdecimation tab_i 1, itpvHandle ifnamp tab_i 2, itpvHandle ifnfreq tab_i 3, itpvHandle if (ifnBinSelection > 0 && isplitselection == 1) then ibslen = ftlen(ifnBinSelection) ifnBinSelectionInverse ftgentmp 0, 0, -(ibslen), -2, 0 index = 0 while (index < ibslen) do tabw_i -(tab_i(index, ifnBinSelection)), index, ifnBinSelectionInverse index += 1 od endif ifnampTemp ftgentmp 0, 0, -(ifftsize / 2), -2, 0 ifnfreqTemp ftgentmp 0, 0, -(ifftsize / 2), -2, 0 anull init 0 aoutinverse = anull fsig pvsanal anull, ifftsize, ifftsize / ifftdecimation, ifftsize, 1 kready pvsftw fsig, ifnampTemp, ifnfreqTemp kwriteindex = 0 kreadindex init istartframe * (ifftsize / 2) if (kreadindex >= ftlen(ifnamp)) then kdone = 1 aout = anull else kdone = 0 if (kready == 1) then while (kwriteindex < (ifftsize / 2)) do tabw tab:k(kreadindex, ifnamp), kwriteindex, ifnampTemp tabw tab:k(kreadindex, ifnfreq), kwriteindex, ifnfreqTemp kreadindex += 1 kwriteindex += 1 od endif pvsftr fsig, ifnampTemp, ifnfreqTemp if (ifnBinSelection > 0) then fproc pvsmaska fsig, ifnBinSelection, 1 if (iuseadsyn == 1) then aout pvsadsyn fproc, ifftsize / 2, 1 else aout pvsynth fproc endif if (isplitselection == 1) then fprocinverse pvsmaska fsig, ifnBinSelectionInverse, 1 if (iuseadsyn == 1) then aoutinverse pvsadsyn fprocinverse, ifftsize / 2, 1 else aoutinverse pvsynth fprocinverse endif endif else if (iuseadsyn == 1) then aout pvsadsyn fsig, ifftsize / 2, 1 else aout pvsynth fsig endif endif endif xout aout, aoutinverse, kdone endop opcode tpvf_resynth, ak, ijoj itpvHandle, ifnBinSelection, iuseadsyn, istartframe xin aout, a_, kdone tpvf_resynth itpvHandle, ifnBinSelection, iuseadsyn, istartframe xout aout, kdone endop opcode tpvf_resynth_offline, ik, io itpvHandle, iuseadsyn xin ifftsize tab_i 0, itpvHandle ifftdecimation tab_i 1, itpvHandle ifnamp tab_i 2, itpvHandle ifnfreq tab_i 3, itpvHandle ifndurations tab_i 4, itpvHandle ifnout ftgen 0, 0, -(round(ifndurations * sr)), -2, 0 ikcycles = floor(ifndurations * kr) kdone = 0 ktimek timeinstk if (ktimek == 1) then kcycle = 0 while (kcycle < ikcycles) do apos lphasor 1 asig, k_ tpvf_resynth itpvHandle, -1, iuseadsyn tabw asig, apos, ifnout kcycle += 1 od else kdone = 1 endif xout ifnout, kdone endop #end