Sname -- a string that identifies a channel of the named software bus to read.
Sname[] -- an array of named software channels to query.
ival -- the control value read at i-time.
Sval -- the string value read at i-time.
ival[] -- an array of control values read at i-time.
Sval{} -- an array of strings read at i-time.
Performance
kval -- the control value read at performance time.
kval[] -- an array of control values read at performance time.
aval -- the audio signal read at performance time.
aval[] -- the array of audio vectors read at performance time.
Sval -- the string value read at k-rate. The chnget opcode works both at i-time and perf-time, whereas chngetks works only at perf-time. String variables are only updated if the channel has changed.
Note
Although it is possible to loop through channel names from an array with chnget and chnset, using the array based variants is more efficient.
Examples
The example shows the software bus being used as an asynchronous control signal to select a filter cutoff. It assumes that an external program that has access to the API is feeding the values.
<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 chnget.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 chnget opcode. It uses the file chnget.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 chnget.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>