| 1 | |
| 2 | <refentry id="distort"> |
| 3 | <indexterm id="IndexDistort"><primary>distort</primary></indexterm> |
| 4 | <refentryinfo><title>Signal Modifiers:Special Effects</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>distort</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | <refnamediv> |
| 10 | <refname>distort</refname> |
| 11 | <refpurpose> |
| 12 | Distort an audio signal via waveshaping and optional clipping. |
| 13 | </refpurpose> |
| 14 | </refnamediv> |
| 15 | |
| 16 | <refsect1> |
| 17 | <title>Description</title> |
| 18 | <para> |
| 19 | Distort an audio signal via waveshaping and optional clipping. |
| 20 | </para> |
| 21 | </refsect1> |
| 22 | |
| 23 | <refsect1> |
| 24 | <title>Syntax</title> |
| 25 | <synopsis>ar <command>distort</command> asig, kdist, ifn[, ihp, istor]</synopsis> |
| 26 | </refsect1> |
| 27 | |
| 28 | <refsect1> |
| 29 | <title>Initialization</title> |
| 30 | <para> |
| 31 | <emphasis>ifn</emphasis> -- table number of a waveshaping |
| 32 | function with extended guard point. The function can be of any |
| 33 | shape, but it should pass through 0 with positive slope at the |
| 34 | table mid-point. The table size need not be large, since it is |
| 35 | read with interpolation. |
| 36 | </para> |
| 37 | <para> |
| 38 | <emphasis>ihp</emphasis> -- (optional) half-power point (in cps) |
| 39 | of an internal low-pass filter. The default value is 10. |
| 40 | </para> |
| 41 | <para> |
| 42 | <emphasis>istor</emphasis> -- (optional) initial disposition of |
| 43 | internal data space (see reson). The default value is 0. |
| 44 | </para> |
| 45 | </refsect1> |
| 46 | |
| 47 | <refsect1> |
| 48 | <title>Performance</title> |
| 49 | <para> |
| 50 | <emphasis>asig</emphasis> -- Audio signal to be processed |
| 51 | </para> |
| 52 | <para> |
| 53 | <emphasis>kdist</emphasis> -- Amount of distortion (usually between 0 and |
| 54 | 1) |
| 55 | </para> |
| 56 | <para> |
| 57 | This unit distorts an incoming signal using a waveshaping function |
| 58 | <emphasis>ifn</emphasis> and a distortion index |
| 59 | <emphasis>kdist</emphasis>. The input signal is first compressed using a |
| 60 | running rms, then passed through a waveshaping function which may modify |
| 61 | its shape and spectrum. Finally it is rescaled to approximately its |
| 62 | original power. |
| 63 | </para> |
| 64 | <para> |
| 65 | The amount of distortion depends on the nature of the shaping function |
| 66 | and on the value of <emphasis>kdist</emphasis>, which generally ranges |
| 67 | from 0 to 1. For low values of <emphasis>kdist</emphasis>, we should like |
| 68 | the shaping function to pass the signal almost unchanged. This will be |
| 69 | the case if, at the mid-point of the table, the shaping function is |
| 70 | near-linear and is passing through 0 with positive slope. A line function |
| 71 | from -1 to +1 will satisfy this requirement; so too will a sigmoid |
| 72 | (sinusoid from 270 to 90 degrees). As <emphasis>kdist</emphasis> is |
| 73 | increased, the compressed signal is expanded to encounter more and more |
| 74 | of the shaping function, and if this becomes non-linear the signal is |
| 75 | increasingly <emphasis>bent</emphasis> on read-through to cause |
| 76 | distortion. |
| 77 | </para> |
| 78 | <para> |
| 79 | When <emphasis>kdist</emphasis> becomes large enough, the read-through process will |
| 80 | eventually hit the outer limits of the table. The table is not |
| 81 | read with wrap-around, but will <quote>stick</quote> at the end-points as the |
| 82 | incoming signal exceeds them; this introduces clipping, an |
| 83 | additional form of signal distortion. The point at which clipping |
| 84 | begins will depend on the complexity (rms-to-peak value) of the |
| 85 | input signal. For a pure sinusoid, clipping will begin only as |
| 86 | <emphasis>kdist</emphasis> exceeds 0.7; for a more complex input, clipping might begin |
| 87 | at a <emphasis>kdist</emphasis> of 0.5 or much less. <emphasis>kdist</emphasis> can exceed |
| 88 | the clip point by any amount, and may be greater than 1. |
| 89 | </para> |
| 90 | <para> |
| 91 | The shaping function can be made arbitrarily complex for extra effect. |
| 92 | It should generally be continuous, though this is not a |
| 93 | requirement. It should also be well-behaved near the mid-point, |
| 94 | and roughly balanced positive-negative overall, else some |
| 95 | excessive DC offset may result. The user might experiment with |
| 96 | more aggressive functions to suit the purpose. A generally |
| 97 | positive slope allows the distorted signal to be mixed with the |
| 98 | source without phase cancellation. |
| 99 | </para> |
| 100 | <para> |
| 101 | <emphasis>distort</emphasis> is useful as an effects process, and is usually combined with |
| 102 | reverb and chorusing on effects busses. However, it can |
| 103 | alternatively be used to good effect within a single instrument. |
| 104 | </para> |
| 105 | </refsect1> |
| 106 | |
| 107 | <refsect1> |
| 108 | <title>Examples</title> |
| 109 | <para> |
| 110 | Here is an example of the distort opcode. It uses the file <ulink url="examples/distort.csd"><citetitle>distort.csd</citetitle></ulink>. |
| 111 | |
| 112 | <example> |
| 113 | <title>Example of the distort opcode.</title> |
| 114 | |
| 115 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 116 | <xi:include href="examples-xml/distort.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 117 | </example> |
| 118 | </para> |
| 119 | </refsect1> |
| 120 | |
| 121 | <refsect1> |
| 122 | <title>See also</title> |
| 123 | <para><link linkend="SigmodSpeciale"><citetitle>Special Effects</citetitle></link></para> |
| 124 | <para><link linkend="SigmodWavshape"><citetitle>Waveshaping</citetitle></link></para> |
| 125 | </refsect1> |
| 126 | |
| 127 | |
| 128 | <refsect1> |
| 129 | <title>Credits</title> |
| 130 | <para>Written by &namebarry; for Extended Csound and released in Csound5.</para> |
| 131 | </refsect1> |
| 132 | </refentry> |