<?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>dam</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" /> <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="cuserrnd.html" title="cuserrnd" /> <link rel="next" href="date.html" title="date" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">dam</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="cuserrnd.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="date.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="dam"></a> <div class="titlepage"></div> <a id="IndexDam" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">dam</span> </h2> <p>dam — A dynamic compressor/expander. </p> </div> <div class="refsect1"> <a id="idm281472943280424"></a> <h2>Description</h2> <p> This opcode dynamically modifies a gain value applied to the input sound <span class="emphasis"><em>ain</em></span> by comparing its power level to a given threshold level. The signal will be compressed/expanded with different factors regarding that it is over or under the threshold. </p> </div> <div class="refsect1"> <a id="idm281472943278456"></a> <h2>Syntax</h2> <pre class="synopsis">ares <span class="command"><strong>dam</strong></span> asig, kthreshold, icomp1, icomp2, irtime, iftime</pre> </div> <div class="refsect1"> <a id="idm281472943276216"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>icomp1</em></span> -- compression ratio for upper zone. </p> <p> <span class="emphasis"><em>icomp2</em></span> -- compression ratio for lower zone </p> <p> <span class="emphasis"><em>irtime</em></span> -- gain rise time in seconds. Time over which the gain factor is allowed to raise of one unit. </p> <p> <span class="emphasis"><em>iftime</em></span> -- gain fall time in seconds. Time over which the gain factor is allowed to decrease of one unit. </p> </div> <div class="refsect1"> <a id="idm281472943271448"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>asig</em></span> -- input signal to be modified </p> <p> <span class="emphasis"><em>kthreshold</em></span> -- level of input signal which acts as the threshold. Can be changed at k-time (e.g. for ducking) </p> <p> Note on the compression factors: A compression ratio of one leaves the sound unchanged. Setting the ratio to a value smaller than one will compress the signal (reduce its volume) while setting the ratio to a value greater than one will expand the signal (augment its volume). </p> </div> <div class="refsect1"> <a id="idm281472943267656"></a> <h2>Examples</h2> <p> Because the results of the <span class="emphasis"><em>dam</em></span> opcode can be subtle, I recommend looking at them in a graphical audio editor program like <span class="emphasis"><em>audacity</em></span>. <span class="emphasis"><em>audacity</em></span> is available for Linux, Windows, and the MacOS and may be downloaded from <a class="ulink" href="http://audacity.sourceforge.net/" target="_top"><em class="citetitle">http://audacity.sourceforge.net</em></a>. </p> <p> Here is an example of the dam opcode. It uses the file <a class="ulink" href="examples/dam.csd" target="_top"><em class="citetitle">dam.csd</em></a>, and <a class="ulink" href="examples/beats.wav" target="_top"><em class="citetitle">beats.wav</em></a>. </p> <div class="example"> <a id="idm281472943262264"></a> <p class="title"> <strong>Example 179. An example of the dam opcode compressing an audio signal.</strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <div class="refsect1"> <a id="idm281472776249912"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;RT audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if RT audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o dam.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="kd">instr</span> <span class="nf">1</span> <span class="c1">;normal audio</span> a<span class="n">sig</span> <span class="nb">diskin2</span> <span class="s">"beats.wav"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="nb">outs</span> a<span class="n">sig</span><span class="p">,</span> a<span class="n">sig</span> <span class="kd">endin</span> <span class="kd">instr</span> <span class="nf">2</span> <span class="c1">; compressed audio</span> k<span class="n">threshold</span> <span class="o">=</span> <span class="mf">0.2</span> i<span class="n">comp1</span> <span class="o">=</span> <span class="mf">0.8</span> i<span class="n">comp2</span> <span class="o">=</span> <span class="mf">0.2</span> i<span class="n">rtime</span> <span class="o">=</span> <span class="mf">0.01</span> i<span class="n">ftime</span> <span class="o">=</span> <span class="mf">0.5</span> a<span class="n">sig</span> <span class="nb">diskin2</span> <span class="s">"beats.wav"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> a<span class="n">sig</span> <span class="nb">dam</span> a<span class="n">sig</span><span class="p">,</span> k<span class="n">threshold</span><span class="p">,</span> i<span class="n">comp1</span><span class="p">,</span> i<span class="n">comp2</span><span class="p">,</span> i<span class="n">rtime</span><span class="p">,</span> i<span class="n">ftime</span> <span class="nb">outs</span> a<span class="n">sig</span><span class="p">,</span> a<span class="n">sig</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">i</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">2</span> <span class="nb">i</span> <span class="mi">2</span> <span class="mf">2.5</span> <span class="mf">8.5</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> This example compresses the audio file <span class="quote">“<span class="quote">beats.wav</span>”</span>. You should hear a drum pattern repeat twice. The second time, the sound should be quieter (compressed) than the first. </p> <p> Here is another example of the dam opcode. It uses the file <a class="ulink" href="examples/dam_expanded.csd" target="_top"><em class="citetitle">dam_expanded.csd</em></a>, and <a class="ulink" href="examples/beats.wav" target="_top"><em class="citetitle">beats.wav</em></a>. </p> <div class="example"> <a id="idm281472943255304"></a> <p class="title"> <strong>Example 180. An example of the dam opcode expanding an audio signal.</strong> </p> <div class="example-contents"> <div class="refsect1"> <a id="idm281472776303768"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;RT audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if RT audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o dam_expanded.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="kd">instr</span> <span class="nf">1</span> a<span class="n">sig</span> <span class="nb">diskin2</span> <span class="s">"beats.wav"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="nb">outs</span> a<span class="n">sig</span><span class="p">,</span> a<span class="n">sig</span> <span class="kd">endin</span> <span class="kd">instr</span> <span class="nf">2</span> <span class="c1">;expanded audio</span> k<span class="n">threshold</span> <span class="o">=</span> <span class="mf">.5</span> i<span class="n">comp1</span> <span class="o">=</span> <span class="mi">2</span> i<span class="n">comp2</span> <span class="o">=</span> <span class="mi">3</span> i<span class="n">rtime</span> <span class="o">=</span> <span class="mf">0.01</span> i<span class="n">ftime</span> <span class="o">=</span> <span class="mf">0.1</span> a<span class="n">sig</span> <span class="nb">diskin2</span> <span class="s">"beats.wav"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> a<span class="n">sig</span> <span class="nb">dam</span> a<span class="n">sig</span><span class="p">,</span> k<span class="n">threshold</span><span class="p">,</span> i<span class="n">comp1</span><span class="p">,</span> i<span class="n">comp2</span><span class="p">,</span> i<span class="n">rtime</span><span class="p">,</span> i<span class="n">ftime</span> <span class="nb">outs</span> a<span class="n">sig</span><span class="o">*</span><span class="mf">.2</span><span class="p">,</span> a<span class="n">sig</span><span class="o">*</span><span class="mf">.2</span> <span class="c1">;adjust volume of expanded beat</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">i</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">2</span> <span class="nb">i</span> <span class="mi">2</span> <span class="mf">2.5</span> <span class="mf">6.5</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> This example expands the audio file <span class="quote">“<span class="quote">beats.wav</span>”</span>. You should hear a drum pattern repeat twice. The second time, the sound should be louder (expanded) than the first. To prevent distortion the volume of the signal has been lowered. </p> </div> <div class="refsect1"> <a id="idm281472943252504"></a> <h2>See Also</h2> <p> <a class="link" href="compress.html" title="compress"><em class="citetitle">compress</em></a> </p> </div> <div class="refsect1"> <a id="idm281472943250360"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Marc Resibois</td> </tr> <tr> <td>Belgium</td> </tr> <tr> <td>1997</td> </tr> </table> <p> </p> <p>New in version 3.47</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="cuserrnd.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="date.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">cuserrnd </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> date</td> </tr> </table> </div> </body> </html>