[Csnd] Easiest time-controlled switching
| Date | 2021-03-20 08:11 |
| From | "Jeanette C." |
| Subject | [Csnd] Easiest time-controlled switching |
Hey hey,
I was wondering if my code could be more elegant.
I have a switch (kSwitch), which can have two states. Now I need to change it
over time. At the moment I'm doing this:
kSwitch = linseg(0, iDur1, 0, 0, 1, iDur2, 1, 0, 0, iDur3 0)
Is there a better, nicer, easier way?
Best wishes and TIA,
Jeanette
--
* Website: http://juliencoder.de - for summer is a state of sound
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
* Audiobombs: https://www.audiobombs.com/users/jeanette_c
* GitHub: https://github.com/jeanette-c
Can't you see I'm a fool in so many ways <3
(Britney Spears)
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 |
| Date | 2021-03-20 09:21 |
| From | Rory Walsh |
| Subject | Re: [Csnd] Easiest time-controlled switching |
You should also used a small table with 0 and 1 in it? On Sat 20 Mar 2021, 8:11 a.m. Jeanette C., <julien@mail.upb.de> wrote: Hey hey, |
| Date | 2021-03-20 10:04 |
| From | "Jeanette C." |
| Subject | Re: [Csnd] Easiest time-controlled switching |
Mar 20 2021, Rory Walsh has written: > You should also used a small table with 0 and 1 in it? Could you perhaps elaborate a little, please? Best wishes, Jeanette > > On Sat 20 Mar 2021, 8:11 a.m. Jeanette C., |
| Date | 2021-03-20 12:09 |
| From | Rory Walsh |
| Subject | Re: [Csnd] Easiest time-controlled switching |
You could also use an array and just switch between the two states? Or am I missing something? On Sat, 20 Mar 2021 at 10:04, Jeanette C. <julien@mail.upb.de> wrote: Mar 20 2021, Rory Walsh has written: |
| Date | 2021-03-20 12:24 |
| From | joachim heintz |
| Subject | Re: [Csnd] Easiest time-controlled switching |
you mean the durations are not the same, so it is an aperiodic switch?
i have a udo which is:
opcode Switch, k, k[]
kDurs[] xin
kndx init 0
kOut init 0
if metro(1/kDurs[kndx])==1 then
kOut = (kOut==0) ? 1 : 0
kndx = (kndx+1) % lenarray(kDurs)
endif
xout kOut
endop
you can feed it with an array of the durations, e.g.
instr 1
kOut Switch fillarray(1, .5, 1, .5, 2)
printk2 kOut
endin
schedule(1,0,10)
it will read the array in a loop, but it could also stop at last value,
or whatever behaviour you wish for your case.
best -
joachim
On 20/03/2021 09:11, Jeanette C. wrote:
> Hey hey,
> I was wondering if my code could be more elegant.
>
> I have a switch (kSwitch), which can have two states. Now I need to
> change it over time. At the moment I'm doing this:
> kSwitch = linseg(0, iDur1, 0, 0, 1, iDur2, 1, 0, 0, iDur3 0)
> Is there a better, nicer, easier way?
>
> Best wishes and TIA,
>
> Jeanette
>
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 |
| Date | 2021-03-20 12:55 |
| From | "Jeanette C." |
| Subject | Re: [Csnd] Easiest time-controlled switching |
Many thanks, Joachim! This is neat! That's why I love this list! <3
Mar 20 2021, joachim heintz has written:
> you mean the durations are not the same, so it is an aperiodic switch?
>
> i have a udo which is:
>
> opcode Switch, k, k[]
> kDurs[] xin
> kndx init 0
> kOut init 0
> if metro(1/kDurs[kndx])==1 then
> kOut = (kOut==0) ? 1 : 0
> kndx = (kndx+1) % lenarray(kDurs)
> endif
> xout kOut
> endop
>
> you can feed it with an array of the durations, e.g.
>
> instr 1
> kOut Switch fillarray(1, .5, 1, .5, 2)
> printk2 kOut
> endin
> schedule(1,0,10)
>
> it will read the array in a loop, but it could also stop at last value, or
> whatever behaviour you wish for your case.
>
> best -
> joachim
>
>
> On 20/03/2021 09:11, Jeanette C. wrote:
>> Hey hey,
>> I was wondering if my code could be more elegant.
>>
>> I have a switch (kSwitch), which can have two states. Now I need to change
>> it over time. At the moment I'm doing this:
>> kSwitch = linseg(0, iDur1, 0, 0, 1, iDur2, 1, 0, 0, iDur3 0)
>> Is there a better, nicer, easier way?
>>
>> Best wishes and TIA,
>>
>> Jeanette
>>
>
> 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
>
--
* Website: http://juliencoder.de - for summer is a state of sound
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
* Audiobombs: https://www.audiobombs.com/users/jeanette_c
* GitHub: https://github.com/jeanette-c
You might think that I won't make it on my own,
But now I'm Stronger <3
(Britney Spears)
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 |