Csound Csound-dev Csound-tekno Search About

k-rate looping, kind of...

Date2015-12-31 12:35
FromRory Walsh
Subjectk-rate looping, kind of...
The two instruments below run through some loops and print values to screen. It seems that instr2 can complete its entire loop in a single k-cycle. I always thought k-rate variables could only be modified at k boundaries, but this is going to make life a lot easier for me! Can't believe I wasn't aware of this!     

instr 1
  p3 = ksmps/sr
  kx init 0
  if kx<=10 then
    printks sprintfk("X:%d\n",kx), 0
    kx = kx+1
  endif
endin

instr 2
  p3 = ksmps/sr
  kx init 0
  loopx:   
    cggoto (kx>10), end
    printks sprintfk("X:%d\n",kx), 0
    kx=kx+1
    cggoto (kx<=10), loopx
  end:
endin
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

Date2015-12-31 12:50
FromKevin Welsh
SubjectRe: k-rate looping, kind of...
Wow, you're right!  Even after talking about this all night, and
sending examples back and forth... I didn't really realize the full
implications of this until just now.  Tho I guess I was looking at it
from the other direction, your example really makes it clear tho.

Thanks again for the help with figuring out what was going on!


On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh  wrote:
> The two instruments below run through some loops and print values to screen.
> It seems that instr2 can complete its entire loop in a single k-cycle. I
> always thought k-rate variables could only be modified at k boundaries, but
> this is going to make life a lot easier for me! Can't believe I wasn't aware
> of this!
>
> instr 1
>   p3 = ksmps/sr
>   kx init 0
>   if kx<=10 then
>     printks sprintfk("X:%d\n",kx), 0
>     kx = kx+1
>   endif
> endin
>
> instr 2
>   p3 = ksmps/sr
>   kx init 0
>   loopx:
>     cggoto (kx>10), end
>     printks sprintfk("X:%d\n",kx), 0
>     kx=kx+1
>     cggoto (kx<=10), loopx
>   end:
> endin
> 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

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

Date2016-01-01 15:39
Fromjoachim heintz
SubjectRe: k-rate looping, kind of...
hi rory, hi kevin -

sorry, i don't get it.  what is so special in instr 2?  what is the 
difference to this version of instr 1, using a while loop?

instr 1
   p3 = ksmps/sr
   kx init 0
   while kx<=10 do
     printks sprintfk("X:%d\n",kx), 0
     kx += 1
   od
endin

best -
	joachim



On 31/12/15 13:50, Kevin Welsh wrote:
> Wow, you're right!  Even after talking about this all night, and
> sending examples back and forth... I didn't really realize the full
> implications of this until just now.  Tho I guess I was looking at it
> from the other direction, your example really makes it clear tho.
>
> Thanks again for the help with figuring out what was going on!
>
>
> On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh  wrote:
>> The two instruments below run through some loops and print values to screen.
>> It seems that instr2 can complete its entire loop in a single k-cycle. I
>> always thought k-rate variables could only be modified at k boundaries, but
>> this is going to make life a lot easier for me! Can't believe I wasn't aware
>> of this!
>>
>> instr 1
>>    p3 = ksmps/sr
>>    kx init 0
>>    if kx<=10 then
>>      printks sprintfk("X:%d\n",kx), 0
>>      kx = kx+1
>>    endif
>> endin
>>
>> instr 2
>>    p3 = ksmps/sr
>>    kx init 0
>>    loopx:
>>      cggoto (kx>10), end
>>      printks sprintfk("X:%d\n",kx), 0
>>      kx=kx+1
>>      cggoto (kx<=10), loopx
>>    end:
>> endin
>> 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
>
> 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
>

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

Date2016-01-01 17:06
FromRory Walsh
SubjectRe: k-rate looping, kind of...
No difference, and nothing particularly special about it. I just didn't think that cggoto worked that way. Don't ask me what I thought. I don't think there was much thought going on at all to be honest! Anyhow, let me take this opportunity to say happy new year to you! 

On 1 January 2016 at 15:39, joachim heintz <jh@joachimheintz.de> wrote:
hi rory, hi kevin -

sorry, i don't get it.  what is so special in instr 2?  what is the difference to this version of instr 1, using a while loop?

instr 1
  p3 = ksmps/sr
  kx init 0
  while kx<=10 do
    printks sprintfk("X:%d\n",kx), 0
    kx += 1
  od
endin

best -
        joachim




On 31/12/15 13:50, Kevin Welsh wrote:
Wow, you're right!  Even after talking about this all night, and
sending examples back and forth... I didn't really realize the full
implications of this until just now.  Tho I guess I was looking at it
from the other direction, your example really makes it clear tho.

Thanks again for the help with figuring out what was going on!


On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh <rorywalsh@ear.ie> wrote:
The two instruments below run through some loops and print values to screen.
It seems that instr2 can complete its entire loop in a single k-cycle. I
always thought k-rate variables could only be modified at k boundaries, but
this is going to make life a lot easier for me! Can't believe I wasn't aware
of this!

