<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Signal Flow Graph Opcodes</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="PartOpcodesOverview.html" title="Part II. Opcodes Overview" /> <link rel="prev" href="MixerOpcodes.html" title="Mixer Opcodes" /> <link rel="next" href="JackoOpcodes.html" title="Jacko Opcodes" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center"> Signal Flow Graph Opcodes </th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="MixerOpcodes.html">Prev</a> </td> <th width="60%" align="center">Part II. Opcodes Overview</th> <td width="20%" align="right"> <a accesskey="n" href="JackoOpcodes.html">Next</a></td> </tr> </table> <hr /> </div> <div class="chapter" title="Signal Flow Graph Opcodes"> <div class="titlepage"> <div> <div> <h2 class="title"><a id="SignalFlowGraphOpcodes"></a> Signal Flow Graph Opcodes </h2> </div> </div> </div> <p> 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, or frate. 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. </p> <p> 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. </p> <p> 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. </p> <p> 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. </p> <p> The signal flow graph opcodes include: <a class="link" href="outleta.html" title="outleta"><em class="citetitle">outleta</em></a>, for sending an arate signal from any instrument out a named port. <a class="link" href="outletk.html" title="outletk"><em class="citetitle">outletk</em></a>, for sending a krate signal from any instrument out a named port. <a class="link" href="outletkid.html" title="outletkid"><em class="citetitle">outletkid</em></a>, similar to outletk, but receiving a krate signal only from an identified instance of a port. <a class="link" href="outletf.html" title="outletf"><em class="citetitle">outletf</em></a>, for sending an frate signal from any instrument out a named port. <a class="link" href="inleta.html" title="inleta"><em class="citetitle">inleta</em></a>, for receiving an arate signal through a named port. <a class="link" href="inletk.html" title="inletk"><em class="citetitle">inletk</em></a>, for receiving a krate signal through a named port. <a class="link" href="inletkid.html" title="inletkid"><em class="citetitle">inletkid</em></a>, similiar to inletk, but transmitting a signal only between inlet and outlet opcodes . <a class="link" href="inletf.html" title="inletf"><em class="citetitle">inletf</em></a>, for receiving an frate signal through a named port. <a class="link" href="connect.html" title="connect"><em class="citetitle">connect</em></a>, for routing the signal from a named outlet in a source instrument to a named inlet in a sink instrument. <a class="link" href="alwayson.html" title="alwayson"><em class="citetitle">alwayson</em></a> 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. <a class="link" href="ftgenonce.html" title="ftgenonce"><em class="citetitle">ftgenonce</em></a> for instantiating function tables from within instrument definitions, without need for f-statements in the score or ftgen opcodes in the orchestra header. </p> <p> 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. </p> <div class="refsect1" title="Example"> <a id="idp12018168"></a> <h2>Example</h2> <p> Here is an example of the signal flow graph opcodes. It uses the file <a class="ulink" href="examples/signalflowgraph.csd" target="_top"><em class="citetitle">signalflowgraph.csd</em></a>. </p> <div class="example"> <a id="idp12019768"></a> <p class="title"> <strong>Example 7. Example of the signal flow graph opcodes.</strong> </p> <div class="example-contents"> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> <span class="comment">; Audio out Audio in No messages</span> -odac -iadc -d <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o madsr.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="op">/</span><span class="op">*</span> Written by Michael Gogins <span class="op">*</span><span class="op">/</span> <span class="comment">; Initialize the global variables.</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 100 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="comment">; Connect up the instruments to create a signal flow graph.</span> <span class="opc">connect</span> "SimpleSine", "leftout", "Reverberator", "leftin" <span class="opc">connect</span> "SimpleSine", "rightout", "Reverberator", "rightin" <span class="opc">connect</span> "Moogy", "leftout", "Reverberator", "leftin" <span class="opc">connect</span> "Moogy", "rightout", "Reverberator", "rightin" <span class="opc">connect</span> "Reverberator", "leftout", "Compressor", "leftin" <span class="opc">connect</span> "Reverberator", "rightout", "Compressor", "rightin" <span class="opc">connect</span> "Compressor", "leftout", "Soundfile", "leftin" <span class="opc">connect</span> "Compressor", "rightout", "Soundfile", "rightin" <span class="comment">; Turn on the "effect" units in the signal flow graph.</span> <span class="opc">alwayson</span> "Reverberator", 0.91, 12000 <span class="opc">alwayson</span> "Compressor" <span class="opc">alwayson</span> "Soundfile" <span class="oblock">instr</span> SimpleSine ihz <span class="op">=</span> <span class="opc">cpsmidinn</span>(p4) iamplitude <span class="op">=</span> <span class="opc">ampdb</span>(p5) <span class="opc">print</span> ihz, iamplitude <span class="comment">; Use ftgenonce instead of ftgen, ftgentmp, or f statement.</span> isine <span class="opc">ftgenonce</span> 0, 0, 4096, 10, 1 a1 <span class="opc">oscili</span> iamplitude, ihz, isine aenv <span class="opc">madsr</span> 0.05, 0.1, 0.5, 0.2 asignal <span class="op">=</span> a1 <span class="op">*</span> aenv <span class="comment">; Stereo audio outlet to be routed in the orchestra header.</span> <span class="opc">outleta</span> "leftout", asignal <span class="op">*</span> 0.25 <span class="opc">outleta</span> "rightout", asignal <span class="op">*</span> 0.75 <span class="oblock">endin</span> <span class="oblock">instr</span> Moogy ihz <span class="op">=</span> <span class="opc">cpsmidinn</span>(p4) iamplitude <span class="op">=</span> <span class="opc">ampdb</span>(p5) <span class="comment">; Use ftgenonce instead of ftgen, ftgentmp, or f statement.</span> isine <span class="opc">ftgenonce</span> 0, 0, 4096, 10, 1 asignal <span class="opc">vco</span> iamplitude, ihz, 1, 0.5, isine kfco <span class="opc">line</span> 200, p3, 2000 krez <span class="opc">init</span> 0.9 asignal <span class="opc">moogvcf</span> asignal, kfco, krez, 100000 <span class="comment">; Stereo audio outlet to be routed in the orchestra header.</span> <span class="opc">outleta</span> "leftout", asignal <span class="op">*</span> 0.75 <span class="opc">outleta</span> "rightout", asignal <span class="op">*</span> 0.25 <span class="oblock">endin</span> <span class="oblock">instr</span> Reverberator <span class="comment">; Stereo input.</span> aleftin <span class="opc">inleta</span> "leftin" arightin <span class="opc">inleta</span> "rightin" idelay <span class="op">=</span> p4 icutoff <span class="op">=</span> p5 aleftout, arightout <span class="opc">reverbsc</span> aleftin, arightin, idelay, icutoff <span class="comment">; Stereo output.</span> <span class="opc">outleta</span> "leftout", aleftout <span class="opc">outleta</span> "rightout", arightout <span class="oblock">endin</span> <span class="oblock">instr</span> Compressor <span class="comment">; Stereo input.</span> aleftin <span class="opc">inleta</span> "leftin" arightin <span class="opc">inleta</span> "rightin" kthreshold <span class="op">=</span> 25000 icomp1 <span class="op">=</span> 0.5 icomp2 <span class="op">=</span> 0.763 irtime <span class="op">=</span> 0.1 iftime <span class="op">=</span> 0.1 aleftout <span class="opc">dam</span> aleftin, kthreshold, icomp1, icomp2, irtime, iftime arightout <span class="opc">dam</span> arightin, kthreshold, icomp1, icomp2, irtime, iftime <span class="comment">; Stereo output.</span> <span class="opc">outleta</span> "leftout", aleftout <span class="opc">outleta</span> "rightout", arightout <span class="oblock">endin</span> <span class="oblock">instr</span> Soundfile <span class="comment">; Stereo input.</span> aleftin <span class="opc">inleta</span> "leftin" arightin <span class="opc">inleta</span> "rightin" <span class="opc">outs</span> aleftin, arightin <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Not necessary to activate "effects" or create f-tables in the score!</span> <span class="comment">; Overlapping notes to create new instances of instruments.</span> <span class="stamnt">i</span> "S<span class="stamnt">i</span>mpleS<span class="stamnt">i</span>ne" 1 5 60 85 <span class="stamnt">i</span> "S<span class="stamnt">i</span>mpleS<span class="stamnt">i</span>ne" 2 5 64 80 <span class="stamnt">i</span> "Moogy" 3 5 67 75 <span class="stamnt">i</span> "Moogy" 4 5 71 70 <span class="stamnt">e</span> 1 <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="MixerOpcodes.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="PartOpcodesOverview.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="JackoOpcodes.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">Mixer Opcodes </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> Jacko Opcodes</td> </tr> </table> </div> </body> </html>