Csound Csound-dev Csound-tekno Search About

[Csnd] Time-based loops

Date2014-09-11 18:37
Fromorebronerd
Subject[Csnd] Time-based loops
I work a lot with loops, a simple example would be (instr 1 calls on instr 10
via event_i):




sr = 44100
ksmps = 10
nchnls = 1
0dbfs  = 1

gisine	ftgen	0,0,2^12,10,1

instr 1
index=0
until index=30 do
itime	= index/4
idur	= 0.1
event_i "i",10,itime,idur
index	=index+1
od
endin

instr 10

asig 		poscil 0.5,220,gisine
kenv 		linseg 0,0.01,1,p3-0.02,1,0.01,0
asig 		= asig*kenv
out		asig
endin



i 1	0	6




But now I want to try a more timebased loop. I want a loop to run for a
certain amount of seconds.  I thought I could just set a condition based on
timesints but CsoundQT just stops and then crashes, both on Windows and Mac.




sr = 44100
ksmps = 10
nchnls = 1
0dbfs  = 1

gisine	ftgen	0,0,2^12,10,1

instr 1
index=0
ksec	timeinsts
until ksec >4 do
itime	= index/4
idur	= 0.1
event_i "i",10,itime,idur
index	=index+1
od
endin

instr 10

asig 		poscil 0.5,220,gisine
kenv 		linseg 0,0.01,1,p3-0.02,1,0.01,0
asig 		= asig*kenv
out		asig
endin



i 1	0	4




Any ideas why it doesn´t work? Any suggestions on how make it work? I know
that I can use index like in the first example, and raise index to a
suitable number, but it seems somewhat easier to base it on seconds. 





--
View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458.html
Sent from the Csound - General mailing list archive at Nabble.com.


Date2014-09-11 18:45
FromRory Walsh
SubjectRe: [Csnd] Time-based loops
I don't have time to look into the specific issue you are having, but
I would use the k-rate version of event if I was doing this:

instr 1
k1  metro 1
if  k1 ==1  then
            event "i", 10, 0, 1
endif
endin

instr 10
asig            poscil 0.5,220,gisine
kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
asig            = asig*kenv
out             asig
endin

This will keep triggering instr 10 for as long as instr 1 is set to run for.

On 11 September 2014 18:37, orebronerd  wrote:
> I work a lot with loops, a simple example would be (instr 1 calls on instr 10
> via event_i):
> 
> 
> 
> 
> sr = 44100
> ksmps = 10
> nchnls = 1
> 0dbfs  = 1
>
> gisine  ftgen   0,0,2^12,10,1
>
> instr 1
> index=0
> until index=30 do
> itime   = index/4
> idur    = 0.1
> event_i "i",10,itime,idur
> index   =index+1
> od
> endin
>
> instr 10
>
> asig            poscil 0.5,220,gisine
> kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
> asig            = asig*kenv
> out             asig
> endin
>
> 
> 
> i 1     0       6
>
> 
> 
>
> But now I want to try a more timebased loop. I want a loop to run for a
> certain amount of seconds.  I thought I could just set a condition based on
> timesints but CsoundQT just stops and then crashes, both on Windows and Mac.
> 
> 
> 
> 
> sr = 44100
> ksmps = 10
> nchnls = 1
> 0dbfs  = 1
>
> gisine  ftgen   0,0,2^12,10,1
>
> instr 1
> index=0
> ksec    timeinsts
> until ksec >4 do
> itime   = index/4
> idur    = 0.1
> event_i "i",10,itime,idur
> index   =index+1
> od
> endin
>
> instr 10
>
> asig            poscil 0.5,220,gisine
> kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
> asig            = asig*kenv
> out             asig
> endin
>
> 
> 
> i 1     0       4
>
> 
> 
>
> Any ideas why it doesn´t work? Any suggestions on how make it work? I know
> that I can use index like in the first example, and raise index to a
> suitable number, but it seems somewhat easier to base it on seconds.
>
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>
>