instr 1
   p3 = ksmps/sr
   kx init 0
   if kx<=10 then
     printks sprintfk("X:%d\n",kx), 0
     kx = kx+1
   endif
endin

instr 2
   p3 = ksmps/sr
   kx init 0
   loopx:
     cggoto (kx>10), end
     printks sprintfk("X:%d\n",kx), 0
     kx=kx+1
     cggoto (kx<=10), loopx
   end:
endin
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

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


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

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

Date2016-01-01 17:30
Fromjoachim heintz
SubjectRe: k-rate looping, kind of...
same for you, thanks!  and i'm curious to see which new cabbage receipes 
the year will bring =)

	joachim


On 01/01/16 18:06, Rory Walsh wrote:
> No difference, and nothing particularly special about it. I just didn't
> think that cggoto worked that way. Don't ask me what I thought. I don't
> think there was much thought going on at all to be honest! Anyhow, let
> me take this opportunity to say happy new year to you!
>
> On 1 January 2016 at 15:39, joachim heintz  > wrote:
>
>     hi rory, hi kevin -
>
>     sorry, i don't get it.  what is so special in instr 2?  what is the
>     difference to this version of instr 1, using a while loop?
>
>     instr 1
>        p3 = ksmps/sr
>        kx init 0
>        while kx<=10 do
>          printks sprintfk("X:%d\n",kx), 0
>          kx += 1
>        od
>     endin
>
>     best -
>              joachim
>
>
>
>
>     On 31/12/15 13:50, Kevin Welsh wrote:
>
>         Wow, you're right!  Even after talking about this all night, and
>         sending examples back and forth... I didn't really realize the full
>         implications of this until just now.  Tho I guess I was looking
>         at it
>         from the other direction, your example really makes it clear tho.
>
>         Thanks again for the help with figuring out what was going on!
>
>
>         On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh          > wrote:
>
>             The two instruments below run through some loops and print
>             values to screen.
>             It seems that instr2 can complete its entire loop in a
>             single k-cycle. I
>             always thought k-rate variables could only be modified at k
>             boundaries, but
>             this is going to make life a lot easier for me! Can't
>             believe I wasn't aware
>             of this!
>
>             instr 1
>                 p3 = ksmps/sr
>                 kx init 0
>                 if kx<=10 then
>                   printks sprintfk("X:%d\n",kx), 0
>                   kx = kx+1
>                 endif
>             endin
>
>             instr 2
>                 p3 = ksmps/sr
>                 kx init 0
>                 loopx:
>                   cggoto (kx>10), end
>                   printks sprintfk("X:%d\n",kx), 0
>                   kx=kx+1
>                   cggoto (kx<=10), loopx
>                 end:
>             endin
>             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
>
>
>         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
>
>
>     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
>
>
> 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

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

Date2016-01-02 08:52
FromKevin Welsh
SubjectRe: k-rate looping, kind of...
My specific problem was from another thread, where I was seeing more
looping than I expected.  By shortening the time, it went back to the
correct number of loops.

Rory had suggested an alternate style of looping, one that only
finishes every k-cycle... and I was seeing wildly different results.
At first we didn't understand why, but this was the root of the
difference between them.  With a very very short init time, mine would
operate normally, but his would only read a few pixels.

Here was my loop:
  kxindex init 0
  kyindex init 0
  kpasses init 0

  loopy:
    kxindex = 0
  loopx:

