| 1 | |
| 2 | <refentry id="cpsoct"> |
| 3 | <indexterm id="IndexCpsoct"><primary>cpsoct</primary></indexterm> |
| 4 | <refentryinfo><title>Pitch Converters:Functions</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>cpsoct</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>cpsoct</refname> |
| 13 | |
| 14 | <refpurpose> |
| 15 | Converts an octave-point-decimal value to cycles-per-second. |
| 16 | </refpurpose> |
| 17 | </refnamediv> |
| 18 | |
| 19 | |
| 20 | <refsect1> |
| 21 | <title>Description</title> |
| 22 | <para> |
| 23 | Converts an octave-point-decimal value to cycles-per-second. |
| 24 | </para> |
| 25 | </refsect1> |
| 26 | |
| 27 | <refsect1> |
| 28 | <title>Syntax</title> |
| 29 | <synopsis><command>cpsoct</command> (oct) (no rate restriction)</synopsis> |
| 30 | |
| 31 | <para> |
| 32 | where the argument within the parentheses may be a further expression. |
| 33 | </para> |
| 34 | </refsect1> |
| 35 | |
| 36 | <refsect1> |
| 37 | <title>Performance</title> |
| 38 | <para> |
| 39 | <emphasis>cpsoct</emphasis> and its related opcodes are really <emphasis>value converters</emphasis> with a special function of manipulating pitch data. |
| 40 | </para> |
| 41 | |
| 42 | <para> |
| 43 | Data concerning pitch and frequency can exist in any of the following forms: |
| 44 | </para> |
| 45 | |
| 46 | <table frame="none" colsep="0"> |
| 47 | <title>Pitch and Frequency Values</title> |
| 48 | |
| 49 | <tgroup cols="2"> |
| 50 | <thead> |
| 51 | <row> |
| 52 | <entry>Name</entry> |
| 53 | <entry>Abbreviation</entry> |
| 54 | </row> |
| 55 | </thead> |
| 56 | |
| 57 | <tbody> |
| 58 | <row> |
| 59 | <entry>octave point pitch-class (8ve.pc)</entry> |
| 60 | <entry>pch</entry> |
| 61 | </row> |
| 62 | |
| 63 | <row> |
| 64 | <entry>octave point decimal</entry> |
| 65 | <entry>oct</entry> |
| 66 | </row> |
| 67 | |
| 68 | <row> |
| 69 | <entry>cycles per second</entry> |
| 70 | <entry>cps</entry> |
| 71 | </row> |
| 72 | |
| 73 | <row> |
| 74 | <entry>Midi note number (0-127)</entry> |
| 75 | <entry>midinn</entry> |
| 76 | </row> |
| 77 | </tbody> |
| 78 | </tgroup> |
| 79 | </table> |
| 80 | |
| 81 | <para> |
| 82 | 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. |
| 83 | </para> |
| 84 | |
| 85 | <para> |
| 86 | 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. |
| 87 | </para> |
| 88 | |
| 89 | <para> |
| 90 | 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. |
| 91 | </para> |
| 92 | |
| 93 | <note> |
| 94 | <title>Note</title> |
| 95 | <para> |
| 96 | 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). |
| 97 | </para> |
| 98 | </note> |
| 99 | </refsect1> |
| 100 | |
| 101 | <refsect1> |
| 102 | <title>Examples</title> |
| 103 | <para> |
| 104 | Here is an example of the cpsoct opcode. It uses the file <ulink url="examples/cpsoct.csd"><citetitle>cpsoct.csd</citetitle></ulink>. |
| 105 | |
| 106 | <example> |
| 107 | <title>Example of the cpsoct opcode.</title> |
| 108 | |
| 109 | |
| 110 | |
| 111 | <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> |
| 112 | <xi:include href="examples-xml/cpsoct.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 113 | </example> |
| 114 | |
| 115 | Its output should include lines like this: |
| 116 | <screen> |
| 117 | instr 1: icps = 440.000 |
| 118 | instr 1: icps = 446.110 |
| 119 | instr 1: icps = 452.344 |
| 120 | instr 1: icps = 80.521 |
| 121 | </screen> |
| 122 | </para> |
| 123 | </refsect1> |
| 124 | |
| 125 | <refsect1> |
| 126 | <title>See also</title> |
| 127 | <para><link linkend="PitchFuncs"><citetitle>Pitch Converters: Functions</citetitle></link></para> |
| 128 | </refsect1> |
| 129 | |
| 130 | </refentry> |