Date2014-09-11 20:48
Fromforrest curo
SubjectRe: [Csnd] Time-based loops
It looks to me that the loop in instr 1 would do its whole thing...

in one long 'init' pass looping & looping and looping

before it got around to anything else. Shouldn't these be k-rate variables in the loop?

[?]
Forrest Curo
San Diego

On Thu, Sep 11, 2014 at 10:45 AM, Rory Walsh <rorywalsh@ear.ie> wrote:
I don't have time to look into the specific issue you are having, but
I would use the k-rate version of event if I was doing this:

instr 1
k1  metro 1
if  k1 ==1  then
            event "i", 10, 0, 1
endif
endin

instr 10
asig            poscil 0.5,220,gisine
kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
asig            = asig*kenv
out             asig
endin

This will keep triggering instr 10 for as long as instr 1 is set to run for.

On 11 September 2014 18:37, orebronerd <martino.flodino@gmail.com> wrote:
> I work a lot with loops, a simple example would be (instr 1 calls on instr 10
> via event_i):
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
> sr = 44100
> ksmps = 10
> nchnls = 1
> 0dbfs  = 1
>
> gisine  ftgen   0,0,2^12,10,1
>
> instr 1
> index=0
> until index=30 do
> itime   = index/4
> idur    = 0.1
> event_i "i",10,itime,idur
> index   =index+1
> od
> endin
>
> instr 10
>
> asig            poscil 0.5,220,gisine
> kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
> asig            = asig*kenv
> out             asig
> endin
>
> </CsInstruments>
> <CsScore>
> i 1     0       6
>
> </CsScore>
> </CsoundSynthesizer>
>
> But now I want to try a more timebased loop. I want a loop to run for a
> certain amount of seconds.  I thought I could just set a condition based on
> timesints but CsoundQT just stops and then crashes, both on Windows and Mac.
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
> sr = 44100
> ksmps = 10
> nchnls = 1
> 0dbfs  = 1
>
> gisine  ftgen   0,0,2^12,10,1
>
> instr 1
> index=0
> ksec    timeinsts
> until ksec >4 do
> itime   = index/4
> idur    = 0.1
> event_i "i",10,itime,idur
> index   =index+1
> od
> endin
>
> instr 10
>
> asig            poscil 0.5,220,gisine
> kenv            linseg 0,0.01,1,p3-0.02,1,0.01,0
> asig            = asig*kenv
> out             asig
> endin
>
> </CsInstruments>
> <CsScore>
> i 1     0       4
>
> </CsScore>
> </CsoundSynthesizer>
>
> Any ideas why it doesn´t work? Any suggestions on how make it work? I know
> that I can use index like in the first example, and raise index to a
> suitable number, but it seems somewhat easier to base it on seconds.
>
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>
>


Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





Date2014-09-13 08:23
Fromorebronerd
Subject[Csnd] Re: Time-based loops
Thank you for your replies. I will try your suggestions. For the moment I can
find different workarounds, but the basic question remains, if it is
possible to construct loops the way I want it, based on timeinsts.



--
View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458p5737477.html
Sent from the Csound - General mailing list archive at Nabble.com.

Date2014-09-23 21:06
Fromjoachim heintz
SubjectRe: [Csnd] Re: Time-based loops
hi --

and sorry for the 10-day delay line. i think i can contribute something 
to your question.

this is the code you sent:
index=0
ksec	timeinsts
until ksec >4 do
itime	= index/4
idur	= 0.1
event_i "i",10,itime,idur
index	=index+1
od

i think there are two different problems here:

