summaryrefslogtreecommitdiff
path: root/opcodes/madsr.xml
blob: 7a24013be8494ced94d56e483d00c5b90b1e5cbf (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
<refentry id="madsr">
<indexterm id="IndexMadsr"><primary>madsr</primary></indexterm>
  <refentryinfo><title>Signal Generators:Envelope Generators</title></refentryinfo>
  <refmeta>
    <refentrytitle>madsr</refentrytitle>
  </refmeta>

  <refnamediv>
    <refname>madsr</refname>
    <refpurpose>
      Calculates the classical ADSR envelope using the <emphasis>linsegr</emphasis> mechanism.
    </refpurpose>
  </refnamediv>

  <refsect1>
    <title>Description</title>
    <para>
      Calculates the classical ADSR envelope using the <link linkend="linsegr"><citetitle>linsegr</citetitle></link> mechanism.
   </para>
  </refsect1>

  <refsect1>
    <title>Syntax</title>
    <synopsis>ares <command>madsr</command> iatt, idec, islev, irel [, idel] [, ireltim]</synopsis>

    <synopsis>kres <command>madsr</command> iatt, idec, islev, irel [, idel] [, ireltim]</synopsis>
  </refsect1>

  <refsect1>
    <title>Initialization</title>
    <para>
      <emphasis>iatt</emphasis> -- duration of attack phase
    </para>

    <para>
      <emphasis>idec</emphasis> -- duration of decay
    </para>

    <para>
      <emphasis>islev</emphasis> -- level for sustain phase
    </para>

    <para>
      <emphasis>irel</emphasis> -- duration of release phase. 
    </para>

    <para>
      <emphasis>idel</emphasis> -- period of zero before the envelope starts
    </para>

    <para>
      <emphasis>ireltim</emphasis> (optional, default=-1) -- Control release time after receiving a MIDI noteoff event. If less than zero, the longest release time given in the current instrument is used. If zero or more, the given value will be used for release time. Its default value is -1. (New in Csound 3.59 - not yet properly tested)
    </para>

    <para>
      Please note that the release time cannot be longer than 32767/<link linkend="kr"><citetitle>kr</citetitle></link> seconds.
    </para>
  </refsect1>

  <refsect1>
    <title>Performance</title>
    <para>
      The envelope is in the range 0 to 1 and may need to be scaled further. The envelope may be described as:

      <mediaobject>
        <imageobject>
          <imagedata fileref="images/adsr.png" format="PNG"/>
        </imageobject>

        <textobject>
          <phrase>Picture of an ADSR envelope.</phrase>
        </textobject>
        <caption>
          <para>Picture of an ADSR envelope.</para>
        </caption>
      </mediaobject>
    </para>

    <para>
      The length of the sustain is calculated from the length of the note. This means <link linkend="adsr"><citetitle>adsr</citetitle></link> is not suitable for use with MIDI events. The opcode <emphasis>madsr</emphasis> uses the <link linkend="linsegr"><citetitle>linsegr</citetitle></link> mechanism, and so can be used in MIDI applications.
    </para>
    <para>
      You can use other pre-made envelopes which start a release segment upon recieving a note off message, like <link linkend="linsegr"><citetitle>linsegr</citetitle></link> and <link linkend="expsegr"><citetitle>expsegr</citetitle></link>, or you can construct more complex envelopes using <link linkend="xtratim"><citetitle>xtratim</citetitle></link> and <link linkend="release"><citetitle>release</citetitle></link>. Note that you don't need to use <link linkend="xtratim"><citetitle>xtratim</citetitle></link> if you are using <emphasis>madsr</emphasis>, since the time is extended automatically.
    </para>
    <note>
      <para> Times for <emphasis>iatt</emphasis>, <emphasis>idec</emphasis> and <emphasis>irel</emphasis> cannot be 0. If 0 is used, no envelope is generated. Use a very small value like 0.0001 if you need an instantaneous attack, decay or release.
      </para>
    </note>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the madsr opcode. It uses the file <ulink url="examples/madsr.csd"><citetitle>madsr.csd</citetitle></ulink>.

      <example>
        <title>Example of the madsr 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/madsr.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
      </example>
    </para>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="expsegr"><citetitle>linsegr</citetitle></link>,
      <link linkend="linenr"><citetitle>expsegr</citetitle></link>,
      <link linkend="envlpxr"><citetitle>envlpxr</citetitle></link>,
      <link linkend="mxadsr"><citetitle>mxadsr</citetitle></link>,
      <link linkend="adsr"><citetitle>madsr</citetitle></link>,
      <link linkend="xadsr"><citetitle>xadsr</citetitle></link>
      <link linkend="expon"><citetitle>expon</citetitle></link>,
      <link linkend="expseg"><citetitle>expseg</citetitle></link>,
      <link linkend="expsega"><citetitle>expsega</citetitle></link>
      <link linkend="line"><citetitle>line</citetitle></link>,
      <link linkend="linseg"><citetitle>linseg</citetitle></link>,
      <link linkend="xtratim"><citetitle>xtratim</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>Author: &namejohn;</para>
    <para>November 2002. Thanks to &namerasmus;, added documentation for the <emphasis>ireltim</emphasis> parameter.</para>
    <para>December 2002. Thanks to Iain McCurdy, added an example.</para>
    <para>December 2002. Thanks to &nameistvan;, added documentation about the maximum release time.</para>
    <para>New in Csound version 3.49.</para>
  </refsect1>
</refentry>