Signal Flow Graph Opcodes

These opcodes enable the use of signal flow graphs (AKA asynchronous data flow graphs) in Csound orchestras. Signals flow from the outlets of source instruments and are summed in the inlets of sink instruments. Signals may be krate, arate, frate, or arate arrays. Any number of outlets may be connected to any number of inlets. When a new instance of an instrument is instantiated during performance, the declared connections also are automatically instantiated.

Signal flow graphs simplify the construction of complex mixers, signal processing chains, and the like. They also simplify the re-use of "plug and play" instrument definitions and even entire sub-orchestras, which can simply be #included and then "plugged in" to existing orchestras.

Note that inlets and outlets are defined in instruments without reference to how they are connected. Connections are defined in the orchestra header. It is this separation that enables plug-in instruments.

Inlets must be named. Instruments may be named or numbered, but in either case each source instrument must be defined in the orchestra before any of its sinks. Naming instruments makes it easier to connect outlets and inlets in any higher-level orchestra to inlets and outlets in any lower-level #included orchestra.

The signal flow graph opcodes include: outleta, for sending an arate signal from any instrument out a named port. outletk, for sending a krate signal from any instrument out a named port. outletkid, similar to outletk, but receiving a krate signal only from an identified instance of a port. outletf, for sending an frate signal from any instrument out a named port. outletv, for sending an arate array signal from any instrument out a named port. inleta, for receiving an arate signal through a named port. inletk, for receiving a krate signal through a named port. inletkid, similiar to inletk, but transmitting a signal only between inlet and outlet opcodes . inletf, for receiving an frate signal through a named port. inletv, for receiving an arate array signal through a named port. connect, for routing the signal from a named outlet in a source instrument to a named inlet in a sink instrument. alwayson for permanently activating an instrument from the orchestra header, without need of a score statement, e.g. for use as an effect processor receiving inputs from a number of sources. ftgenonce for instantiating function tables from within instrument definitions, without need for f-statements in the score or ftgen opcodes in the orchestra header.

A typical scenario for the use of these opcodes would be something like this. A set of instruments would be defined, each in its own orchestra file, and each instrument would define inlet ports, outlet ports, and function tables within itself. Such instruments are completely self-contained. Then, a set of effects processors, such as equalizers, reverbs, compressors, and so on, would also be defined, each in its own file. Then, a customized master orchestra would #include the instruments and effects to be used, route the outputs of some instruments into one equalizer and the outputs of other effects into another equalizer, then route the outputs of both equalizers into a reverb, the output of the reverb into a compressor, and the output of the compressor into a stereo output soundfile.

Example

Here is an example of the signal flow graph opcodes. Play signalflowgraph.csd

Example 6. Example of the signal flow graph opcodes.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o madsr.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

/* Written by Michael Gogins */
; Initialize the global variables.
sr = 44100
ksmps = 100
nchnls = 2

; Connect up the instruments to create a signal flow graph.

connect "SimpleSine",   "leftout",     "Reverberator",     	"leftin"
connect "SimpleSine",   "rightout",    "Reverberator",     	"rightin"

connect "Moogy",        "leftout",     "Reverberator",     	"leftin"
connect "Moogy",        "rightout",    "Reverberator",     	"rightin"

connect "Reverberator", "leftout",     "Compressor",       	"leftin"
connect "Reverberator", "rightout",    "Compressor",       	"rightin"

connect "Compressor",   "leftout",     "Soundfile",       	"leftin"
connect "Compressor",   "rightout",    "Soundfile",       	"rightin"

; Turn on the "effect" units in the signal flow graph.

alwayson "Reverberator", 0.91, 12000
alwayson "Compressor"
alwayson "Soundfile"

instr SimpleSine
  ihz = cpsmidinn(p4)
  iamplitude = ampdb(p5)
  print ihz, iamplitude
  ; Use ftgenonce instead of ftgen, ftgentmp, or f statement.
  isine ftgenonce 0, 0, 4096, 10, 1
  a1 oscili iamplitude, ihz, isine
  aenv madsr 0.05, 0.1, 0.5, 0.2
  asignal = a1 * aenv
  ; Stereo audio outlet to be routed in the orchestra header.
  outleta "leftout", asignal * 0.25
  outleta "rightout", asignal * 0.75
endin

instr Moogy
  ihz = cpsmidinn(p4)
  iamplitude = ampdb(p5)
  ; Use ftgenonce instead of ftgen, ftgentmp, or f statement.
  isine ftgenonce 0, 0, 4096, 10, 1
  asignal vco iamplitude, ihz, 1, 0.5, isine
  kfco line 200, p3, 2000
  krez init 0.9
  asignal moogvcf asignal, kfco, krez, 100000
  ; Stereo audio outlet to be routed in the orchestra header.
  outleta "leftout", asignal * 0.75
  outleta "rightout", asignal * 0.25
endin

instr Reverberator
  ; Stereo input.
  aleftin inleta "leftin"
  arightin inleta "rightin"
  idelay = p4
  icutoff = p5
  aleftout, arightout reverbsc aleftin, arightin, idelay, icutoff
  ; Stereo output.
  outleta "leftout", aleftout
  outleta "rightout", arightout 
endin

instr Compressor
  ; Stereo input.
  aleftin inleta "leftin"
  arightin inleta "rightin"
  kthreshold = 25000
  icomp1 = 0.5
  icomp2 = 0.763
  irtime = 0.1
  iftime = 0.1
  aleftout dam aleftin, kthreshold, icomp1, icomp2, irtime, iftime
  arightout dam arightin, kthreshold, icomp1, icomp2, irtime, iftime
  ; Stereo output.
  outleta "leftout", aleftout 
  outleta "rightout", arightout 
endin

instr Soundfile
  ; Stereo input.
  aleftin inleta "leftin"
  arightin inleta "rightin"
  outs aleftin, arightin
endin

</CsInstruments>
<CsScore>
; Not necessary to activate "effects" or create f-tables in the score!
; Overlapping notes to create new instances of instruments.
i "SimpleSine" 1 5 60 85
i "SimpleSine" 2 5 64 80
i "Moogy" 3 5 67 75
i "Moogy" 4 5 71 70
e 1
</CsScore>
</CsoundSynthesizer>