1) you mix up i- and k-rate. if you have a condition at k-rate ("until 
ksec>4 do"), you must have a consecution at k-rate. or, in other words: 
the i-rate statements in your code will not care at all about the k-rate 
condition. look at this:

instr 1
kbla = 1
until kbla < 4 do
event_i "i", 2, 0, 1
od
endin
instr 2
prints "HUHU\n"
endin

although the until condition is not being passed, instr 2 is called 
(once), because it is called at i-rate, and the k-condition does not 
prevent this.

we all know (and experience it again and again) that this i- / k- stuff 
is one major source for code errors in csound. perhaps this helps to 
understand what happens (if you do not know it already): 
http://en.flossmanuals.net/csound/a-initialization-and-performance-pass


2) i must say that i do not understand exactly why you use an until-loop 
at all in your instrument. what is your code supposed to do? you said in 
your first message: "I want a loop to run for a certain amount of 
seconds." what does this mean? if you want to fire instruments as long 
as a certain time is not exceeded, you do not need any loop inside the 
instrument. this code, for instance. calls instr 2 once a k-period, 
until 0.1 has not been exceeded:



-n


ksmps = 32

instr 1
ktime timeinsts
if ktime < 0.1 then
event "i", 2, 0, 0
endif
endin

instr 2
prints "HUHUHU\n"
endin



i1 0 .5




the number of instrument calls depends on the k-rate. so if you use 
ksmps=10 instead of ksmps=32, you will get more calls, and vice versa.

hope this helps. all best -
	joachim


Am 13.09.2014 um 09:23 schrieb orebronerd:
> Thank you for your replies. I will try your suggestions. For the moment I can
> find different workarounds, but the basic question remains, if it is
> possible to construct loops the way I want it, based on timeinsts.
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458p5737477.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>
>
>

Date2014-09-24 07:25
Fromorebronerd
Subject[Csnd] Re: Time-based loops
Thank you for your reply. Regarding my aim: I use loops today, that I can
regulate the tempo by dividing index by different amounts. I can adjust it
to a certain metronome tempo, 1/8th notes, triplets etc. I can then regulate
the length of the loop either by regulating the loop count, or setting the
loop count high, and regulating the length of the note for the instrument
with the loop. Example:





sr = 44100
ksmps = 1
nchnls = 1
0dbfs  = 1
	;instr 1 is a loop that calls instrument 10.
gisine	ftgen	0,0,2^12,10,1
gitempo	=60/115	;global tempo, in this case MM=115

instr 1
	index=0
	loop:
	itime	=index*gitempo/4	;adjusting the tempo of notes produced. MM =115,
16:th notes.
	idur	=0.1
	ifreq	= 220
	event_i "i",10,itime,idur,ifreq
	loop_lt index,1,100,loop ; loop count set high. 
	endin

instr 10

asig 		poscil 0.5,p4,gisine
kenv 		linseg 0,0.01,1,p3-0.02,1,0.01,0
asig 		= asig*kenv
out		asig
endin




i 1	0	10		; I can regulate the length of the loop with the duration of the
note for instr 1.		




My aim was to see if I could regulate the length of the loop more easily
within the loop itself. I use score less and less, because I find it hard to
work with when you are using a lot of notes. This is easier to control by
loops in my opinion. I also wanted in the next step to have a loop within a
loop that regulated the length of the loop. (Of course I can do this now by
having a loop changing the loop count of an inner loop.)
I am working on some pieces with a lot of loops where the MM per se isn´t
important, but the length of the loops in seconds. (Although I adjust the
tempo of the loop to a fitting feeling, but it doesn´t relate to a certain
master tempo.) Of course I can continue working with different lengths of
notes to instr 1, but for me it would be more elegant and easy if I could
regulate the time in seconds within the loop. 
I understand the difference between i-rate and k-rate. I thought in this
case that the k-rate only would affect the speed with which the computer
computed this, since the resulting notes are governed by the itime variable
based on the index value, but I realize now that this isn´t the case. It
works with loops based on index, but not based on duration for the
instrument, or rather I think it works in theory, but you get an enormous
amount of loop counts, that chokes the computer.
This isn´t a big problem at the moment, so please don´t waste a lot of time
on this. I have workarounds. 



--
View this message in context: http://csound.1045644.n5.nabble.com/Time-based-loops-tp5737458p5737637.html
Sent from the Csound - General mailing list archive at Nabble.com.