Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release > by-pkgid > b707d9a4ee443103660a75ccb6e51334 > files > 466

csound-doc-5.19.01-10.mga5.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>cpsmidinn</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="cpsmidib.html" title="cpsmidib" />
    <link rel="next" href="cpsoct.html" title="cpsoct" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">cpsmidinn</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="cpsmidib.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="cpsoct.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry" title="cpsmidinn">
      <a id="cpsmidinn"></a>
      <div class="titlepage"></div>
      <a id="IndexCpsmidinn" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">cpsmidinn</span>
        </h2>
        <p>cpsmidinn — 
      Converts a Midi note number value to cycles-per-second.
          </p>
      </div>
      <div class="refsect1" title="Description">
        <a id="idp16778960"></a>
        <h2>Description</h2>
        <p>
      Converts a Midi note number value to cycles-per-second.
    </p>
      </div>
      <div class="refsect1" title="Syntax">
        <a id="idp16779624"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>cpsmidinn</strong></span> (MidiNoteNumber)  (init- or control-rate args only)</pre>
        <p>
      where the argument within the parentheses may be a further expression.
    </p>
      </div>
      <div class="refsect1" title="Performance">
        <a id="idp16790312"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>cpsmidinn</em></span> is a function that takes an i-rate or k-rate value representing a Midi note number and returns the equivalent frequency value in cycles-per-second (Hertz). This conversion assumes that Middle C is Midi note number 60 and that Middle A is tuned to 440 Hz. 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.
    </p>
        <div class="note" title="cpsmidinn vs. cpsmidi" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: cpsmidinn vs. cpsmidi">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">cpsmidinn vs. cpsmidi</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        The <span class="emphasis"><em>cpsmidinn</em></span> 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 <span class="emphasis"><em>cpsmidinn</em></span> 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 <a class="link" href="notnum.html" title="notnum"><em class="citetitle">notnum</em></a> 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 <a class="link" href="cpsmidi.html" title="cpsmidi"><em class="citetitle">cpsmidi</em></a> opcode only produces meaningful results in a Midi-activated note (either real-time or from a Midi score with the -F flag).  With <a class="link" href="cpsmidi.html" title="cpsmidi"><em class="citetitle">cpsmidi</em></a>, 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.
      </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
      <span class="emphasis"><em>cpsmidinn</em></span> and its related opcodes are really <span class="emphasis"><em>value converters</em></span> with a special function of manipulating pitch data.
    </p>
        <p>
      Data concerning pitch and frequency can exist in any of the following forms:
    </p>
        <div class="table">
          <a id="idp16833400"></a>
          <p class="title">
            <strong>Table 7. Pitch and Frequency Values</strong>
          </p>
          <div class="table-contents">
            <table summary="Pitch and Frequency Values" border="0">
              <colgroup>
                <col />
                <col />
              </colgroup>
              <thead>
                <tr>
                  <th>Name</th>
                  <th>Abbreviation</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>octave point pitch-class (8ve.pc)</td>
                  <td>pch</td>
                </tr>
                <tr>
                  <td>octave point decimal</td>
                  <td>oct</td>
                </tr>
                <tr>
                  <td>cycles per second</td>
                  <td>cps</td>
                </tr>
                <tr>
                  <td>Midi note number (0-127)</td>
                  <td>midinn</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <br class="table-break" />
        <p>
      The first two forms consist of a whole number, representing octave registration, followed by a specially interpreted fractional part. For <span class="emphasis"><em>pch</em></span>, the fraction is read as two decimal digits representing the 12 equal-tempered pitch classes from .00 for C to .11 for B. For <span class="emphasis"><em>oct</em></span>, 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 (<span class="emphasis"><em>cps</em></span>), 69 (<span class="emphasis"><em>midinn</em></span>), 8.09 (<span class="emphasis"><em>pch</em></span>), or 8.75 (<span class="emphasis"><em>oct</em></span>). Microtonal divisions of the <span class="emphasis"><em>pch</em></span> semitone can be encoded by using more than two decimal places.
    </p>
        <p>
      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 <span class="emphasis"><em>cpspch</em></span>(8.09) will convert the pitch argument 8.09 to its <span class="emphasis"><em>cps</em></span> (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. 
    </p>
        <p>
      By contrast, the conversion <span class="emphasis"><em>cpsoct</em></span>(8.75 + k1) which gives the value of A440 transposed by the octave interval <span class="emphasis"><em>k1</em></span>. The calculation will be repeated every k-period since that is the rate at which <span class="emphasis"><em>k1</em></span> varies.
    </p>
        <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        The conversion from <span class="emphasis"><em>pch</em></span>, <span class="emphasis"><em>oct</em></span>, or <span class="emphasis"><em>midinn</em></span> into <span class="emphasis"><em>cps</em></span> 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).
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1" title="Examples">
        <a id="idp16844512"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the cpsmidinn opcode. It uses the file <a class="ulink" href="examples/cpsmidinn.csd" target="_top"><em class="citetitle">cpsmidinn.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp16845504"></a>
          <p class="title">
            <strong>Example 132. Example of the cpsmidinn opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform.</span>
