summaryrefslogtreecommitdiff
path: root/opcodes/octmidinn.xml
blob: 0aac095dca9f74501fe732728513c3869d44ab5a (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
142
143
144
145
146
147
148
<refentry id="octmidinn">
<indexterm id="IndexOctmidinn"><primary>octmidinn</primary></indexterm>
  <refentryinfo><title>Pitch Converters:Functions</title></refentryinfo>
  <refmeta>
    <refentrytitle>octmidinn</refentrytitle>
  </refmeta>


 
  <refnamediv>
    <refname>octmidinn</refname>

    <refpurpose>
      Converts a Midi note number value to octave-point-decimal.
    </refpurpose>
  </refnamediv>

 
  <refsect1>
    <title>Description</title>
    <para>
      Converts a Midi note number value to octave-point-decimal.
    </para>
  </refsect1>
 
  <refsect1>
    <title>Syntax</title>
    <synopsis><command>octmidinn</command> (MidiNoteNumber)  (init- or control-rate args only)</synopsis>

    <para>
      where the argument within the parentheses may be a further expression.
    </para>
  </refsect1>
 
  <refsect1>
    <title>Performance</title>
    <para>
      <emphasis>octmidinn</emphasis> is a function that takes an i-rate or k-rate value representing a Midi note number and returns the equivalent pitch value in Csound's octave-point-decimal format. This conversion assumes that Middle C (8.000 in <emphasis>oct</emphasis>) is Midi note number 60. Midi note number values are typically integers in the range from 0 to 127 but fractional values or values outside of this range will be interpreted consistently.
    </para>

    <note>
      <title>octmidinn vs. octmidi</title>
      <para>
        The <emphasis>octmidinn</emphasis> opcode may be used in any Csound instrument instance whether it is activated from a Midi event, score event, line event, or from another instrument.  The input value for <emphasis>octmidinn</emphasis> might for example come from a p-field in a textual score or it may have been retrieved from the real-time Midi event that activated the current note using the <link linkend="notnum"><citetitle>notnum</citetitle></link> opcode.  You must specify an i-rate or k-rate expression for the Midi note number that is to be converted.  On the other hand, the <link linkend="octmidi"><citetitle>octmidi</citetitle></link> opcode only produces meaningful results in a Midi-activated note (either real-time or from a Midi score with the -F flag).  With <link linkend="octmidi"><citetitle>octmidi</citetitle></link>, the Midi note number value is taken from the Midi event associated with the instrument instance, and no location or expression for this value may be specified.
      </para>
    </note>

    <para>
      <emphasis>octmidinn</emphasis> and its related opcodes are really <emphasis>value converters</emphasis> with a special function of manipulating pitch data.
    </para>

    <para>
      Data concerning pitch and frequency can exist in any of the following forms:
    </para>

    <table frame="none" colsep="0">
      <title>Pitch and Frequency Values</title>

      <tgroup cols="2">
        <thead>
          <row>
            <entry>Name</entry>
            <entry>Abbreviation</entry>
          </row>
        </thead>

        <tbody>
          <row>
            <entry>octave point pitch-class (8ve.pc)</entry>
            <entry>pch</entry>
          </row>

          <row>
            <entry>octave point decimal</entry>
            <entry>oct</entry>
          </row>

          <row>
            <entry>cycles per second</entry>
            <entry>cps</entry>
          </row>

          <row>
            <entry>Midi note number (0-127)</entry>
            <entry>midinn</entry>
          </row>
        </tbody>
      </tgroup>
    </table>

    <para>
      The first two forms consist of a whole number, representing octave registration, followed by a specially interpreted fractional part. For <emphasis>pch</emphasis>, the fraction is read as two decimal digits representing the 12 equal-tempered pitch classes from .00 for C to .11 for B. For <emphasis>oct</emphasis>, the fraction is interpreted as a true decimal fractional part of an octave. The two fractional forms are thus related by the factor 100/12. In both forms, the fraction is preceded by a whole number octave index such that 8.00 represents Middle C, 9.00 the C above, etc. Midi note number values range between 0 and 127 (inclusively) with 60 representing Middle C, and are usually whole numbers. Thus A440 can be represented alternatively by 440 (<emphasis>cps</emphasis>), 69 (<emphasis>midinn</emphasis>), 8.09 (<emphasis>pch</emphasis>), or 8.75 (<emphasis>oct</emphasis>). Microtonal divisions of the <emphasis>pch</emphasis> semitone can be encoded by using more than two decimal places.
    </para>

    <para>
      The mnemonics of the pitch conversion units are derived from morphemes of the forms involved, the second morpheme describing the source and the first morpheme the object (result). Thus <emphasis>cpspch</emphasis>(8.09) will convert the pitch argument 8.09 to its <emphasis>cps</emphasis> (or Hertz) equivalent, giving the value of 440. Since the argument is constant over the duration of the note, this conversion will take place at i-time, before any samples for the current note are produced. 
    </para>

    <para>
      By contrast, the conversion <emphasis>cpsoct</emphasis>(8.75 + k1) which gives the value of A440 transposed by the octave interval <emphasis>k1</emphasis>. The calculation will be repeated every k-period since that is the rate at which <emphasis>k1</emphasis> varies.
    </para>

    <note>
      <title>Note</title>
      <para>
        The conversion from <emphasis>pch</emphasis>, <emphasis>oct</emphasis>, or <emphasis>midinn</emphasis> into <emphasis>cps</emphasis> is not a linear operation but involves an exponential process that could be time-consuming when executed repeatedly. Csound now uses a built-in table lookup to do this efficiently, even at audio rates. Because the table index is truncated without interpolation, pitch resolution when using one of these opcodes is limited to 8192 discrete and equal divisions of the octave, and some pitches of the standard 12-tone equally-tempered scale are very slightly mistuned (by at most 0.15 cents).
      </para>
    </note>
  </refsect1>

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

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

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="cpsmidinn"><citetitle>cpsmidinn</citetitle></link>,
      <link linkend="pchmidinn"><citetitle>pchmidinn</citetitle></link>,
      <link linkend="octmidi"><citetitle>octmidi</citetitle></link>,
      <link linkend="notnum"><citetitle>notnum</citetitle></link>,
      <link linkend="cpspch"><citetitle>cpspch</citetitle></link>,
      <link linkend="cpsoct"><citetitle>cpsoct</citetitle></link>,
      <link linkend="octcps"><citetitle>octcps</citetitle></link>,
      <link linkend="octpch"><citetitle>octpch</citetitle></link>,
      <link linkend="pchoct"><citetitle>pchoct</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>Derived from original value converters by Barry Vercoe.</para>
    <para>New in version 5.07</para>
  </refsect1>
</refentry>