[Csnd] cv switch
Date | 2013-09-27 15:31 |
From | orebronerd |
Subject | [Csnd] cv switch |
I am trying to implement a 3 way switch in csound, but can´t find any easy solutions. A 2 way switch is relatively easy. I solved that this way: instr 1 asig1 poscil 0.3,440,gisine asig2 poscil 0.3,220,gisine klfo1 lfo 1,2,3 klfo1 port klfo1, 0.01 klfo2 = 1-klfo1 asig1 =asig1*klfo1 asig2 =asig2*klfo2 atot = asig1 + asig2 out atot endin But a 3 way (or more) switch is more complicated. I could use a 3 level cv, and some if-statements, but it seems a bit laboursome. I have tried to find a switch opcode, but a search for "switch" returned 0. I dream about an opcode that looks like this: asig NSWITCH ktrig, inumber, asig1, asig2, asig3 etc where you can specify a trigger, the number of inputs(= inumber), and the different input signals. It should also have an internal attack-release of about 0.01 s when you change signal, to avoid clicks. Any ideas with existing opcodes, or perhaps someone good at programming could have a go? -- View this message in context: http://csound.1045644.n5.nabble.com/cv-switch-tp5727911.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-09-27 16:12 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Csnd] cv switch |
Maybe you need an array of signals and some code to cross-fade > I am trying to implement a 3 way switch in csound, but can´t find any > easy > solutions. A 2 way switch is relatively easy. I solved that this way: > instr 1 > > asig1 poscil 0.3,440,gisine > asig2 poscil 0.3,220,gisine > klfo1 lfo 1,2,3 > klfo1 port klfo1, 0.01 > klfo2 = 1-klfo1 > asig1 =asig1*klfo1 > asig2 =asig2*klfo2 > atot = asig1 + asig2 > out atot > endin > > But a 3 way (or more) switch is more complicated. I could use a 3 level > cv, > and some if-statements, but it seems a bit laboursome. I have tried to > find > a switch opcode, but a search for "switch" returned 0. > I dream about an opcode that looks like this: > asig NSWITCH ktrig, inumber, asig1, asig2, asig3 etc > where you can specify a trigger, the number of inputs(= inumber), and the > different input signals. It should also have an internal attack-release of > about 0.01 s when you change signal, to avoid clicks. > Any ideas with existing opcodes, or perhaps someone good at programming > could have a go? > > > > -- > View this message in context: > http://csound.1045644.n5.nabble.com/cv-switch-tp5727911.html > Sent from the Csound - General mailing list archive at Nabble.com. > > > Send bugs reports to the Sourceforge bug trackers > csound6: > https://sourceforge.net/p/csound/tickets/ > csound5: > https://sourceforge.net/p/csound/bugs/ > Discussions of bugs and features can be posted here > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe > csound" > > > > > |
Date | 2013-09-27 17:57 |
From | joachim heintz |
Subject | Re: [Csnd] cv switch |
Attachments | test2.csd |
yes, this is not that complicated. actually, if you did not need crossfade, the code would be simple: instr 1 asig1 poscil .2, 770 asig2 poscil .2, 440 asig3 poscil .2, 550 kTrig randomh 1, 4, 1 printk2 int(kTrig) if kTrig < 2 then asig = asig1 elseif kTrig < 3 then asig = asig2 else asig = asig3 endif outs asig, asig endin crossfading means that you do more or less the same, but for the volume control of each "track". adding port (as you already did) is all you need then: instr 2 ;three audio signals asig1 poscil .2, 770 asig2 poscil .2, 440 asig3 poscil .2, 550 ;primitive random choice kTrig randomh 1, 4, 1 printk2 int(kTrig) ;switch matrix if kTrig < 2 then ksig1 = 1 ksig2 = 0 ksig3 = 0 elseif kTrig < 3 then ksig1 = 0 ksig2 = 1 ksig3 = 0 else ksig1 = 0 ksig2 = 0 ksig3 = 1 endif ;apply smooth transitions ksig1 port ksig1, .1 ksig2 port ksig2, .1 ksig3 port ksig3, .1 ;multiply with audio asig1 = asig1*ksig1 asig2 = asig2*ksig2 asig3 = asig3*ksig3 ;send the sum out outs asig1+asig2+asig3, asig1+asig2+asig3 endin i have attached a complete example. best - joachim Am 27.09.2013 16:31, schrieb orebronerd: > I am trying to implement a 3 way switch in csound, but can´t find any easy > solutions. A 2 way switch is relatively easy. I solved that this way: > instr 1 > > asig1 poscil 0.3,440,gisine > asig2 poscil 0.3,220,gisine > klfo1 lfo 1,2,3 > klfo1 port klfo1, 0.01 > klfo2 = 1-klfo1 > asig1 =asig1*klfo1 > asig2 =asig2*klfo2 > atot = asig1 + asig2 > out atot > endin > > But a 3 way (or more) switch is more complicated. I could use a 3 level cv, > and some if-statements, but it seems a bit laboursome. I have tried to find > a switch opcode, but a search for "switch" returned 0. > I dream about an opcode that looks like this: > asig NSWITCH ktrig, inumber, asig1, asig2, asig3 etc > where you can specify a trigger, the number of inputs(= inumber), and the > different input signals. It should also have an internal attack-release of > about 0.01 s when you change signal, to avoid clicks. > Any ideas with existing opcodes, or perhaps someone good at programming > could have a go? > > > > -- > View this message in context: http://csound.1045644.n5.nabble.com/cv-switch-tp5727911.html > Sent from the Csound - General mailing list archive at Nabble.com. > > > Send bugs reports to the Sourceforge bug trackers > csound6: > https://sourceforge.net/p/csound/tickets/ > csound5: > https://sourceforge.net/p/csound/bugs/ > Discussions of bugs and features can be posted here > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound" > > > |
Date | 2013-09-27 18:14 |
From | Iain McCurdy |
Subject | RE: [Csnd] cv switch |
Here's another option using a table with wrapping. The advantage of this method is that you could expand it to a 20 way switch without the code needing to be vastly more complicated. <CsoundSynthesizer> <CsOptions> -odac </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 1 0dbfs = 1 instr 1 iOnOff ftgen 0,0,4,-2,1 kswitch = p4 k1 table kswitch-1 ,iOnOff,0,0,1 k2 table kswitch-2,iOnOff,0,0,1 k3 table kswitch-3,iOnOff,0,0,1 a1 vco2 0.3*k1,400,4,0.5 ; switch pos. 1 a2 vco2 0.3*k2,500,4,0.5 ; switch pos. 2 a3 vco2 0.3*k3,600,4,0.5 ; switch pos. 3 out a1+a2+a3 endin </CsInstruments> <CsScore> ; p4 = switch position 1,2 or 3 i 1 0 0.5 1 i 1 + 0.5 2 i 1 + 0.5 3 </CsScore> </CsoundSynthesizer> > Date: Fri, 27 Sep 2013 07:31:48 -0700 > From: martino.flodino@gmail.com > To: csound@lists.bath.ac.uk > Subject: [Csnd] cv switch > > I am trying to implement a 3 way switch in csound, but can´t find any easy > solutions. A 2 way switch is relatively easy. I solved that this way: > instr 1 > > asig1 poscil 0.3,440,gisine > asig2 poscil 0.3,220,gisine > klfo1 lfo 1,2,3 > klfo1 port klfo1, 0.01 > klfo2 = 1-klfo1 > asig1 =asig1*klfo1 > asig2 =asig2*klfo2 > atot = asig1 + asig2 > out atot > endin > > But a 3 way (or more) switch is more complicated. I could use a 3 level cv, > and some if-statements, but it seems a bit laboursome. I have tried to find > a switch opcode, but a search for "switch" returned 0. > I dream about an opcode that looks like this: > asig NSWITCH ktrig, inumber, asig1, asig2, asig3 etc > where you can specify a trigger, the number of inputs(= inumber), and the > different input signals. It should also have an internal attack-release of > about 0.01 s when you change signal, to avoid clicks. > Any ideas with existing opcodes, or perhaps someone good at programming > could have a go? > > > > -- > View this message in context: http://csound.1045644.n5.nabble.com/cv-switch-tp5727911.html > Sent from the Csound - General mailing list archive at Nabble.com. > > > Send bugs reports to the Sourceforge bug trackers > csound6: > https://sourceforge.net/p/csound/tickets/ > csound5: > https://sourceforge.net/p/csound/bugs/ > Discussions of bugs and features can be posted here > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound" > > |
Date | 2013-09-27 20:29 |
From | joachim heintz |
Subject | Re: [Csnd] cv switch |
very clever ... -- it took some time until i understood how this works. would be nice (und much easier) to do this with the new arrays! best - joachim Am 27.09.2013 19:14, schrieb Iain McCurdy: > Here's another option using a table with wrapping. The advantage of this > method is that you could expand it to a 20 way switch without the code > needing to be vastly more complicated. > > |
Date | 2013-09-27 20:40 |
From | orebronerd |
Subject | [Csnd] Re: cv switch |
Thank you for your suggestions. They all look like workable solutions. I will try them out tomorrow, it´s getting late in Sweden. I do miss a switch opcode though. Perhaps something for the next update? -- View this message in context: http://csound.1045644.n5.nabble.com/cv-switch-tp5727911p5727916.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-09-27 21:29 |
From | orebronerd |
Subject | [Csnd] Re: cv switch |
I had another go, (it wasn´t so late after all) working with table lookups and if statements, but then I have the problem with the clicks when it jumps in amplitude. |
Date | 2013-09-27 21:43 |
From | Steven Yi |
Subject | Re: [Csnd] Re: cv switch |
Here's another possible solution. kswitch sig is any signal. It gets truncated to just the integer part, then the amplitude for that index is set to 1 or 0. Port is used to smooth the transition from those two states. You could also do a recursive UDO version that could be extended to n- oscillators at run time. Cheers! steven |
Date | 2013-09-28 10:07 |
From | joachim heintz |
Subject | Re: [Csnd] Re: cv switch |
yes, i have shown in my previous mail how you can prevent clicks (in the second example). joachim Am 27.09.2013 22:29, schrieb orebronerd: > I had another go, (it wasn´t so late after all) working with table lookups > and if statements, but then I have the problem with the clicks when it jumps > in amplitude. > > |
Date | 2013-09-28 12:13 |
From | orebronerd |
Subject | [Csnd] Re: cv switch |
Thank you once more for all of your ideas. Sorry, I missed the port solution, I guess it was late after all. :-) -- View this message in context: http://csound.1045644.n5.nabble.com/cv-switch-tp5727911p5727928.html Sent from the Csound - General mailing list archive at Nabble.com. |