From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/udo/tab2wav.udo | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 site/udo/tab2wav.udo (limited to 'site/udo/tab2wav.udo') diff --git a/site/udo/tab2wav.udo b/site/udo/tab2wav.udo new file mode 100755 index 0000000..1c0b9cb --- /dev/null +++ b/site/udo/tab2wav.udo @@ -0,0 +1,151 @@ +#ifndef UDO_TAB2WAV +#define UDO_TAB2WAV ## + +/* + Table to wave to table file ease tool + + This file is part of the SONICS UDO collection by Richard Knight 2023 + License: GPL-2.0-or-later + http://1bpm.net +*/ + + +/* + Output table to 16bit WAV file + + kdone tab2wav ifn, Spath [, ilen, iprocrate, iblocksize] + + kdone trigger to specify when done + ifn table number to use + Spath file path to output to + isamples how many samples to save, defaults to full length + iprocrate processing rate in processes per second, defaults to 10 + iblocksize block size in one process cycle, defaults to 2048 +*/ +opcode tab2wav, k, iSjjj + ifn, Spath, isamples, iprocrate, iblocksize xin + + iprocrate = (iprocrate == -1) ? 10 : iprocrate + iblocksize = (iblocksize == -1) ? 2048 : iblocksize + + ichannels = ftchnls(ifn) + isr = ftsr(ifn) + ilenraw = (isamples == -1) ? ftlen(ifn) : isamples + ilen = ilenraw / ichannels + + kdone init 0 + + + if (kdone == 0) then + ; each block processing at iprocrate + ktrig metro iprocrate + if (ktrig == 1) then + kcount = 0 + while (kcount < iblocksize) do + apos = round:a(lphasor(isr / sr)) ; rounded to deal with stereo offset if required + + ; if complete, set kdone + if (downsamp(apos) >= ilen) then + kdone = 1 + kgoto complete + endif + + ; read and write position calcs for stereo / reverse + aposbase = apos * ichannels + aposrL = aposbase + aposrR = aposbase + 1 + + if (ichannels == 2) then + fout Spath, 14, table:a(aposrL, ifn), table:a(aposrR, ifn) + else + fout Spath, 14, table:a(aposrL, ifn) + endif + kcount += 1 + od + endif + + endif + +complete: + xout kdone +endop + + + + +/* + Load file to existing table without altering length/channels + + kdone wav2tab Spath, ifn [, imonochannel=0] + + kdone trigger to specify when done + Spath file path to load from + ifn table number to use + imonochannel if ifn is mono and Spath is stereo, 1 specifies to load from the right channel, rather than the default (0) which is left + iprocrate processing rate in processes per second, defaults to 10 + iblocksize block size in one process cycle, defaults to 2048 +*/ +opcode wav2tab, k, Siojj + Spath, ifn, imonochannel, iprocrate, iblocksize xin + iprocrate = (iprocrate == -1) ? 10 : iprocrate + iblocksize = (iblocksize == -1) ? 2048 : iblocksize + + ifilechannels = filenchnls(Spath) + ichannels = ftchnls(ifn) + isr = ftsr(ifn) + ilenraw = ftlen(ifn) + ilen = ilenraw / ichannels + + kdone init 0 + + + if (kdone == 0) then + ; each block processing at iprocrate + ktrig metro iprocrate + if (ktrig == 1) then + kcount = 0 + while (kcount < iblocksize) do + apos = round:a(lphasor(isr / sr)) ; rounded to deal with stereo offset if required + + ; if complete, set kdone + if (downsamp(apos) >= ilen) then + kdone = 1 + kgoto complete + endif + + if (ifilechannels == 2) then + aL, aR diskin Spath, 1 + else + aL diskin Spath, 1 + aR = aL + endif + + ; read and write position calcs for stereo / reverse + aposbase = apos * ichannels + aposwL = aposbase + aposwR = aposbase + 1 + + + if (ichannels == 2) then + tablew aL, aposwL, ifn + tablew aR, aposwR, ifn + else + if (imonochannel == 1 && ifilechannels == 2) then + tablew aR, aposwL, ifn + else + tablew aL, aposwL, ifn + endif + endif + kcount += 1 + od + endif + + endif + +complete: + xout kdone +endop + + +#end + -- cgit v1.2.3