Csound Csound-dev Csound-tekno Search About

[Csnd] Recursive UDOs?

Date2009-12-26 07:51
FromGraham Breed
Subject[Csnd] Recursive UDOs?
After trying to get a fractal noise generator working, I'm
now looking at the basic problem of a recursive UDO.
Here's a simple example:

sr = 44100
ksmps = 100
nchnls = 1

opcode Recursive, i, ii
  icurr, itar xin
  cigoto (icurr >= itar), end
  icurr Recursive icurr + 1, itar
end:
  xout icurr
endop

instr 1
  icps Recursive 1, 440
  print icps
  a1 oscil 20000, icps, 1
  out a1
endin

That should run with the score for the "line" example.  The
recursion is only to count up to the target value supplied
as the second argument.  What actually happens is:

instr 1:  icps = 440.000
PERF ERROR in instr 1 (opcode Recursive): Recursive: not
initialised
icurr	Recursive	#i0
itar	0 note aborted
B  0.000 ..  2.000 T  2.000 TT  2.000 M:      0.0

The recursion's clearly working because the correct value
comes out.  But then this error stops the performance.  The
documentation says "But it is possible to call the opcode
from itself. This allows recursion of any depth that is
limited only by available memory."

http://www.csounds.com/manual/html/opcode.html

It looks like recursion can only be of infinite depth.
Otherwise, how can it be stopped without not initializing
the opcode?

I've also tried an k-rate UDO.  In that case, I get no
errors or warnings, and the orchestra cleanly segfaults.
I'll guess that it's doing infinite recursion.  I don't
know if that's supposed to happen or not.  The
documentation helpfully says:

"The opcode call is always executed both at initialization
and performance time, even if there are no a- or k-rate
arguments. If there are many user opcode calls that are
known to have no effect at performance time in an
instrument, then it may save some CPU time to jump over
groups of such opcodes with kgoto. "

That doesn't make sense.  What's the point of jumping over
the opcodes if they're always executed?  Is a kgoto
supposed to stop them being executed or not?

I'm running Csound 5.10, which may not be the latest.  (It
would help if the website gave the current version
number.)  Is there a bug that's been fixed?  Does anybody
have a strategy for recursive UDOs?


                      Graham


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-12-26 09:58
FromVictor Lazzarini
Subject[Csnd] Re: Recursive UDOs?
This example works fine as far as I know

/* example opcode 3: recursive call */

        opcode RecursiveLowpass, a, akkpp

ain, ka1, ka2, idep, icnt       xin     ; read input parameters
        if (icnt >= idep) goto skip1    ; check if max depth reached
ain     RecursiveLowpass ain, ka1, ka2, idep, icnt + 1
skip1:
aout    Lowpass ain, ka1, ka2           ; call filter
        xout aout                       ; write output

        endop
In your example, I guess the problem is that icps can only take a single value per instrument initialisation. What you want to do perhaps is to move the oscillator into the UDO and output the mixed signal. This example mixes signals:



Victor


On 26 Dec 2009, at 07:51, Graham Breed wrote:

After trying to get a fractal noise generator working, I'm
now looking at the basic problem of a recursive UDO.
Here's a simple example:

sr = 44100
ksmps = 100
nchnls = 1

opcode Recursive, i, ii
 icurr, itar xin
 cigoto (icurr >= itar), end
 icurr Recursive icurr + 1, itar
end:
 xout icurr
endop

instr 1
 icps Recursive 1, 440
 print icps
 a1 oscil 20000, icps, 1
 out a1
endin

That should run with the score for the "line" example.  The
recursion is only to count up to the target value supplied
as the second argument.  What actually happens is:

instr 1:  icps = 440.000
PERF ERROR in instr 1 (opcode Recursive): Recursive: not
initialised
icurr Recursive #i0
itar 0 note aborted
B  0.000 ..  2.000 T  2.000 TT  2.000 M:      0.0

The recursion's clearly working because the correct value
comes out.  But then this error stops the performance.  The
documentation says "But it is possible to call the opcode
from itself. This allows recursion of any depth that is
limited only by available memory."

http://www.csounds.com/manual/html/opcode.html

It looks like recursion can only be of infinite depth.
Otherwise, how can it be stopped without not initializing
the opcode?

I've also tried an k-rate UDO.  In that case, I get no
errors or warnings, and the orchestra cleanly segfaults.
I'll guess that it's doing infinite recursion.  I don't
know if that's supposed to happen or not.  The
documentation helpfully says:

"The opcode call is always executed both at initialization
and performance time, even if there are no a- or k-rate
arguments. If there are many user opcode calls that are
known to have no effect at performance time in an
instrument, then it may save some CPU time to jump over
groups of such opcodes with kgoto. "

That doesn't make sense.  What's the point of jumping over
the opcodes if they're always executed?  Is a kgoto
supposed to stop them being executed or not?

I'm running Csound 5.10, which may not be the latest.  (It
would help if the website gave the current version
number.)  Is there a bug that's been fixed?  Does anybody
have a strategy for recursive UDOs?


                     Graham


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2009-12-26 10:08
FromGraham Breed
Subject[Csnd] Re: Re: Recursive UDOs?
Victor Lazzarini  wrote:
> This example works fine as far as I know

Thanks!  What it's doing different to mine is using if ...
goto instead of cigoto.  So I change

  cigoto (icurr >= itar), end

into

  if (icurr >= itar) goto end

and it works!  I don't understand why, but I'll look at the
real example now.


                                        Graham


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"