; this is the meat
;    printks sprintfk("counted X:%d Y:%d\n",kxindex,kyindex), 0
    kpasses = kpasses+1

    kxindex=kxindex+1
    cggoto (kxindex wrote:
> hi rory, hi kevin -
>
> sorry, i don't get it.  what is so special in instr 2?  what is the
> difference to this version of instr 1, using a while loop?
>
> instr 1
>   p3 = ksmps/sr
>   kx init 0
>   while kx<=10 do
>     printks sprintfk("X:%d\n",kx), 0
>     kx += 1
>   od
> endin
>
> best -
>         joachim
>
>
>
>
> On 31/12/15 13:50, Kevin Welsh wrote:
>>
>> Wow, you're right!  Even after talking about this all night, and
>> sending examples back and forth... I didn't really realize the full
>> implications of this until just now.  Tho I guess I was looking at it
>> from the other direction, your example really makes it clear tho.
>>
>> Thanks again for the help with figuring out what was going on!
>>
>>
>> On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh  wrote:
>>>
>>> The two instruments below run through some loops and print values to
>>> screen.
>>> It seems that instr2 can complete its entire loop in a single k-cycle. I
>>> always thought k-rate variables could only be modified at k boundaries,
>>> but
>>> this is going to make life a lot easier for me! Can't believe I wasn't
>>> aware
>>> of this!
>>>
>>> instr 1
>>>    p3 = ksmps/sr
>>>    kx init 0
>>>    if kx<=10 then
>>>      printks sprintfk("X:%d\n",kx), 0
>>>      kx = kx+1
>>>    endif
>>> endin
>>>
>>> instr 2
>>>    p3 = ksmps/sr
>>>    kx init 0
>>>    loopx:
>>>      cggoto (kx>10), end
>>>      printks sprintfk("X:%d\n",kx), 0
>>>      kx=kx+1
>>>      cggoto (kx<=10), loopx
>>>    end:
>>> endin
>>> 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
>>
>>
>> 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
>>
>
> 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

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

Date2016-01-02 11:39
Fromjoachim heintz
SubjectRe: k-rate looping, kind of...
thanks for the explanation, kevin.  i did not follow this thread.

actually i think that the if-expression which you quote is no loop at 
all.  it would become a loop if there was any "goto" statement (which is 
not, currently).

i personally prefer the style using while or until, which avoids labels, 
but this is of course a choice for everyone to decide on his/her own. 
loop_lt or cggoto do the same, in effect.

best -
	joachim


On 02/01/16 09:52, Kevin Welsh wrote:
> My specific problem was from another thread, where I was seeing more
> looping than I expected.  By shortening the time, it went back to the
> correct number of loops.
>
> Rory had suggested an alternate style of looping, one that only
> finishes every k-cycle... and I was seeing wildly different results.
> At first we didn't understand why, but this was the root of the
> difference between them.  With a very very short init time, mine would
> operate normally, but his would only read a few pixels.
>
> Here was my loop:
>    kxindex init 0
>    kyindex init 0
>    kpasses init 0
>
>    loopy:
>      kxindex = 0
>    loopx:
>
> ; this is the meat
> ;    printks sprintfk("counted X:%d Y:%d\n",kxindex,kyindex), 0
>      kpasses = kpasses+1
>
>      kxindex=kxindex+1
>      cggoto (kxindex      kyindex=kyindex+1
>      cggoto (kyindex
> chnset sprintfk("text(counted %d %d passes %d)",kxindex,kyindex,
> kpasses), "debug"
>
>
> And here is Rory's loop:
>
>    if kyindex      kxindex = (kxindex      if kxindex==0 then
>        kyindex = kyindex+1
>      endif
> ; this is the meat
> ;    printks sprintfk("counted X:%d Y:%d\n",kxindex,kyindex), 0
>    kpasses = kpasses+1
>    endif
> chnset sprintfk("text(counted %d %d passes %d)",kxindex,kyindex,
> kpasses), "debug"
>
> On Fri, Jan 1, 2016 at 10:39 AM, joachim heintz  wrote:
>> hi rory, hi kevin -
>>
>> sorry, i don't get it.  what is so special in instr 2?  what is the
>> difference to this version of instr 1, using a while loop?
>>
>> instr 1
>>    p3 = ksmps/sr
>>    kx init 0
>>    while kx<=10 do
>>      printks sprintfk("X:%d\n",kx), 0
>>      kx += 1
>>    od
>> endin
>>
>> best -
>>          joachim
>>
>>
>>
>>
>> On 31/12/15 13:50, Kevin Welsh wrote:
>>>
>>> Wow, you're right!  Even after talking about this all night, and
>>> sending examples back and forth... I didn't really realize the full
>>> implications of this until just now.  Tho I guess I was looking at it
>>> from the other direction, your example really makes it clear tho.
>>>
>>> Thanks again for the help with figuring out what was going on!
>>>
>>>
>>> On Thu, Dec 31, 2015 at 7:35 AM, Rory Walsh  wrote:
>>>>
>>>> The two instruments below run through some loops and print values to
>>>> screen.
>>>> It seems that instr2 can complete its entire loop in a single k-cycle. I
>>>> always thought k-rate variables could only be modified at k boundaries,
>>>> but
>>>> this is going to make life a lot easier for me! Can't believe I wasn't
>>>> aware
>>>> of this!
>>>>
>>>> instr 1
>>>>     p3 = ksmps/sr
>>>>     kx init 0
>>>>     if kx<=10 then
>>>>       printks sprintfk("X:%d\n",kx), 0
>>>>       kx = kx+1
>>>>     endif
>>>> endin
>>>>
>>>> instr 2
>>>>     p3 = ksmps/sr
>>>>     kx init 0
>>>>     loopx:
>>>>       cggoto (kx>10), end
>>>>       printks sprintfk("X:%d\n",kx), 0
>>>>       kx=kx+1
>>>>       cggoto (kx<=10), loopx
>>>>     end:
>>>> endin
>>>> 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
>>>
>>>
>>> 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
>>>
>>
>> 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
>
> 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
>

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

Date2016-01-02 12:09
FromRory Walsh
SubjectRe: k-rate looping, kind of...

actually i think that the if-expression which you quote is no loop at all.  it would become a loop if there was any "goto" statement (which is not, currently).

Exactly. I never used cggoto, or any of those label driven conditions. Hence I was confusing them for conditional statements rather than looping constructs, even though the name kind of gives them away.....
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