<?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>compress2</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="compress.html" title="compress" /> <link rel="next" href="connect.html" title="connect" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">compress2</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="compress.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="connect.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="compress2"></a> <div class="titlepage"></div> <a id="IndexCompress2" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">compress2</span> </h2> <p>compress2 — Compress, limit, expand, duck or gate an audio signal. </p> </div> <div class="refsect1"> <a id="idm281472945729880"></a> <h2>Description</h2> <p> This unit functions as an audio compressor, limiter, expander, or noise gate, using either soft-knee or hard-knee mapping, and with dynamically variable performance characteristics. It takes two audio input signals, <span class="emphasis"><em>aasig</em></span> and <span class="emphasis"><em>acsig</em></span>, the first of which is modified by a running analysis of the second. Both signals can be the same, or the first can be modified by a different controlling signal. </p> <p> <span class="command"><strong>compress2</strong></span> first examines the controlling <span class="emphasis"><em>acsig</em></span> by performing envelope detection. This is directed by two control values <span class="emphasis"><em>katt</em></span> and <span class="emphasis"><em>krel</em></span>, defining the attack and release time constants (in seconds) of the detector. The detector rides the peaks (not the RMS) of the control signal. Typical values are .01 and .1, the latter usually being similar to <span class="emphasis"><em>ilook</em></span>. </p> <p> The running envelope is next converted to decibels, then passed through a mapping function to determine what compresser action (if any) should be taken. The mapping function is defined by four decibel control values. These are given as positive values, where 0 db corresponds to an amplitude of 0dbfs. </p> </div> <div class="refsect1"> <a id="idm281472945653816"></a> <h2>Syntax</h2> <pre class="synopsis">ar <span class="command"><strong>compress2</strong></span> aasig, acsig, kthresh, kloknee, khiknee, kratio, katt, krel, ilook</pre> </div> <div class="refsect1"> <a id="idm281472945651592"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>ilook</em></span> -- lookahead time in seconds, by which an internal envelope release can sense what is coming. This induces a delay between input and output, but a small amount of lookahead improves the performance of the envelope detector. Typical value is .05 seconds, sufficient to sense the peaks of the lowest frequency in <span class="emphasis"><em>acsig</em></span>. </p> </div> <div class="refsect1"> <a id="idm281472945649192"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>kthresh</em></span> -- sets the lowest decibel level that will be allowed through. Normally -90 or less, but if higher the threshold will begin removing low-level signal energy such as background noise. </p> <p> <span class="emphasis"><em>kloknee</em></span>, <span class="emphasis"><em>khiknee</em></span> -- decibel break-points denoting where compression or expansion will begin. These set the boundaries of a soft-knee curve joining the low-amplitude 1:1 line and the higher-amplitude compression ratio line. Typical values are -52 and -30 db. If the two breakpoints are equal, a hard-knee (angled) map will result. </p> <p> <span class="emphasis"><em>kratio</em></span> -- ratio of compression when the signal level is above the knee. The value 2 will advance the output just one decibel for every input gain of two; 3 will advance just one in three; 20 just one in twenty, etc. Inverse ratios will cause signal expansion: .5 gives two for one, .25 four for one, etc. The value 1 will result in no change. </p> <p> The actions of compress2 will depend on the parameter settings given. A hard-knee compressor-limiter, for instance, is obtained from a near-zero attack time, equal-value break-points, and a very high ratio (say 100). A noise-gate plus expander is obtained from some positive threshold, and a fractional ratio above the knee. A voice-activated music compressor (ducker) will result from feeding the music into <span class="emphasis"><em>aasig</em></span> and the speech into <span class="emphasis"><em>acsig</em></span>. A voice de-esser will result from feeding the voice into both, with the <span class="emphasis"><em>acsig</em></span> version being preceded by a band-pass filter that emphasizes the sibilants. Each application will require some experimentation to find the best parameter settings; these have been made k-variable to make this practical. </p> </div> <div class="refsect1"> <a id="idm281472945642248"></a> <h2>Examples</h2> <p> Here is an example of the compress2 opcode. It uses the file <a class="ulink" href="examples/compress2.csd" target="_top"><em class="citetitle">compress2.csd</em></a>. </p> <div class="example"> <a id="idm281472945640392"></a> <p class="title"> <strong>Example 144. Example of the compress2 opcode.</strong> </p> <div class="example-contents"> <div class="refsect1"> <a id="idm281472778907304"></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 -iadc <span class="c1">;;;RT audio out and in</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o compress2.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="kd">instr</span> <span class="nf">1</span> <span class="c1">; uncompressed signal</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 signal.</span> <span class="c1">; Use the "beats.wav" audio file and a mic</span> a<span class="n">voice</span> <span class="nb">in</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="c1">; duck the audio signal "beats.wav" with your voice.</span> k<span class="n">thresh</span> <span class="o">=</span> <span class="o">-</span><span class="mi">90</span> k<span class="n">loknee</span> <span class="o">=</span> <span class="o">-</span><span class="mi">50</span> k<span class="n">hiknee</span> <span class="o">=</span> <span class="o">-</span><span class="mi">30</span> k<span class="n">ratio</span> <span class="o">=</span> <span class="mi">3</span> k<span class="n">att</span> <span class="o">=</span> <span class="mf">0.1</span> k<span class="n">rel</span> <span class="o">=</span> <span class="mf">.5</span> i<span class="n">look</span> <span class="o">=</span> <span class="mf">.02</span> a<span class="n">sig</span> <span class="nb">compress2</span> a<span class="n">sig</span><span class="p">,</span> a<span class="n">voice</span><span class="p">,</span> k<span class="n">thresh</span><span class="p">,</span> k<span class="n">loknee</span><span class="p">,</span> k<span class="n">hiknee</span><span class="p">,</span> k<span class="n">ratio</span><span class="p">,</span> k<span class="n">att</span><span class="p">,</span> k<span class="n">rel</span><span class="p">,</span> i<span class="n">look</span> <span class="c1">; voice-activated compressor</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">5</span> <span class="nb">i</span> <span class="mi">2</span> <span class="mi">6</span> <span class="mi">21</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" /> </p> </div> <div class="refsect1"> <a id="idm281472945638472"></a> <h2>See Also</h2> <p> <a class="link" href="dam.html" title="dam"><em class="citetitle">dam</em></a> </p> <p> <a class="link" href="compress.html" title="compress"><em class="citetitle">compress</em></a> </p> </div> <div class="refsect1"> <a id="idm281472945635176"></a> <h2>Credits</h2> <p>Written by John ffitch after Barry L. Vercoe from Extended but with more common dB values, new in version 6.07. </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="compress.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="connect.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">compress </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> connect</td> </tr> </table> </div> </body> </html>