chnset — Writes data to the named software bus.


Write to a channel of the named software bus. Implies declaring the channel with imod=2 (see also chn_k, chn_a, and chn_S).


chnset ival, Sname
chnset kval, Sname
chnset aval, Sname
chnset Sval, Sname
chnsetks Sval, Sname


Sname -- a string that indicates which named channel of the software bus to write.

ival -- the control value to write at i-time.

Sval -- the string value to write at i-time.


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.


The example shows the software bus being used to write pitch information to a controlling program.

        sr = 44100
        kr = 100
        ksmps = 1

        instr   1
           a1    in
           kp,ka pitchamdf a1
                 chnset    kp, "pitch"

Here is another example of the chnset opcode. It uses the file chnset.csd.

Example 129. Example of the chnset opcode.

; 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
;Example by Joachim Heintz
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

  instr 1; send i-values
          chnset    1, "sio"
          chnset    -1, "non"

  instr 2; send k-values
kfreq     randomi   100, 300, 1
          chnset    kfreq, "cntrfreq"
kbw       =         kfreq/10
          chnset    kbw, "bandw"

  instr 3; send a-values
anois     rand      .1
          chnset    anois, "noise"
idur      random    .3, 1.5
          timout    0, idur, do
          reinit    loop
ifreq     random    400, 1200
iamp      random    .1, .3
asig      oscils    iamp, ifreq, 0
aenv      transeg   1, idur, -10, 0
asine     =         asig * aenv
          chnset    asine, "sine"

  instr 11; receive some chn values and send again
ival1     chnget    "sio"
ival2     chnget    "non"
          print     ival1, ival2
kcntfreq  chnget    "cntrfreq"
kbandw    chnget    "bandw"
anoise    chnget    "noise"
afilt     reson     anoise, kcntfreq, kbandw
afilt     balance   afilt, anoise
          chnset    afilt, "filtered"

  instr 12; mix the two audio signals
amix1     chnget     "sine"
amix2     chnget     "filtered"
          chnmix     amix1, "mix"
          chnmix     amix2, "mix"

  instr 20; receive and reverb
amix      chnget     "mix"
aL, aR    freeverb   amix, amix, .8, .5
          outs       aL, aR

  instr 100; clear
          chnclear   "mix"

i 1 0 20
i 2 0 20
i 3 0 20
i 11 0 20
i 12 0 20
i 20 0 20
i 100 0 20


Author: Istvan Varga