[Csnd] using macros in a loop inside a udo
Date | 2024-03-31 16:38 |
From | Philipp Neumann |
Subject | [Csnd] using macros in a loop inside a udo |
Hello everybody. i want to create a flexible udo design for using audio arrays as input. especially i want to dynamically sum the signals for the output array. in more detail: i have a udo which gets a audio array of size N as input. inside the udo i create a output array of size N. i #define a macro with the soundmodifications, which then should be called i a loop of N iterations. i this way i want to automatically sum the signals for the output. the problem is, i only get one iteration of the loop. so i guess the loop idea is not working and i should use recursion…. but i can’t figure out right now how this can be done with the macro. maybe someone can help. opcode arr_delay,a[],a[]kkk aIn[],kTime,kFdbk,kLevel xin setksmps 1 iArrayLength = lenarray(aIn) aOut[] init iArrayLength iCount init 0 #define DELAY(In'Time'Fdbk'Level'N'Out) # aIn$N = $In aDump$N delayr 5 aDelOut$N deltap $Time delayw aIn$N+(aDelOut$N*$Fdbk) aDelOut$N *= $Level $Out = aDelOut$N # ;; loop: ;; $DELAY(aIn[iCount]'kTime'kFdbk'kLevel'iCount'aOut[iCount]) ;; loop_lt iCount,1,iArrayLength-1,loop if iCount < iArrayLength then $DELAY(aIn[iCount]'kTime'kFdbk'kLevel'iCount'aOut[iCount]) iCount += 1 endif aOut = (aOut/2)+(aIn/2) xout aOut endop Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2024-03-31 21:59 |
From | ST Music |
Subject | Re: [Csnd] using macros in a loop inside a udo |
Hi Philipp, not sure exactly how to fix the overall concept (not familiar with macros and rarely use audio arrays) but I think the if loop will only run once as it's i time so it only calls the macro once (if you put "print iCount" in the macro you can see it runs only once). A while/until loop will run multiple iterations (it does print iCount iArrayLength times) but not sure that helps in the long run. Curious to know if you find a solution though, hopefully someone else can be more helpful. Best, Scott On Sun, Mar 31, 2024, 11:38 a.m. Philipp Neumann <philipp@von-neumann.com> wrote: Hello everybody. |
Date | 2024-04-02 08:43 |
From | Philipp Neumann |
Subject | Re: [Csnd] using macros in a loop inside a udo |
Hey Scott, i guess it’s not the loops fault :/ My guess is that you can’t do a text replacement, and this is what the macro is doing, in a loop. better: you just copy the text there for once. I guess the macro is replaced in the preprocessor and it has something to do how the text is inserted there. But i really like working with macros now. This is my first time using this and it makes the code much cleaner. But maybe someone else can comment this? Philipp > Am 31.03.2024 um 22:59 schrieb ST Music |
Date | 2024-04-02 21:44 |
From | joachim heintz |
Subject | Re: [Csnd] using macros in a loop inside a udo |
hi philipp - at first, i must confess that i don't like macros in csound code, unless very restricted cases. so if you like them, i am not a good partner in communication ... =) but i am wondering: why don't you use another UDO for what you write as macro? instead of #define DELAY(In'Time'Fdbk'Level'N'Out) # aIn$N = $In aDump$N delayr 5 aDelOut$N deltap $Time delayw aIn$N+(aDelOut$N*$Fdbk) aDelOut$N *= $Level $Out = aDelOut$N # you can write something like opcode myDelay,a,k... and you can call / use this UDO inside your arr_delay UDO. i recently improved (i hope ...) example 03G09 in the floss manual about recursive UDOs. it is in the development version; in case you don't know it yet: https://csound-floss-dev.firebaseapp.com/csound-language/user-defined-opcodes#recursive-user-defined-opcodes ciao - joachim On 02/04/2024 09:43, Philipp Neumann wrote: > Hey Scott, > > i guess it’s not the loops fault :/ > My guess is that you can’t do a text replacement, and this is what the macro is doing, in a loop. better: you just copy the text there for once. > I guess the macro is replaced in the preprocessor and it has something to do how the text is inserted there. > > But i really like working with macros now. This is my first time using this and it makes the code much cleaner. > > But maybe someone else can comment this? > > Philipp > >> Am 31.03.2024 um 22:59 schrieb ST Music |