Sname -- a string that indicates which named channel of the software bus to write.
Sname[] -- an array of string that indicates which named channels of the software bus to write to.
ival -- the control value to write at i-time.
ival[] -- an array of control values to write at i-time.
Sval -- the string value to write at i-time.
Sval[] -- an array of string values to write at i-time.
Performance
kval -- the control value to write at performance time.
aval -- the audio signal to write at performance time.
Sval -- the string value to write at perf-time. The opcode chnset with strings works at both i- and perf-time, whereas chnsetks works only a perf-time. Channel contents are only updated if the string variable is modified.
kval[] -- an array of control values to write at performance time.
aval[] -- an array of audio vectors to write at performance time.
Note
Although it is possible to loop through channel names from an array with chnget and chnset, using the array based channel opcodes is more efficient.
Examples
The example shows the software bus being used to write pitch information to a controlling program.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o chnset.wav -W ;;; for file output any platform</CsOptions><CsInstruments>;Example by Joachim Heintzsr=44100ksmps=32nchnls=20dbfs=1instr1; send i-valueschnset(1,"sio")chnset(-1,"non")endininstr2; send k-valuesfreq:k=randomi(100,300,1)chnset(freq,"cntrfreq")bw:k=freq/10chnset(bw,"bandw")endininstr3; send a-valuesnois:a=rand(0.1)chnset(nois,"noise")loop:dur:i=random(0.3,1.5)timout(0,dur,do_)reinit(loop)do_:freq:i=random(400,1200)amp:i=random(0.1,0.3)sig:a=oscils(amp,freq,0)env:a=transeg(1,dur,-10,0)sine:a=sig*envchnset(sine,"sine")endininstr11; receive some chn values and send againval1:i=chnget("sio")val2:i=chnget("non")print(val1,val2)cntfreq:k=chnget("cntrfreq")bandw:k=chnget("bandw")nois:a=chnget("noise")filt:a=reson(nois,cntfreq,bandw)filt=balance(filt,nois)chnset(filt,"filtered")endininstr12; mix the two audio signalsmix1:a=chnget("sine")mix2:a=chnget("filtered")chnmix(mix1,"mix")chnmix(mix2,"mix")endininstr20; receive and reverbmix:a=chnget("mix")aL,aR=freeverb(mix,mix,0.8,0.5)outs(aL,aR)endininstr100; clearchnclear("mix")endin</CsInstruments><CsScore>i1020i2020i3020i11020i12020i20020i100020</CsScore></CsoundSynthesizer>
Here is another example of the chnset opcode. It uses the file chnset.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o chnset.wav -W ;;; for file output any platform</CsOptions><CsInstruments>;Example by Joachim Heintzsr=44100ksmps=32nchnls=20dbfs=1instr1; send i-valueschnset1,"sio"chnset-1,"non"endininstr2; send k-valueskfreqrandomi100,300,1chnsetkfreq,"cntrfreq"kbw=kfreq/10chnsetkbw,"bandw"endininstr3; send a-valuesanoisrand.1chnsetanois,"noise"loop:idurrandom.3,1.5timout0,idur,do_reinitloopdo_:ifreqrandom400,1200iamprandom.1,.3asigoscilsiamp,ifreq,0aenvtranseg1,idur,-10,0asine=asig*aenvchnsetasine,"sine"endininstr11; receive some chn values and send againival1chnget"sio"ival2chnget"non"printival1,ival2kcntfreqchnget"cntrfreq"kbandwchnget"bandw"anoisechnget"noise"afiltresonanoise,kcntfreq,kbandwafiltbalanceafilt,anoisechnsetafilt,"filtered"endininstr12; mix the two audio signalsamix1chnget"sine"amix2chnget"filtered"chnmixamix1,"mix"chnmixamix2,"mix"endininstr20; receive and reverbamixchnget"mix"aL,aRfreeverbamix,amix,.8,.5outsaL,aRendininstr100; clearchnclear"mix"endin</CsInstruments><CsScore>i1020i2020i3020i11020i12020i20020i100020</CsScore></CsoundSynthesizer>