<span class="comment">; This example produces no audio, so we render in</span>
<span class="comment">; non-realtime and turn off sound to disk:</span>
-n
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="oblock">instr</span> 1
  <span class="comment">; i-time loop to print conversion table</span>
  imidiNN <span class="op">=</span>   0
  loop1<span class="op">:</span>
    icps  <span class="op">=</span> <span class="opc">cpsmidinn</span>(imidiNN)
    ioct  <span class="op">=</span> <span class="opc">octmidinn</span>(imidiNN)
    ipch  <span class="op">=</span> <span class="opc">pchmidinn</span>(imidiNN)
            
    <span class="opc">print</span>   imidiNN, icps, ioct, ipch
      
    imidiNN <span class="op">=</span> imidiNN <span class="op">+</span> 1
  <span class="octrl">if</span> (imidiNN <span class="op">&lt;</span> 128) <span class="octrl">igoto</span> loop1
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2
  <span class="comment">; test k-rate converters</span>
  kMiddleC  <span class="op">=</span>   60
  kcps  <span class="op">=</span> <span class="opc">cpsmidinn</span>(kMiddleC)
  koct  <span class="op">=</span> <span class="opc">octmidinn</span>(kMiddleC)
  kpch  <span class="op">=</span> <span class="opc">pchmidinn</span>(kMiddleC)
            
  <span class="opc">printks</span> "<span class="op">%</span>d <span class="op">%</span>f <span class="op">%</span>f <span class="op">%</span>f\n", 1.0, kMiddleC, kcps, koct, kpch
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span>1 0 0
<span class="stamnt">i</span>2 0 0.1
<span class="stamnt">e</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>
      Here is another example of the cpsmidinn opcode. It uses the file <a class="ulink" href="examples/cpsmidinn2.csd" target="_top"><em class="citetitle">cpsmidinn2.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp16848336"></a>
          <p class="title">
            <strong>Example 133. Second example of the cpsmidinn opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">;;;RT audio out, midi in, note=p4 and velocity=p5</span>
-odac -+rtmidi=virtual -M0d --midi-key=4 --midi-velocity-amp=5
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o cpsmidinn.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="ohdr">massign</span> 0, 1	<span class="comment">;assign all midi to instr. 1</span>

<span class="oblock">instr</span> 1	<span class="comment">;play virtual keyboard</span>

inote <span class="op">=</span> p4
icps  <span class="op">=</span> <span class="opc">cpsmidinn</span>(inote)
asig	<span class="opc">oscil</span> 0.6, icps, 1
	<span class="opc">print</span> icps
	<span class="opc">outs</span>  asig, asig

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>0 20
<span class="comment">;sine wave.</span>
<span class="stamnt">f</span> 1 0 16384 10 1
<span class="comment">;play note from score too</span>
<span class="stamnt">i</span>1 0 1 60
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1" title="See Also">
        <a id="idp16849360"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="octmidinn.html" title="octmidinn"><em class="citetitle">octmidinn</em></a>,
      <a class="link" href="pchmidinn.html" title="pchmidinn"><em class="citetitle">pchmidinn</em></a>,
      <a class="link" href="cpsmidi.html" title="cpsmidi"><em class="citetitle">cpsmidi</em></a>,
      <a class="link" href="notnum.html" title="notnum"><em class="citetitle">notnum</em></a>,
      <a class="link" href="cpspch.html" title="cpspch"><em class="citetitle">cpspch</em></a>,
      <a class="link" href="cpsoct.html" title="cpsoct"><em class="citetitle">cpsoct</em></a>,
      <a class="link" href="octcps.html" title="octcps"><em class="citetitle">octcps</em></a>,
      <a class="link" href="octpch.html" title="octpch"><em class="citetitle">octpch</em></a>,
      <a class="link" href="pchoct.html" title="pchoct"><em class="citetitle">pchoct</em></a>
    </p>
      </div>
      <div class="refsect1" title="Credits">
        <a id="idp16854216"></a>
        <h2>Credits</h2>
        <p>Derived from original value converters by Barry Vercoe.</p>
        <p>New in version 5.07</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="cpsmidib.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="cpsoct.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">cpsmidib </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> cpsoct</td>
        </tr>
      </table>
    </div>
  </body>
</html>