[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)

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

Hey Scott,

i guess it’s not the loops fault :confused:
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

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)