summaryrefslogtreecommitdiff
path: root/opcodes/clip.xml
blob: 68e136c1c48b026fc549e5e3c8b549979323d01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<refentry id="clip">
<indexterm id="IndexClip"><primary>clip</primary></indexterm>
  <refentryinfo><title>Signal Modifiers:Amplitude Modifiers</title></refentryinfo>
  <refmeta>
    <refentrytitle>clip</refentrytitle>
  </refmeta>


 
  <refnamediv>
    <refname>clip</refname>
    <refpurpose>
      Clips a signal to a predefined limit.
          </refpurpose>
  </refnamediv>
 
  <refsect1>
    <title>Description</title>
    <para>
      Clips an a-rate signal to a predefined limit, in a <quote>soft</quote> manner, using one of three methods.
   </para>
  </refsect1>
 
  <refsect1>
    <title>Syntax</title>
    <synopsis>ares <command>clip</command> asig, imeth, ilimit [, iarg]</synopsis>
  </refsect1>
 
  <refsect1>
    <title>Initialization</title>
    <para>
      <emphasis>imeth</emphasis> -- selects the clipping method. The default is 0. The methods are:
      <itemizedlist>
        <listitem>
            <para>0 = Bram de Jong method (default)</para>
        </listitem>

        <listitem>
            <para>1 = sine clipping</para>
        </listitem>

        <listitem>
            <para>2 = tanh clipping</para>
        </listitem>
      </itemizedlist>
    </para>

    <para>
      <emphasis>ilimit</emphasis> -- limiting value
    </para>

    <para>
      <emphasis>iarg</emphasis> (optional, default=0.5) -- when <emphasis>imeth</emphasis> = 0, indicates the point at which clipping starts, in the range 0 - 1. Not used when <emphasis>imeth</emphasis> = 1 or <emphasis>imeth</emphasis> = 2. Default is 0.5.
    </para>
  </refsect1>
 
  <refsect1>
    <title>Performance</title>
    <para>
      <emphasis>asig</emphasis> -- a-rate input signal
    </para>

    <para>
      The Bram de Jong method (<emphasis>imeth</emphasis> = 0) applies the algorithm:
    </para>

    <para>
      <informalexample>
        <programlisting>
|<emphasis>x</emphasis>| &gt; <emphasis>a</emphasis>:     f(<emphasis>x</emphasis>) = sin(<emphasis>x</emphasis>) * (a+(<emphasis>x-a</emphasis>)/(1+((<emphasis>x-a</emphasis>)/(1-<emphasis>a</emphasis>))<superscript>2</superscript> |<emphasis>x</emphasis>| &gt; 1: f(<emphasis>x</emphasis>) = sin(<emphasis>x</emphasis>) * (<emphasis>a</emphasis>+1)/2
        </programlisting>
      </informalexample>
    </para>

    <para>
      This method requires that <emphasis>asig</emphasis> be normalized to 1.
    </para>

    <para>
      The second method (<emphasis>imeth</emphasis> = 1) is the sine clip:
    </para>

    <para>
      <informalexample>
        <programlisting>
|<emphasis>x</emphasis>| &lt; <emphasis>limit</emphasis>: f(<emphasis>x</emphasis>) = <emphasis>limit</emphasis> * sin(&pi;*<emphasis>x</emphasis>/(2*<emphasis>limit</emphasis>)) f(<emphasis>x</emphasis>) = <emphasis>limit</emphasis> * sin(<emphasis>x</emphasis>)
        </programlisting>
      </informalexample>
    </para>

    <para>
      The third method (imeth = 3) is the tanh clip:
    </para>

    <para>
      <informalexample>
        <programlisting>
|<emphasis>x</emphasis>| &lt; <emphasis>limit</emphasis>: f(<emphasis>x</emphasis>) = <emphasis>limit</emphasis> * tanh(<emphasis>x/limit</emphasis>)/tanh(1) f(<emphasis>x</emphasis>) = <emphasis>limit</emphasis> * sin(<emphasis>x</emphasis>)
        </programlisting>
      </informalexample>
    </para>

    <note>
      <title>Note</title>
      <para>
        Method 1 appears to be non-functional at release of Csound version 4.07.
      </para>
    </note>
  </refsect1>
 
  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the clip opcode. It uses the file <ulink url="examples/clip.csd"><citetitle>clip.csd</citetitle></ulink>.

      <example>
        <title>Example of the clip opcode.</title>

        

        <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>
          <xi:include href="examples-xml/clip.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      </example>
    </para>
  </refsect1>
 
  <refsect1>
    <title>Credits</title>
    <para>
      <simplelist>
        <member>Author: &namejohn;</member>
        <member>University of Bath, Codemist Ltd.</member>
        <member>Bath, UK</member>
        <member>August, 2000</member>
      </simplelist>
    </para>

    <para>New in Csound version 4.07</para>
  </refsect1>
</refentry>