Waiting until instr has finished
Date | 2015-12-28 00:26 |
From | Guillermo Senna |
Subject | Waiting until instr has finished |
Hi, I am trying to do a synth to do additive synthesis. I'm doing it with Cabbage. But my problems are related to Csound.I always get caught in the same thing, which is, how csound doesn't wait until for an instruction to be finished to read the next one. For example, in the attached .csd I have to call instr 4 and just then instr 5 to reset the volume. If I merge both instruments:instr 4 ; To be used after Stop button has been pressed. timout 0, 0.19, applyExpon turnoff2 3, 0, 1 ; turn off sound gkOff = 1 ; reset volume applyExpon: gkOff expon 1, 0.19, 0.0001 ; apply expon to avoid clicks. endin the assignment -besides being after the turnoff opcode- is evaluated before has finished. |
Date | 2015-12-28 00:30 |
From | Guillermo Senna |
Subject | Re: Waiting until instr has finished |
Attachments | ssd_a.csd |
Sorry, I hit the Send button. I was saying that the assignment happens before expon has finished, and the variable never gets reset to 1.2015-12-27 21:26 GMT-03:00 Guillermo Senna <gsenna@gmail.com>:
|
Date | 2015-12-28 05:05 |
From | Tarmo Johannes |
Subject | Re: Waiting until instr has finished |
Hi, perhaps the r-family envelope opcodes help you (r - for appended extra release time for decay), for example expsegr http://www.csounds.com/manual/html/expsegr.html or linenr, madsr http://www.csounds.com/manual/html/linenr.html And you don't need instr 4 after all. 2015-12-28 2:30 GMT+02:00 Guillermo Senna <gsenna@gmail.com>:
|
Date | 2015-12-28 19:33 |
From | Guillermo Senna |
Subject | Re: Waiting until instr has finished |
Hi Tarmo, Thanks. I'll change my code using what you're suggesting. But I was thinking beyond this code actually. Because it's a recurrent situation for my. So, is it "best practice" to write code using a lot of instruments just to reset a variable or is there a "wait until return" opcode or something like that in Csound that i'm missing? Thank you. 2015-12-28 2:05 GMT-03:00, Tarmo Johannes |
Date | 2015-12-29 02:17 |
From | Kevin Welsh |
Subject | Re: Waiting until instr has finished |
I think in this case, the -r opcodes are *especially* helpful because you want it recurrent (I assume the goal is to eventually have it midi controlled, responding to more than just the on/off button?)... but I might not understand your end goal correctly, so maybe not. As it's currently written, if one instance of the instrument is in it's release phase the second instance will also release, because they're both using the same global variable (gkOff) for amplitude. Using a -r opcode allows you to have a release phase that extends after the "noteoff" event, so you could move the release envelope code into instr 3 (the oscillator), that way each triggered note can have it's own envelope. Hopefully that helps, good luck! On Mon, Dec 28, 2015 at 2:33 PM, Guillermo Senna |
Date | 2015-12-29 03:13 |
From | Guillermo Senna |
Subject | Re: Waiting until instr has finished |
Hi Kevin, In Csound this doesn't necessarily happen. Because if I asked for an expon opcode and THEN an assignment, the assignment does not wait until the expon has finished. So I end up writing small instruments and using p2 and p3 to control the sequence. I think there has to be a better way, because time is not a guarantee that the first instrument has returned. So, is there such thing in Csound? Or how do you solve that kind of problem? Thanks. 2015-12-28 23:17 GMT-03:00 Kevin Welsh <tgrey1@gmail.com>: I think in this case, the -r opcodes are *especially* helpful because |
Date | 2015-12-29 07:17 |
From | Tarmo Johannes |
Subject | Re: Waiting until instr has finished |
Hi,
Csound logic is slightly different than say python or other programming language where you can write: do that, and next row is executed when it is done. It is rather a loop an all the code of all instruments must be done withing one audio cycle, say 1/44100 of second - otherwise audio has dropouts.
I think easiest way to organise when something is done is to put your code that you want to be executed to another instrument and call it (schedule, schedkwhen, event "i" etc ) when it is needed. Or use timout as in your first example. Somehow I am always confused with it and tend to prefer to use other instruments for timing tasks. Or you can also use timeinst to measure time from the beginning of your instrument. OR you can use release() to detect if this is the last k-cycle of the instrument. There are of course mor ways, as always with csound...
So:
instr 4 ; To be used after Stop button has been pressed. p3 = 0.19 ; make the instrument run 0.19 seconds gkOff expon 1, p3, 0.0001 ; apply expon to avoid clicks.
if (release()==1) then turnoff2 3, 0, 1 ; turn off sound gkOff = 1 ; reset volume endif
endin
OR
instr 4 ; To be used after Stop button has been pressed. gkOff expon 1, 0.19, 0.0001 ; apply expon to avoid clicks.
if (timeinst()>=0.19) then turnoff2 3, 0, 1 ; turn off sound gkOff = 1 ; reset volume turnoff ; and turn itself off endif
endin
OR
instr 4 ; To be used after Stop button has been pressed. schedule 5, 0.19,0.1 gkOff expon 1, 0.19, 0.0001 ; apply expon to avoid clicks. endin
instr 5 gkOff init 1 turnoff2 3,0,1 endin
These are just examples and in your exact case don't make sense (since r-thing is best solution for an envelope), I hope it could help you to understand some "csound tricks".
And it IS is a bit confusing at the beginning, don't worry. Thanks for clarifying!
tarmo
On Tuesday 29 December 2015 00:13:09 you wrote: > Hi Kevin, > > The end goal is to build a simple synth with 5 oscilators to generate "tone > mixtures" as the ones used by Stockhausen in his Studie II, and to be able > to record them also. So, I will use the -r opcodes in this .csd to simplify > the thing. > > But my concerns are not about this particular piece of code, but more in a > general way. Maybe because I am more used to thinking sequentially about > programming, I am always looking for some opcode that will allow me to > write something like "Do that, and exactly after you've returned continue > with this". > > In Csound this doesn't necessarily happen. Because if I asked for an expon > opcode and THEN an assignment, the assignment does not wait until the expon > has finished. So I end up writing small instruments and using p2 and p3 to > control the sequence. I think there has to be a better way, because time is > not a guarantee that the first instrument has returned. So, is there such > thing in Csound? Or how do you solve that kind of problem? > > Thanks. > > 2015-12-28 23:17 GMT-03:00 Kevin Welsh <tgrey1@gmail.com>: > > I think in this case, the -r opcodes are *especially* helpful because > > you want it recurrent (I assume the goal is to eventually have it midi > > controlled, responding to more than just the on/off button?)... but I > > might not understand your end goal correctly, so maybe not. > > > > As it's currently written, if one instance of the instrument is in > > it's release phase the second instance will also release, because > > they're both using the same global variable (gkOff) for amplitude. > > Using a -r opcode allows you to have a release phase that extends > > after the "noteoff" event, so you could move the release envelope code > > into instr 3 (the oscillator), that way each triggered note can have > > it's own envelope. > > > > Hopefully that helps, good luck! > > > > On Mon, Dec 28, 2015 at 2:33 PM, Guillermo Senna <gsenna@gmail.com> wrote: > > > Hi Tarmo, > > > > > > Thanks. I'll change my code using what you're suggesting. > > > > > > But I was thinking beyond this code actually. Because it's a recurrent > > > situation for my. So, is it "best practice" to write code using a lot > > > of instruments just to reset a variable or is there a "wait until > > > return" opcode or something like that in Csound that i'm missing? > > > > > > Thank you. > > > > > > 2015-12-28 2:05 GMT-03:00, Tarmo Johannes < > > > > tarmo.johannes@otsakool.edu.ee>: > > >> Hi, > > >> > > >> perhaps the r-family envelope opcodes help you (r - for appended extra > > >> release time for decay), for example expsegr > > >> http://www.csounds.com/manual/html/expsegr.html or linenr, madsr > > >> http://www.csounds.com/manual/html/linenr.html > > >> > > >> Perhaps something like that in instr 3 > > >> > > >> ares expsegr 0.0001, p6, p5, p7, 0.0001 > > >> or > > >> ares linenr p5, p6, p7,0.001 > > >> > > >> And you don't need instr 4 after all. > > >> > > >> Hope it helps, > > >> tarmo > > >> > > >> 2015-12-28 2:30 GMT+02:00 Guillermo Senna <gsenna@gmail.com>: > > >>> Sorry, I hit the Send button. > > >>> > > >>> I was saying that the assignment happens before expon has finished, > > >>> and > > >>> the variable never gets reset to 1. > > >>> Also, if you could mark better ways to do anything in the code, please > > >>> do. > > >>> > > >>> Thanks you. > > >>> > > >>> 2015-12-27 21:26 GMT-03:00 Guillermo Senna <gsenna@gmail.com>: > > >>>> Hi, > > >>>> > > >>>> I am trying to do a synth to do additive synthesis. I'm doing it with > > >>>> Cabbage. But my problems are related to Csound.I always get caught in > > >>>> the > > >>>> same thing, which is, how csound doesn't wait until for an > > >>>> instruction > > >>>> to > > >>>> be finished to read the next one. For example, in the attached .csd I > > >>>> have > > >>>> to call instr 4 and just then instr 5 to reset the volume. If I merge > > >>>> both > > >>>> instruments: > > >>>> > > >>>> instr 4 ; To be used after Stop button has been pressed. > > >>>> > > >>>> timout 0, 0.19, applyExpon > > >>>> turnoff2 3, 0, 1 ; turn off sound > > >>>> > > >>>> gkOff = 1 ; reset volume > > >>>> > > >>>> applyExpon: > > >>>> gkOff expon 1, 0.19, 0.0001 ; apply expon to avoid clicks. > > >>>> > > >>>> endin > > >>>> > > >>>> the assignment -besides being after the turnoff opcode- is evaluated > > >>>> > > >>>> before has finished. > > >>> > > >>> 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
|