|
Hello,
I have since sorted this out, and I wanted to post my solution, just in case
anyone else needs to do something similar. The problem I was having was that
using gasig to send from the inputs was clipping madly, resulting in out of
range samples, silence, and distortion. I am using a scaled MixerSend now
and it works quite well. Also, I used turnoff2 to include the fadeout. Note:
the Mixer instrument is for future use, and not implemented in the below
code.
Thanks again Iain!
sr = 44100
kr = 441
ksmps = 100
nchnls = 2
0dbfs = 1
chn_k "Control1", 1
chn_k "Control2", 1
chn_k "Control3", 1
chn_k "Control4", 1
chn_k "Control5", 1
chn_k "Control6", 1
chn_k "Control7", 1
chn_k "Control8", 1
chn_k "Control9", 1
chn_k "Control10", 1
chn_k "Control11", 1
chn_k "Control12", 1
chn_k "Control13", 1
chn_k "Control14", 1
chn_k "Control15", 1
chn_k "Control16", 1
chn_k "Ktime", 1
chn_k "kTrigger", 1
chn_k "gkeffect", 1
chn_k "kInsnumoff", 1
chn_k "kattack", 1 ; fade in time
chn_k "krelease", 1 ;fade out time
chn_k "gkvolumefactor", 1 ;volume scaler for all effects
chn_k "kroot_note", 1 ;root note for pitch effects
instr 1
;control invalues
iControl1 chnget "Control1"
iControl2 chnget "Control2"
iControl3 chnget "Control3"
iControl4 chnget "Control4"
iControl5 chnget "Control5"
iControl6 chnget "Control6"
iControl7 chnget "Control7"
iControl8 chnget "Control8"
iControl9 chnget "Control9"
iControl10 chnget "Control10"
iControl11 chnget "Control11"
iControl12 chnget "Control12"
iControl13 chnget "Control13"
iControl14 chnget "Control14"
iControl15 chnget "Control15"
iControl16 chnget "Control16"
irootNote chnget "kroot_note"
gkControl1 chnget "Control1"
gkControl2 chnget "Control2"
gkControl3 chnget "Control3"
gkControl4 chnget "Control4"
gkControl5 chnget "Control5"
gkControl6 chnget "Control6"
gkControl7 chnget "Control7"
gkControl8 chnget "Control8"
gkControl9 chnget "Control9"
gkControl10 chnget "Control10"
gkControl11 chnget "Control11"
gkControl12 chnget "Control12"
gkControl13 chnget "Control13"
gkControl14 chnget "Control14"
gkControl15 chnget "Control15"
gkControl16 chnget "Control16"
gkrootNote chnget "kroot_note"
kTime chnget "kTime"
girelease chnget "krelease"
giattack chnget "kattack"
gkvolumefactor chnget "gkvolumefactor"
gkControl1 portk gkControl1, kTime, iControl1
gkControl2 portk gkControl2, kTime, iControl2
gkControl3 portk gkControl3, kTime, iControl3
gkControl4 portk gkControl4, kTime, iControl4
gkControl5 portk gkControl5, kTime, iControl5
gkControl6 portk gkControl6, kTime, iControl6
gkControl7 portk gkControl7, kTime, iControl7
gkControl8 portk gkControl8, kTime, iControl8
gkControl9 portk gkControl9, kTime, iControl9
gkControl10 portk gkControl10, kTime, iControl10
gkControl11 portk gkControl11, kTime, iControl11
gkControl12 portk gkControl12, kTime, iControl12
gkControl13 portk gkControl13, kTime, iControl13
gkControl14 portk gkControl14, kTime, iControl14
gkControl15 portk gkControl15, kTime, iControl15
gkControl16 portk gkControl16, kTime, iControl16
gkrootNote portk gkrootNote, kTime, irootNote
asig, asig2 ins
MixerSetLevel 1, 11, gkvolumefactor
MixerSend asig, 1, 11, 0 ; change first number to be the instrument
number
MixerSend asig2, 1, 11, 1 ; change first number to be the instrument
number
endin
instr 2 ;Effects Scheduler
ktrigger init 0 ;NO INITIAL TRIGGER
gkeffect chnget "gkeffect" ;TURNS ON NEW EFFECT IF CHANGED
ktrigger changed gkeffect ;IF gkeffect CHANGES GENERATE AN TRIGGER IMPULSE
kmintim = 0
kmaxnum = 3
kwhen = 0
kdur = 3600
;START NEW EFFECT
schedkwhen ktrigger, kmintim, kmaxnum, gkeffect, kwhen, kdur
endin
instr 3 ; WAVEGUIDE
;TURNOFF CONDITION
if gkeffect !=3 then
turnoff2 3, 0, 1
endif
;FADING
afade madsr giattack, 0, 1,girelease
;MAPPING
kfl scale gkControl1, 40, 15000
kfr scale gkControl2, 40, 15000
kcol scale gkControl3, 1000, 18000
kcor scale gkControl4, 1000, 18000
kfbl scale gkControl5, 0, 1
kfbr scale gkControl6, 0, 1
;ROUTING
asig MixerReceive 11, 0
asig2 MixerReceive 11, 1
;DSP
a1 wguide1 asig, kfl, kcol, kfbl
a2 wguide1 asig2, kfr, kcor, kfbr
;OUTPUT CALCULATIONS
asigL = a1* afade; FADE
asigR = a2* afade; FADE
outs asigL, asigR
endin
instr 4; PHASER
;TURNOFF CONDITION
if gkeffect !=4 then
turnoff2 4, 0, 1
endif
;FADING
afade madsr giattack, 0, 1, girelease ;FADE ENVELOPE
;MAPPING
kfl scale gkControl1, 40, 15000
kfr scale gkControl2, 40, 15000
kordL scale gkControl3, 2, 80
kordR scale gkControl4, 2, 80
kfbl scale gkControl5, 0, 1
kfbr scale gkControl6, 0, 1
;ROUTING
asig MixerReceive 11, 0
asig2 MixerReceive 11, 1
;DSP
a1 phaser1 asig, kfl, kordL, kfbl
a2 phaser1 asig2, kfr, kordR, kfbr
;OUTPUT CALCULATIONS
asigL = a1* afade; FADE
asigR = a2* afade; FADE
outs asigL, asigR
endin
instr 5; NO PROCESSING
;TURNOFF CONDITION
if gkeffect !=5 then
turnoff2 5, 0, 1
endif
;FADING
afadein linseg 0,giattack,1,1,1 ;FADE IN ENVELOPE
afadeout linsegr 1,girelease,0 ;FADE OUT ENVELOPE
;MAPPING
kfl scale gkControl1, 40, 15000
kfr scale gkControl2, 40, 15000
kordL scale gkControl3, 2, 80
kordR scale gkControl4, 2, 80
kfbl scale gkControl5, 0, 1
kfbr scale gkControl6, 0, 1
;Routing
a1 MixerReceive 11, 0
a2 MixerReceive 11, 1
;DSP
;a1 phaser1 asig, kfl, kordL, kfbl
;a2 phaser1 asig2, kfr, kordR, kfbr
;OUTPUT CALCULATIONS
asigL = a1*afadein*afadeout
asigR = a2*afadein*afadeout
outs asigL, asigR
endin
instr 6; NO PROCESSING
;TURNOFF CONDITION
if gkeffect !=6 then
turnoff2 6, 0, 1
endif
;FADING
afadein linseg 0,giattack,1,1,1 ;FADE IN ENVELOPE
afadeout linsegr 1,girelease,0 ;FADE OUT ENVELOPE
;MAPPING
kfl scale gkControl1, 40, 15000
kfr scale gkControl2, 40, 15000
kordL scale gkControl3, 2, 80
kordR scale gkControl4, 2, 80
kfbl scale gkControl5, 0, 1
kfbr scale gkControl6, 0, 1
;Routing
a1 MixerReceive 11, 0
a2 MixerReceive 11, 1
;DSP
;a1 phaser1 asig, kfl, kordL, kfbl
;a2 phaser1 asig2, kfr, kordR, kfbr
;OUTPUT CALCULATIONS
asigL = a1*afadein*afadeout
asigR = a2*afadein*afadeout
outs asigL, asigR
endin
instr 111 ;Effects output
aOutL MixerReceive 111, 0
aOutR MixerReceive 111, 1
;OUTS AND POSTPROCESSING
denorm aOutL, aOutR
aOutL dcblock2 aOutL
aOutR dcblock2 aOutR
outs aOutL, aOutR
MixerClear
endin
f 0 60000
i 1 0 60000 ; Activate the always-on chnget/input instrument.
i 2 0 60000 ; Activate the always-on scheduler instrument.
i 111 0 60000 ; Activate the always-on mixer out instrument.
e ; indicates the end of the score
UnUnUnium wrote:
>
> Thank you much for this Iain, very helpful. I have implemented this
> technique in my project, but I'm still not able to get sound output.
>
> I have included my .csd just in case I am doing anything really basic
> wrong. If you notice I have commented out the mixer section of the .csd,
> just to simplify things, and directed my effects outs using the "outs"
> opcode. The .csd compiles, and shows to be triggering the correct
> instrument numbers, but the sound never reaches the output. Could it have
> to do with the way I have implemented attack and release?
>
> Cheers, Jeremy
>
> Code follows:
>
>
>
>
>
> sr = 44100
> kr = 441
> ksmps = 100
> nchnls = 2
>
> 0dbfs = 1
>
> chn_k "Control1", 1
> chn_k "Control2", 1
> chn_k "Control3", 1
> chn_k "Control4", 1
> chn_k "Control5", 1
> chn_k "Control6", 1
>
> chn_k "Ktime", 1
> chn_k "kTrigger", 1
> chn_k "gkeffect", 1
> chn_k "kInsnumoff", 1
> chn_k "kattack", 1 ; fade in time
> chn_k "krelease", 1 ;fade out time
> chn_k "gkvolumefactor", 1 ;volume scaler for all effects
> chn_k "kroot_note", 1 ;root note for pitch effects
>
> instr 1
>
> ;control invalues
>
> iControl1 chnget "Control1"
> iControl2 chnget "Control2"
> iControl3 chnget "Control3"
> iControl4 chnget "Control4"
> iControl5 chnget "Control5"
> iControl6 chnget "Control6"
>
> irootNote chnget "kroot_note"
>
>
> gkControl1 chnget "Control1"
> gkControl2 chnget "Control2"
> gkControl3 chnget "Control3"
> gkControl4 chnget "Control4"
> gkControl5 chnget "Control5"
> gkControl6 chnget "Control6"
>
> gkrootNote chnget "kroot_note"
>
> kTime chnget "kTime"
> girelease chnget "krelease"
> giattack chnget "kattack"
> gkvolumefactor chnget "gkvolumefactor"
>
> gkControl1 portk gkControl1, kTime, iControl1
> gkControl2 portk gkControl2, kTime, iControl2
> gkControl3 portk gkControl3, kTime, iControl3
> gkControl4 portk gkControl4, kTime, iControl4
> gkControl5 portk gkControl5, kTime, iControl5
> gkControl6 portk gkControl6, kTime, iControl6
>
> gkrootNote portk gkrootNote, kTime, irootNote
>
> gasig, gasig2 ins
>
> endin
>
> instr 2 ;Effects Scheduler
>
> ktrigger init 0 ;NO INITIAL TRIGGER
>
> gkeffect chnget "gkeffect" ; to turn on new effect
> ktrigger changed gkeffect ;IF gkeffect CHANGES GENERATE AN TRIGGER IMPULSE
>
> kmintim = 0
> kmaxnum = 2
> kwhen = 0
> kdur = 3600
>
> ;start new effect
> schedkwhen ktrigger, kmintim, kmaxnum, gkeffect, kwhen, kdur
>
>
> endin
>
> instr 3 ; WAVEGUIDE
> ;TURNOFF CONDITION
> if gkeffect!=3 then
> turnoff
> endif
> ;FADING
> afadein linseg 0,giattack,1,1,1 ;FADE IN ENVELOPE
> afadeout linsegr 1,girelease,0 ;FADE OUT ENVELOPE
>
> ;MAPPING
> kfl scale gkControl1, 40, 15000
> kfr scale gkControl2, 40, 15000
> kcol scale gkControl3, 1000, 18000
> kcor scale gkControl4, 1000, 18000
> kfbl scale gkControl5, 0, 1
> kfbr scale gkControl6, 0, 1
>
> ;DSP
> a1 wguide1 gasig, kfl, kcol, kfbl
> a2 wguide1 gasig2, kfr, kcor, kfbr
>
> ;OUTPUT CALCULATIONS
> asigL = a1*afadein*afadeout
> asigR = a2*afadein*afadeout
> asigL = asigL * gkvolumefactor ;a factor to scale volume per instance.
> asigR = asigR * gkvolumefactor ;a factor to scale volume per instance.
> ;MixerSend asigL, 3 , 111, 0 ; change first number to be the
> instrument number
> ;MixerSend asigR, 3, 111, 1 ; change first number to be the
> instrument number
> outs asigL, asigR
> endin
>
> instr 4; PHASER
> ;TURNOFF CONDITION
> if gkeffect!=4 then
> turnoff
> endif
> ;FADING
> afadein linseg 0,giattack,1,1,1 ;FADE IN ENVELOPE
> afadeout linsegr 1,girelease,0 ;FADE OUT ENVELOPE
>
> ;MAPPING
> kfl scale gkControl1, 40, 15000
> kfr scale gkControl2, 40, 15000
> kordL scale gkControl3, 2, 80
> kordR scale gkControl4, 2, 80
> kfbl scale gkControl5, 0, 1
> kfbr scale gkControl6, 0, 1
>
> ;DSP
> a12 phaser1 gasig, kfl, kordL, kfbl
> a22 phaser1 gasig2, kfr, kordR, kfbr
>
> ;OUTPUT CALCULATIONS
> asig2L = a12*afadein*afadeout
> asig2R = a22*afadein*afadeout
> asig2L = asig2L * gkvolumefactor ;a factor to scale volume per instance.
> asig2R = asig2R * gkvolumefactor ;a factor to scale volume per instance.
> ;MixerSend asig2L, 4 , 111, 0 ; change first number to be the
> instrument number
> ;MixerSend asig2R, 4, 111, 1 ; change first number to be the
> instrument number
> outs asig2L, asig2R
> endin
>
>
> ;instr 111 ;Effects output
> ;aOutR MixerReceive 111, 0
> ;aOutL MixerReceive 111, 1
>
> ;outs and envs
> ;denorm aOutL, aOutR
> ;aOutL dcblock2 aOutL
> ;aOutR dcblock2 aOutR
> ;outs aOutL, aOutR
> ;MixerClear
> ;endin
>
>
>
>
>
> f 0 60000
> i 1 0 60000 ; Activate the always-on chnget/input instrument.
> i 2 0 60000 ; Activate the always-on scheduler instrument.
> ;i 111 0 60000 ; Activate the always-on mixer out instrument.
> e ; indicates the end of the score
>
>
>
>
>
>
>
> Iain McCurdy wrote:
>>
>>
>> Hi Jeremy,
>>
>> I was needing to do something like this recently and used this sort of
>> approach. The scheduling instrument only turns effects instruments on.
>> The effects instruments themselves deal with turning themselves off.
>> Morphs are dealt with using linsegs and linsegrs. In this example there
>> are effectively 4 instruments: bypass, dry signal out, phaser1 and
>> phaser2.
>> As regards tempo synced effects, I would find it easier to send Csound a
>> tempo variable from which it would create its own lfos for effect
>> modulation.
>> Hope this is helpful, Iain
>>
>>
>> instr 1 ;REGISTERS CHANGES IN EFFECT SELECTION FROM THE SCORE
>> gkeffect init p4
>> endin
>>
>> instr 2 ;SCHEDULES TURNING ON EFFECTS INSTRUMENTS
>> ga1 pinkish 0.1 ;SOME PINK NOISE
>> ktrigger init 0 ;NO INITIAL TRIGGER
>> ktrigger changed gkeffect ;IF gkeffect CHANGES GENERATE AN
>> TRIGGER IMPULSE
>> schedkwhen ktrigger, 0,1,gkeffect+p1+1,0,3600 ;START
>> RELEVANT INSTRUMENT
>> endin
>>
>> instr 3 ;NO EFFECT - BYPASS INSTRUMENT
>> endin
>>
>> instr 4 ;DRY SIGNAL OUT
>> if gkeffect!=1 then
>> turnoff
>> endif
>> afadein linseg 0,0.5,1,1,1 ;FADE IN ENVELOPE
>> afadeout linsegr 1,0.5,0 ;FADE OUT ENVELOPE
>> adry = ga1*afadein*afadeout
>> outs adry, adry
>> endin
>>
>> instr 5 ;PHASER 1
>> if gkeffect!=2 then
>> turnoff
>> endif
>> aphaser phaser1 ga1, 200, 20, 0.9
>> afadein linseg 0,0.5,1,1,1 ;FADE IN ENVELOPE
>> afadeout linsegr 1,0.5,0 ;FADE OUT ENVELOPE
>> aphaser = aphaser*afadein*afadeout
>> outs aphaser, aphaser
>> endin
>>
>> instr 6 ;PHASER 2
>> if gkeffect!=3 then
>> turnoff
>> endif
>> aphaser phaser2 ga1, 500, 3, 8, 2, 0.75, 0.85
>> afadein linseg 0,0.5,1,1,1 ;FADE IN ENVELOPE
>> afadeout linsegr 1,0.5,0 ;FADE OUT ENVELOPE
>> aphaser = aphaser*afadein*afadeout
>> outs aphaser, aphaser
>> endin
>>
>>
>>
>>
>> i 2 0 3600
>> i 1 2 0.01 1 ;TURN ON EFFECT 1 (DRY SIGNAL OUT)
>> i 1 4 0.01 2 ;TURN ON EFFECT 2 (PHASER 1)
>> i 1 6 0.01 3 ;TURN ON EFFECT 3 (PHASER 2)
>> i 1 8 0.01 0 ;TURN ON BYPASS INSTRUMENT
>>
>>
>>
>> Date: Mon, 7 Dec 2009 17:27:42 +0000
>> From: falabala66@gmail.com
>> To: csound@lists.bath.ac.uk
>> Subject: [Csnd] cross fading effects switcher
>>
>> Hello,
>> I am trying to create a crossfading effects switcher that allows me to
>> switch between different predefined processing types in Csound. I am
>> using Schedkwhen and turnoff2 to schedule the turning on and off of
>> several instruments - I have set this up in a discrete, "always on"
>> instrument.
>>
>> It's worth noting that I am to be using this in Max with the Csound~
>> object - but I am still trying to design something that could be used
>> independently of Max. There are two main problems I am having:
>>
>> 1. How do I make it so that Csound switches off the last effect (with a
>> crossfade release time), and turns on the new effect? These effects will
>> be represented by integer numbers (for instance 1 = chorus, 2 =
>> distortion, etc.) - for now I would like it so that only one at a time is
>> on. In max I would do something like storing the last integer, sending
>> that to the "turnoff2" as soon as the number changed, while sending the
>> new number to the "schedkwhen" opcode. I have no idea how to accomplish
>> this in Csound.
>>
>> 2. Many of these effects (not yet built) I am hoping to be tempo
>> synchronised to sources outside of Csound, namely max. I can easily send
>> a string of clicks or a phasor from max (or wherever) into Csound, but
>> how might I use this to synchronise effects like flanger, delay, and
>> tremolo to an external signal? Just looking for some suggestions here.
>>
>> OK - code follows - I have only included the scheduler bit for brevity
>> let me know if more is needed to explain what I am doing. Any suggestions
>> welcome!
>> Best, Jeremy
>>
>> instr 2;Effects Scheduler
>> ktrigger chnget "kTtrigger" ; to trigger (somehow used in conjuntion with
>> kinsum)kinsnum chnget "kInsnum" ; to turn on new effect
>> krelease chnget "krelease" ; release time for turn offkinsnumoff chnget
>> "kinsnumoff" ; to turn off old effect
>> kmintim = 0 kmaxnum = 1 kwhen = 0
>> kdur = 5
>> ;start new effectschedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen,
>> kdur
>> ;release previous effect
>> kmode =1
>> turnoff2 kinsnumoff, kmode, krelease
>> endin
>>
>>
>> _________________________________________________________________
>> View your other email accounts from your Hotmail inbox. Add them now.
>> http://clk.atdmt.com/UKM/go/186394592/direct/01/
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>>
>
> |