<?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>distort1</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="distort.html" title="distort" /> <link rel="next" href="divz.html" title="divz" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">distort1</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="distort.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="divz.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="distort1"></a> <div class="titlepage"></div> <a id="IndexDistort1" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">distort1</span> </h2> <p>distort1 — Modified hyperbolic tangent distortion. </p> </div> <div class="refsect1"> <a id="idm281472941110504"></a> <h2>Description</h2> <p> Implementation of modified hyperbolic tangent distortion. <span class="emphasis"><em>distort1</em></span> can be used to generate wave shaping distortion based on a modification of the <a class="link" href="tanh.html" title="tanh"><em class="citetitle">tanh</em></a> function. </p> <p> </p> <div class="literallayout"> <p><br /> exp(asig * (shape1 + pregain)) - exp(asig * (shape2 - pregain))<br /> aout = ---------------------------------------------------------------<br /> exp(asig * pregain) + exp(-asig * pregain)<br /> </p> </div> <p> </p> </div> <div class="refsect1"> <a id="idm281472941040360"></a> <h2>Syntax</h2> <pre class="synopsis">ares <span class="command"><strong>distort1</strong></span> asig, kpregain, kpostgain, kshape1, kshape2[, imode]</pre> </div> <div class="refsect1"> <a id="idm281472941038088"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>imode</em></span> (Csound version 5.00 and later only; optional, defaults to 0) -- scales kpregain, kpostgain, kshape1, and kshape2 for use with audio signals in the range -32768 to 32768 (imode=0), -0dbfs to 0dbfs (imode=1), or disables scaling of kpregain and kpostgain and scales kshape1 by kpregain and kshape2 by -kpregain (imode=2). </p> </div> <div class="refsect1"> <a id="idm281472941035784"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>asig</em></span> -- is the input signal. </p> <p> <span class="emphasis"><em>kpregain</em></span> -- determines the amount of gain applied to the signal before waveshaping. A value of 1 gives slight distortion. </p> <p> <span class="emphasis"><em>kpostgain</em></span> -- determines the amount of gain applied to the signal after waveshaping. </p> <p> <span class="emphasis"><em>kshape1</em></span> -- determines the shape of the positive part of the curve. A value of 0 gives a flat clip, small positive values give sloped shaping. </p> <p> <span class="emphasis"><em>kshape2</em></span> -- determines the shape of the negative part of the curve. </p> </div> <div class="refsect1"> <a id="idm281472941029880"></a> <h2>Examples</h2> <p> Here is an example of the distort1 opcode. It uses the file <a class="ulink" href="examples/distort1.csd" target="_top"><em class="citetitle">distort1.csd</em></a>. </p> <div class="example"> <a id="idm281472941028024"></a> <p class="title"> <strong>Example 218. Example of the distort1 opcode.</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="idm281472773852328"></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 distort1.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> ga<span class="n">dist</span> <span class="nb">init</span> <span class="mi">0</span> <span class="kd">instr</span> <span class="nf">1</span> i<span class="n">amp</span> <span class="o">=</span> <span class="nb">p4</span> i<span class="n">fqc</span> <span class="o">=</span> <span class="nb">cpspch</span><span class="p">(</span><span class="nb">p5</span><span class="p">)</span> a<span class="n">sig</span> <span class="nb">pluck</span> i<span class="n">amp</span><span class="p">,</span> i<span class="n">fqc</span><span class="p">,</span> i<span class="n">fqc</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> ga<span class="n">dist</span> <span class="o">=</span> ga<span class="n">dist</span> <span class="o">+</span> a<span class="n">sig</span> <span class="kd">endin</span> <span class="kd">instr</span> <span class="nf">50</span> k<span class="n">pre</span> <span class="nb">init</span> <span class="nb">p4</span> k<span class="n">post</span> <span class="nb">init</span> <span class="nb">p5</span> k<span class="n">shap1</span> <span class="nb">init</span> <span class="nb">p6</span> k<span class="n">shap2</span> <span class="nb">init</span> <span class="nb">p7</span> a<span class="n">out</span> <span class="nb">distort1</span> ga<span class="n">dist</span><span class="p">,</span> k<span class="n">pre</span><span class="p">,</span> k<span class="n">post</span><span class="p">,</span> k<span class="n">shap1</span><span class="p">,</span> k<span class="n">shap2</span><span class="p">,</span> <span class="mi">1</span> <span class="nb">outs</span> a<span class="n">out</span><span class="p">,</span> a<span class="n">out</span> ga<span class="n">dist</span> <span class="o">=</span> <span class="mi">0</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="c1">; Sta Dur Amp Pitch</span> <span class="nb">i</span><span class="mi">1</span> <span class="mf">0.0</span> <span class="mf">3.0</span> <span class="mf">0.5</span> <span class="mf">6.00</span> <span class="nb">i</span><span class="mi">1</span> <span class="mf">0.5</span> <span class="mf">2.5</span> <span class="mf">0.5</span> <span class="mf">7.00</span> <span class="nb">i</span><span class="mi">1</span> <span class="mf">1.0</span> <span class="mf">2.0</span> <span class="mf">0.5</span> <span class="mf">7.07</span> <span class="nb">i</span><span class="mi">1</span> <span class="mf">1.5</span> <span class="mf">1.5</span> <span class="mf">0.5</span> <span class="mf">8.00</span> <span class="c1">; Sta Dur PreGain PostGain Shape1 Shape2</span> <span class="nb">i</span><span class="mi">50</span> <span class="mi">0</span> <span class="mi">4</span> <span class="mi">2</span> <span class="mf">.5</span> <span class="mi">0</span> <span class="mi">0</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="idm281472941023704"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Hans Mikelson</td> </tr> <tr> <td>December 1998</td> </tr> </table> <p> </p> <p>New in Csound version 3.50</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="distort.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="divz.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">distort </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> divz</td> </tr> </table> </div> </body> </html>