[Csnd] krate udo recursion

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] krate udo recursion

jhearon
Hi,
I made the example more consistent with the approach shown in the manual: //http://csound.com/docs/manual/opcode.html, and not segfaulting now. 

Still not sure why return value is only 1.0?  Seems like it should return 5.0, so I still have some work to do.

Point is to have kloop in instr calling a krate udo, which is recursive, and will wait to return a kvalue to the instr until a certain value is reached.

Thanks,
Regards,
Jim

<CsoundSynthesizer>
<CsOptions>
csound -s -d -+rtaudio=ALSA -odevaudio -b1024 -B16384  
</CsOptions>
<CsInstruments>
sr = 22050 ;ksmps = sr/kr
kr = 1
0dbfs = 1
nchnls    = 2

        opcode Recursion_kRate, k, ki
k1, icnt xin
i2 = 5
print icnt
 if (icnt < i2) then
kcall  Recursion_kRate k1 + 1, icnt + 1 ;recursion
 elseif (icnt >= i2) then
printks2 "*k1*: %f\n", k1
endif
   xout k1
       endop

    instr 1
kcounter = 0
 until (kcounter == 1) do
kout Recursion_kRate 1, 1
kcounter  +=   1
 od
printks2 "--kout-- %f\n", kout
    endin

</CsInstruments>
<CsScore>
i 1 0 3
</CsScore>
</CsoundSynthesizer>

Csound mailing list [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] krate udo recursion

joachim-3
hi jim -

i think the output is correct.  you get the return calue from the FIRST
instance.  this code may show more clearly what is happening:

         opcode Recursion_kRate, k, ki
k1, icnt xin
i2 = 5
  if (icnt < i2) then
kcall  Recursion_kRate k1 + 1, icnt + 1 ;recursion
  elseif (icnt >= i2) then
endif
printks "Instance = %d, kcall = %d, k1 = %d\n", 0, icnt, kcall, k1
    xout k1
        endop

     instr 1
kout Recursion_kRate 1, 1
printks2 "--kout-- %f\n", kout
turnoff
     endin

Instance = 5, kcall = 0, k1 = 5
Instance = 4, kcall = 5, k1 = 4
Instance = 3, kcall = 4, k1 = 3
Instance = 2, kcall = 3, k1 = 2
Instance = 1, kcall = 2, k1 = 1
--kout-- 1.000000

best -
        joachim



On 13/02/18 17:14, James Hearon wrote:

> Hi,
> I made the example more consistent with the approach shown in the
> manual: //http://csound.com/docs/manual/opcode.html, and not segfaulting
> now.
>
> Still not sure why return value is only 1.0?  Seems like it should
> return 5.0, so I still have some work to do.
>
> Point is to have kloop in instr calling a krate udo, which is recursive,
> and will wait to return a kvalue to the instr until a certain value is
> reached.
>
> Thanks,
> Regards,
> Jim
>
> <CsoundSynthesizer>
> <CsOptions>
> csound -s -d -+rtaudio=ALSA -odevaudio -b1024 -B16384
> </CsOptions>
> <CsInstruments>
> sr = 22050 ;ksmps = sr/kr
> kr = 1
> 0dbfs = 1
> nchnls    = 2
>
>         opcode Recursion_kRate, k, ki
> k1, icnt xin
> i2 = 5
> print icnt
>  if (icnt < i2) then
> kcall  Recursion_kRate k1 + 1, icnt + 1 ;recursion
>  elseif (icnt >= i2) then
> printks2 "*k1*: %f\n", k1
> endif
>    xout k1
>        endop
>
>     instr 1
> kcounter = 0
>  until (kcounter == 1) do
> kout Recursion_kRate 1, 1
> kcounter  +=   1
>  od
> printks2 "--kout-- %f\n", kout
>     endin
>
> </CsInstruments>
> <CsScore>
> i 1 0 3
> </CsScore>
> </CsoundSynthesizer>
>
> Csound mailing list [hidden email]
> <mailto:[hidden email]>
> 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

Csound mailing list
[hidden email]
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