LISTSERV mailing list manager LISTSERV 16.5

Help for CSOUND Archives


CSOUND Archives

CSOUND Archives


CSOUND@LISTSERV.HEANET.IE


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

CSOUND Home

CSOUND Home

CSOUND  January 2016

CSOUND January 2016

Subject:

Re: no looping

From:

Steven Yi <[log in to unmask]>

Reply-To:

A discussion list for users of Csound <[log in to unmask]>

Date:

Mon, 25 Jan 2016 11:42:13 -0500

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (429 lines)

Hi Thorin,

Thanks for sharing that. I still prefer to avoid gotos/labels myself,
but the posted code is certainly clear to me and I can see why you'd
prefer that style too.  Like you said, different tastes. :)

One thing about the example is that it makes me think we should look
at implementing a few functional programming approaches to array/list
processing (particularly an apply operator, in-line lambdas as UDO's,
a more generic map opcode).  That might simplify the event generation
code there.  Something to think about for CS7.

steven



On Fri, Jan 22, 2016 at 12:26 AM, thorin kerr <[log in to unmask]> wrote:
> OK, while I'm here, I'll share some code... it mixes all of the above, and
> has a ckgoto
>
> I'm not being argumentative. It really is just a matter of taste. I just
> felt like an excuse to share some code.
>
> opcode chordal, 0, k[]k[]opO
> ;quick chords. koriginal holds the pfields on an event. (limit of 10
> pfields)
> ;koriginal is an array, holding pfields for an event
> ;kintervals specifies concurrant pitches with that event.
> ;idur specifies durations of the new events
> ;iampfac is a multiplier for p4 (assumed to be amplitude)
> ;uses cpstun for pitches, with scale specified by kscale (defaults to
> gi_CurrentScale)
> koriginal[],kintervals[],idur,iampfac,kscale xin
>   kndx      init      0
>   konce     init      0
>
>   ckgoto    (konce == 1), terminate     ; one pass
>
>   kscale    =  (kscale == 0 ? gi_CurrentScale : kscale)
>   kpitval init 0
>   ilen lenarray kintervals
>   iplen lenarray koriginal
>
>   kdur    =  (idur == 0 ? koriginal[2] : idur)
>
>   until     (kndx >= ilen) do
>     kpitval   =  koriginal[4] + kintervals[kndx]
>     if (iplen == 5) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale)
>     elseif (iplen == 6) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale), koriginal[5]
>     elseif (iplen == 7) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale), koriginal[5], koriginal[6]
>     elseif (iplen == 8) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale), koriginal[5], koriginal[6],
> koriginal[7]
>     elseif (iplen == 9) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale), koriginal[5], koriginal[6],
> koriginal[7], koriginal[8]
>     elseif (iplen == 10) then
>       event     "i", koriginal[0], tempodur_k(koriginal[1]),
> tempodur_k(kdur), koriginal[3]*iampfac,\
>                       cpstun(1,kpitval,kscale), koriginal[5], koriginal[6],
> koriginal[7], koriginal[8], koriginal[9]
>     endif
>
>   kndx      +=        1
>   od
>
>   konce = 1
>   terminate:
> endop
>
>
> ;Can be used in an instrument like this. Fires instrument 1 chords, every 2
> seconds.
>
> instr 10
>
> chordal array(1, 0, 2, 0.5, 0), array(0,2,4,8,10, -7, -14)
>
> schedule p1, 2, 1, p4 + 1
> turnoff
> endin
>
> instr 1
> ares fmrhode p4, p5, 3, 2, 0.3, 3, -1, -1, -1, -1, -1
> outs ares, ares
> endin
>
>
>
>
> On Fri, Jan 22, 2016 at 2:07 PM, Steven Yi <[log in to unmask]> wrote:
>>
>> I don't really think of Csound as being all that peculiar. ;)
>>
>> For my own code, I tend to use init-time code (e.g., use event_i
>> instead of event) and turnoff rather than do a single k-rate pass.
>> Even then, you could use turnoff at perf-time for an early exit with a
>> conditional block:
>>
>> kcount init 0
>> if (kcount == 1) then
>>   turnoff  ;; early exit, done on 2nd k-pass
>> endif
>>
>> ... krate stuff ...
>> kcount += 1
>>
>> For example, this instrument:
>>
>> instr 1
>> kcount init 0
>>
>> printk2 kcount
>>
>> if (kcount == 1) then
>>   turnoff
>> endif
>> kcount += 1
>> printk2 kcount, 2
>>
>> endin
>>
>> produces:
>>
>>  i1     0.00000
>>  i1       1.00000
>>  i1     1.00000
>>
>> before it exits. I personally think the if-statement is a bit clearer
>> on the intention of the code than the ckgoto version.  It's a little
>> more verbose but removes the use of a label to look for and keep track
>> of, which is worth the trade off for my tastes.
>>
>>
>>
>> On Thu, Jan 21, 2016 at 10:15 PM, thorin kerr <[log in to unmask]>
>> wrote:
>> > Yes.... but.... Csound is peculiar.
>> > For example, I use ckgoto a lot to do stuff on a single control pass,
>> > which
>> > I think is more useful than stuffing it all into a conditional block.
>> >
>> > konce init 0
>> > ckgoto (konce == 1), terminate
>> >
>> > ... krate stuff, usually on arrays or k-rate opcodes like event
>> >
>> > konce = 1
>> >
>> > terminate:
>> >
>> >
>> >
>> >
>> >
>> > On Fri, Jan 22, 2016 at 7:04 AM, Steven Yi <[log in to unmask]> wrote:
>> >>
>> >> Hi Kevin,
>> >>
>> >> Using until-loops will compile down to gotos and labels and the loops
>> >> will process each value per k-rate loop and is as efficient as using
>> >> gotos and labels directly. Usage of until-loops is for clarity and
>> >> falls under the category of "control structures" within "structured
>> >> programming" (see [1] for background info). Dijkstra's [2] argument
>> >> against gotos and Knuth's [3] discussion of it and structured
>> >> programming are worthwhile reads, IMO, to get an idea of what happened
>> >> from the early days of programming as programming language design
>> >> evolved.  I think all of the same arguments against gotos/labels still
>> >> apply to Csound programming today.
>> >>
>> >> For my own Csound programming, since the introduction of if-then in CS
>> >> 4.23 and until- and while-loops in CS5/6, I have not had a need for
>> >> labels and gotos anymore. I'd generally encourage others to stop using
>> >> gotos/labels as well.
>> >>
>> >> steven
>> >>
>> >> [1] - https://en.wikipedia.org/wiki/Structured_programming
>> >> [2] -
>> >>
>> >> http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html
>> >> [3] -
>> >> http://www.cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammingGoTo.pdf
>> >>
>> >> On Thu, Jan 21, 2016 at 2:33 PM, Kevin Welsh <[log in to unmask]> wrote:
>> >> > Steven, is there a performance reason until is preferred over if/goto
>> >> > or cggoto?  I haven't tested it, but I believe in Menno's case (from
>> >> > having looked at the imageplayer before) he needs k-rate loops
>> >> > operating more than one pass per control rate.  Does using until
>> >> > achieve this too?
>> >> >
>> >> > Sorry if they're stupid questions... as evidenced by my last thread
>> >> > about loops and my replies to Rory's thread about loops, it's
>> >> > probably
>> >> > obvious looping in k-rate is fairly new to me.
>> >> >
>> >> > On Thu, Jan 21, 2016 at 1:20 PM, Steven Yi <[log in to unmask]>
>> >> > wrote:
>> >> >> Sorry, I realized I should have added increments, so the basic form
>> >> >> should be:
>> >> >>
>> >> >> kx = 0
>> >> >>
>> >> >> until (kx >= imaxX) do
>> >> >>   ky = 0
>> >> >>   until (ky >= imaxY) do
>> >> >>     ... do code ...
>> >> >>     ky += 1
>> >> >>   od
>> >> >>   kx += 1
>> >> >> od
>> >> >>
>> >> >> On Thu, Jan 21, 2016 at 10:44 AM, Steven Yi <[log in to unmask]>
>> >> >> wrote:
>> >> >>> I haven't looked at the code in depth, but in general for this kind
>> >> >>> of
>> >> >>> 2-dimensional data, I think it'd be more common to use nested
>> >> >>> loops,
>> >> >>> i.e.:
>> >> >>>
>> >> >>> kx = 0
>> >> >>>
>> >> >>> until (kx >= imaxX) do
>> >> >>>   ky = 0
>> >> >>>   until (ky >= imaxY) do
>> >> >>>   ... do code ...
>> >> >>>   od
>> >> >>> od
>> >> >>>
>> >> >>> That should read as "for each x location, read each y location and
>> >> >>> "do
>> >> >>> code". I would also suggest using the until-looping structure over
>> >> >>> goto's of any sort.
>> >> >>>
>> >> >>>
>> >> >>> On Thu, Jan 21, 2016 at 6:05 AM, Kevin Welsh <[log in to unmask]>
>> >> >>> wrote:
>> >> >>>> Hello Menno,
>> >> >>>>
>> >> >>>> I had taken a look at your imageplayer instrument a month or two
>> >> >>>> ago
>> >> >>>> when I was considering "porting" it to cabbage.  I noticed it
>> >> >>>> wasn't
>> >> >>>> looping on the y axis as well, so I had taken a crack at
>> >> >>>> re-writing
>> >> >>>> it.  I've been way too busy with life to really put too much
>> >> >>>> effort
>> >> >>>> into continuing the imageplayer port, I'm hoping I'll get more
>> >> >>>> free
>> >> >>>> time soon to work on it.
>> >> >>>>
>> >> >>>> This loop snippet starts both X and Y at 0, reads the data (insert
>> >> >>>> your own code for this where the comment is in the middle),
>> >> >>>> increments
>> >> >>>> X, returns to the "loopx" label to read again as long as it hasn't
>> >> >>>> reached maxX, in which case is continues... increments y, and
>> >> >>>> returns
>> >> >>>> to loopy label which in turn resets X to 0 to start reading the
>> >> >>>> next
>> >> >>>> row.  This continues until Y reaches it's max as well.
>> >> >>>>
>> >> >>>> The code can't be copy/pasted right in as a replacement, but it
>> >> >>>> hopefully it gives you an idea to get you moving forward.
>> >> >>>>
>> >> >>>>   iimage imageload Sfile
>> >> >>>>   imaxX, imaxY imagesize iimage
>> >> >>>>
>> >> >>>>   kxindex init 0
>> >> >>>>   kyindex init 0
>> >> >>>>
>> >> >>>>   loopy:
>> >> >>>>     kxindex = 0
>> >> >>>>   loopx:
>> >> >>>>
>> >> >>>> ;    imagegetpixel and the rest of what you want to do in the
>> >> >>>> "meat"
>> >> >>>> of the loop goes here
>> >> >>>>
>> >> >>>>     kxindex=kxindex+1
>> >> >>>>     cggoto (kxindex<imaxX), loopx
>> >> >>>>     kyindex=kyindex+1
>> >> >>>>     cggoto (kyindex<imaxY), loopy
>> >> >>>>
>> >> >>>> On Thu, Jan 21, 2016 at 5:26 AM, Menno Knevel
>> >> >>>> <[log in to unmask]>
>> >> >>>> wrote:
>> >> >>>>> Hi,
>> >> >>>>> i have an image that i want to convert to sound.
>> >> >>>>> <http://csound.1045644.n5.nabble.com/file/n5746506/30.png>
>> >> >>>>> This image example is 100 pixels x 3 pixels.
>> >> >>>>>
>> >> >>>>> I get it to scan from left to right but not from left to right
>> >> >>>>> while
>> >> >>>>> scanning the y axis. Somehow my loop is not correct but i don't
>> >> >>>>> see
>> >> >>>>> how.
>> >> >>>>> Perhaps someone can help here?
>> >> >>>>>
>> >> >>>>> loop:
>> >> >>>>>         ky = kindex / imageh
>> >> >>>>>         kred, kgreen, kblue imagegetpixel image, kx, ky
>> >> >>>>> ;printk 0, ky
>> >> >>>>> ;printk 0, kblue
>> >> >>>>>         printk 0, kindex
>> >> >>>>>         tablew (kgreen + kblue)*.5 , kindex, giamps
>> >> >>>>> ;write as amps to table
>> >> >>>>>         tablew imageh*1000 , kindex, gifrqs
>> >> >>>>> ;write as freqs to another table
>> >> >>>>>         kres tablei kindex, gifrqs
>> >> >>>>>         kindex = kindex + 1
>> >> >>>>> if (kindex < imageh) kgoto loop
>> >> >>>>>
>> >> >>>>> and in a greater context:
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>         instr 1
>> >> >>>>>
>> >> >>>>> ;===========load
>> >> >>>>> image==============================================
>> >> >>>>> image imageload
>> >> >>>>> "/home/menno/onderzoek/imageopcodes/px3greenblue.png"
>> >> >>>>> imagew, imageh imagesize image
>> >> >>>>> printf "width and height of image = %d x %d\n", 1, imagew, imageh
>> >> >>>>> ;show width and height of image
>> >> >>>>>
>> >> >>>>> giamps ftgen 0, 0, -imageh, 10, 1
>> >> >>>>> gifrqs ftgen 0, 0, imagew, -7, 0, imagew, 2
>> >> >>>>>
>> >> >>>>> kindex = 1
>> >> >>>>> kx linseg 0, p3, 1                                      ;X-axis
>> >> >>>>> range
>> >> >>>>>
>> >> >>>>> loop:
>> >> >>>>>         ky = kindex / imageh
>> >> >>>>>         kred, kgreen, kblue imagegetpixel image, kx, ky
>> >> >>>>> ;printk 0, ky
>> >> >>>>> ;printk 0, kblue
>> >> >>>>>         printk 0, kindex
>> >> >>>>>         tablew (kgreen + kblue)*.5 , kindex, giamps
>> >> >>>>> ;write as amps to table
>> >> >>>>>         tablew imageh*1000 , kindex, gifrqs
>> >> >>>>> ;write as freqs to another table
>> >> >>>>>         kres tablei kindex, gifrqs
>> >> >>>>>         kindex = kindex + 1
>> >> >>>>> if (kindex < imageh) kgoto loop
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>
>> >> >>>>> --
>> >> >>>>> View this message in context:
>> >> >>>>> http://csound.1045644.n5.nabble.com/no-looping-tp5746506.html
>> >> >>>>> Sent from the Csound - General mailing list archive at
>> >> >>>>> Nabble.com.
>> >> >>>>>
>> >> >>>>> Csound mailing list
>> >> >>>>> [log in to unmask]
>> >> >>>>> 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
>> >> >>>> [log in to unmask]
>> >> >>>> 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
>> >> >> [log in to unmask]
>> >> >> 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
>> >> > [log in to unmask]
>> >> > 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
>> >> [log in to unmask]
>> >> 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 [log in to unmask]
>> > 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
>> [log in to unmask]
>> 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 [log in to unmask]
> 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
[log in to unmask]
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

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015

ATOM RSS1 RSS2



LISTSERV.HEANET.IE

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager