Sophie

Sophie

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

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>syncphasor</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="syncloop.html" title="syncloop" />
    <link rel="next" href="system.html" title="system" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">syncphasor</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="syncloop.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="system.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry" title="syncphasor">
      <a id="syncphasor"></a>
      <div class="titlepage"></div>
      <a id="IndexSyncPhasor" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">syncphasor</span>
        </h2>
        <p>syncphasor — 
      Produces a normalized moving phase value with sync input and output.
          </p>
      </div>
      <div class="refsect1" title="Description">
        <a id="idp46937496"></a>
        <h2>Description</h2>
        <p>
      Produces a moving phase value between zero and one and an extra impulse output ("sync out") whenever its phase value crosses or is reset to zero. The phase can be reset at any time by an impulse on the "sync in" parameter.
    </p>
      </div>
      <div class="refsect1" title="Syntax">
        <a id="idp46924456"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">aphase, asyncout <span class="command"><strong>syncphasor</strong></span> xcps, asyncin, [, iphs]</pre>
      </div>
      <div class="refsect1" title="Initialization">
        <a id="idp46925568"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iphs</em></span> (optional) -- initial phase, expressed as a fraction of a cycle (0 to 1). A negative value will cause phase initialization to be skipped. The default value is zero.
    </p>
      </div>
      <div class="refsect1" title="Performance">
        <a id="idp46977000"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>aphase</em></span> -- the output phase value; always between 0 and 1.
    </p>
        <p>
      <span class="emphasis"><em>asyncout</em></span> -- the sync output has a value of 1.0 for one sample whenever the phase value crosses zero or whenever the sync input is non-zero.  It is zero at all other times.
    </p>
        <p>
      <span class="emphasis"><em>asyncin</em></span> -- the sync input causes the phase to reset  to zero whenever <span class="emphasis"><em>asyncin</em></span> is non-zero.
    </p>
        <p>
      <span class="emphasis"><em>xcps</em></span> -- frequency of the phasor in cycles-per-second.  If <span class="emphasis"><em>xcps</em></span> is negative, the phase value will decrease from 1 to 0 instead of increasing.
    </p>
        <p>
      An internal phase is successively accumulated in accordance with the <span class="emphasis"><em>xcps</em></span> frequency to produce a moving phase value, normalized to lie in the range 0 &lt;= phs &lt; 1.  When used as the index to a <a class="link" href="table.html" title="table"><em class="citetitle">table</em></a> unit, this phase (multiplied by the desired function table length) will cause it to behave like an oscillator.
    </p>
        <p>
      The phase of <span class="emphasis"><em>syncphasor</em></span> though can be synced to another phasor (or other signal) using the <span class="emphasis"><em>asyncin</em></span> parameter.  Any time that <span class="emphasis"><em>asyncin</em></span> is a non-zero value, the value of <span class="emphasis"><em>aphase</em></span> will be reset to zero.  <span class="emphasis"><em>syncphasor</em></span> also outputs its own "sync" signal that consists of a one-sample impulse whenever its phase crosses zero or is reset.  This makes it easy to chain together multiple <span class="emphasis"><em>syncphasor</em></span> opcodes to create an oscillator "hard sync" effect.    
    </p>
      </div>
      <div class="refsect1" title="Examples">
        <a id="idp46982976"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the syncphasor opcode. It uses the file <a class="ulink" href="examples/syncphasor.csd" target="_top"><em class="citetitle">syncphasor.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp46983968"></a>
          <p class="title">
            <strong>Example 843. Example of the syncphasor 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">; Audio out   Audio in</span>
-odac           -iadc    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o abs.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="oblock">instr</span> 1
    <span class="comment">; Use two syncphasors - one is the "master",</span>
    <span class="comment">; the other the "slave"</span>
    
    <span class="comment">; master's frequency determines pitch</span>
    imastercps  <span class="op">=</span>           <span class="opc">cpspch</span>(p4)
    imaxamp     <span class="op">=</span>           10000

    <span class="comment">; the slave's frequency affects the timbre </span>
    kslavecps   <span class="opc">line</span>        imastercps, p3, imastercps <span class="op">*</span> 3
    
    <span class="comment">; the master "oscillator"</span>
    <span class="comment">; the master has no sync input </span>
    anosync     <span class="opc">init</span>        0.0
    am, async   <span class="opc">syncphasor</span>  imastercps, anosync
    
    <span class="comment">; the slave "oscillator"</span>
    aout, as    <span class="opc">syncphasor</span>  kslavecps, async
    
    adeclick    <span class="opc">linseg</span>      0.0, 0.05, 1.0, p3 <span class="op">-</span> 0.1, 1.0, 0.05, 0.0
    
    <span class="comment">; Output the slave's phase value which is a rising</span>
    <span class="comment">; sawtooth wave.  This produces aliasing, but hey, this</span>
    <span class="comment">; this is just an example ;)</span>
    
              <span class="opc">out</span>         aout <span class="op">*</span> adeclick <span class="op">*</span> imaxamp
<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 1    7.00
<span class="stamnt">i</span>1 + 0.5  7.02
<span class="stamnt">i</span>1 + .    7.05
<span class="stamnt">i</span>1 + .    7.07
<span class="stamnt">i</span>1 + .    7.09
<span class="stamnt">i</span>1 + 2    7.06

<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 syncphasor opcode. It uses the file <a class="ulink" href="examples/syncphasor-CZresonance.csd" target="_top"><em class="citetitle">syncphasor-CZresonance.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp46986840"></a>
          <p class="title">
            <strong>Example 844. Another example of the syncphasor 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">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o syncphasor-CZresonance.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">; by Anthony Kozar. February 2008</span>
<span class="comment">; http://www.anthonykozar.net/</span>

<span class="comment">; Imitation of the Casio CZ-series synthesizer's "Resonance" waveforms</span>
<span class="comment">; using a synced phasor to read a sinusoid table.  The jumps at the sync </span>
<span class="comment">; points are smoothed by multiplying with a windowing function controlled</span>
<span class="comment">; by the master phasor.</span>

<span class="comment">; Based on information from the Wikipedia article on phase distortion:</span>
<span class="comment">; http://en.wikipedia.org/wiki/Phase_distortion_synthesis</span>

<span class="comment">; Sawtooth Resonance waveform. Smoothing function is just the inverted</span>
<span class="comment">; master phasor.</span>

<span class="comment">; The Wikipedia article shows an inverted cosine as the stored waveform,</span>
<span class="comment">; which implies that it must be unipolar for the smoothing to work.</span>
<span class="comment">; I have substituted a sine wave in the first phrase to keep the output</span>
<span class="comment">; bipolar.  The second phrase demonstrates the much "rezzier" sound of the</span>
<span class="comment">; bipolar cosine due to discontinuities.</span>

<span class="oblock">instr</span> 1
  ifreq      <span class="op">=</span>           <span class="opc">cpspch</span>(p4)
  initReson  <span class="op">=</span>           p5
  itable     <span class="op">=</span>           p6
  imaxamp    <span class="op">=</span>           10000
  anosync    <span class="opc">init</span>        0.0

  kslavecps       <span class="opc">line</span>        ifreq <span class="op">*</span> initReson, p3, ifreq
  amaster, async  <span class="opc">syncphasor</span>  ifreq, anosync		<span class="comment">; pair of phasors</span>
  aslave, async2  <span class="opc">syncphasor</span>  kslavecps, async		<span class="comment">; slave synced to master</span>
  aosc            <span class="opc">tablei</span>      aslave, itable, 1		<span class="comment">; use slave phasor to read a (co)sine table</span>
  aout            <span class="op">=</span>           aosc <span class="op">*</span> (1.0 <span class="op">-</span> amaster)	<span class="comment">; inverted master smoothes jumps </span>
  adeclick        <span class="opc">linseg</span>      0.0, 0.05, 1.0, p3 <span class="op">-</span> 0.1, 1.0, 0.05, 0.0

                    <span class="opc">out</span>         aout <span class="op">*</span> adeclick <span class="op">*</span> imaxamp
<span class="oblock">endin</span>

<span class="comment">; Triangle or Trapezoidal Resonance waveform. Uses a second table to change</span>
<span class="comment">; the shape of the smoothing function.  (This is my best guess so far as to</span>
<span class="comment">; how these worked). The cosine table works fine with the triangular smoothing</span>
<span class="comment">; but we once again need to use a sine table with the trapezoidal smoothing.</span>

<span class="comment">; (It might be interesting to be able to vary the "width" of the trapezoid.</span>
<span class="comment">; This could be done with the pdhalf opcode).</span>

<span class="oblock">instr</span> 2
  ifreq      <span class="op">=</span>           <span class="opc">cpspch</span>(p4)
  initReson  <span class="op">=</span>           p5
  itable     <span class="op">=</span>           p6
  ismoothtbl <span class="op">=</span>           p7
  imaxamp    <span class="op">=</span>           10000
  anosync    <span class="opc">init</span>        0.0

  kslavecps       <span class="opc">line</span>        ifreq <span class="op">*</span> initReson, p3, ifreq
  amaster, async  <span class="opc">syncphasor</span>  ifreq, anosync		<span class="comment">; pair of phasors</span>
  aslave, async2  <span class="opc">syncphasor</span>  kslavecps, async		<span class="comment">; slave synced to master</span>
  aosc            <span class="opc">tablei</span>      aslave, itable, 1		<span class="comment">; use slave phasor to read a (co)sine table</span>
  asmooth         <span class="opc">tablei</span>      amaster, ismoothtbl, 1	<span class="comment">; use master phasor to read smoothing table</span>
  aout            <span class="op">=</span>           aosc <span class="op">*</span> asmooth
  adeclick        <span class="opc">linseg</span>      0.0, 0.05, 1.0, p3 <span class="op">-</span> 0.1, 1.0, 0.05, 0.0

  <span class="opc">out</span>         aout <span class="op">*</span> adeclick <span class="op">*</span> imaxamp
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1 0 16385 10  1
<span class="stamnt">f</span>3 0 16385  9  1 1 270			<span class="comment">; inverted cosine</span>
<span class="stamnt">f</span>5 0 4097   7  0.0 2048 1.0 2049 0.0	<span class="comment">; unipolar triangle</span>
<span class="stamnt">f</span>6 0 4097   7  1.0 2048 1.0 2049 0.0    <span class="comment">; "trapezoid"</span>

<span class="comment">; Sawtooth resonance with a sine table</span>
<span class="stamnt">i</span>1 0 1    7.00  5.0  1
<span class="stamnt">i</span>. + 0.5  7.02  4.0
<span class="stamnt">i</span>. + .    7.05  3.0
<span class="stamnt">i</span>. + .    7.07  2.0
<span class="stamnt">i</span>. + .    7.09  1.0
<span class="stamnt">i</span>. + 2    7.06  12.0
<span class="stamnt">f</span>0 6
<span class="stamnt">s</span>

<span class="comment">; Sawtooth resonance with a cosine table</span>
<span class="stamnt">i</span>1 0 1    7.00  5.0  3
<span class="stamnt">i</span>. + 0.5  7.02  4.0
<span class="stamnt">i</span>. + .    7.05  3.0
<span class="stamnt">i</span>. + .    7.07  2.0
<span class="stamnt">i</span>. + .    7.09  1.0
<span class="stamnt">i</span>. + 2    7.06  12.0
<span class="stamnt">f</span>0 6
<span class="stamnt">s</span>

<span class="comment">; Triangle resonance with a cosine table</span>
<span class="stamnt">i</span>2 0 1    7.00  5.0  3  5
<span class="stamnt">i</span>. + 0.5  7.02  4.0
<span class="stamnt">i</span>. + .    7.05  3.0
<span class="stamnt">i</span>. + .    7.07  2.0
<span class="stamnt">i</span>. + .    7.09  1.0
<span class="stamnt">i</span>. + 2    7.06  12.0
<span class="stamnt">f</span>0 6
<span class="stamnt">s</span>

<span class="comment">; Trapezoidal resonance with a sine table</span>
<span class="stamnt">i</span>2 0 1    7.00  5.0  1  6
<span class="stamnt">i</span>. + 0.5  7.02  4.0
<span class="stamnt">i</span>. + .    7.05  3.0
<span class="stamnt">i</span>. + .    7.07  2.0
<span class="stamnt">i</span>. + .    7.09  1.0
<span class="stamnt">i</span>. + 2    7.06  12.0

<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="idp46987800"></a>
        <h2>See also</h2>
        <p>
      <a class="link" href="phasor.html" title="phasor"><em class="citetitle">phasor</em></a>.
    </p>
        <p>
      And the <a class="link" href="SiggenTableacc.html" title="Table Access"><em class="citetitle">Table Access</em></a> opcodes like: <a class="link" href="table.html" title="table"><em class="citetitle">table</em></a>, <a class="link" href="tablei.html" title="tablei"><em class="citetitle">tablei</em></a>, <a class="link" href="table3.html" title="table3"><em class="citetitle">table3</em></a>  and <a class="link" href="tab.html" title="tab"><em class="citetitle">tab</em></a>.
    </p>
      </div>
      <div class="refsect1" title="Credits">
        <a id="idp46991416"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Adapted from the <span class="emphasis"><em>phasor</em></span> opcode by Anthony Kozar</td>
          </tr>
          <tr>
            <td>January 2008</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 5.08</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="syncloop.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="system.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">syncloop </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> system</td>
        </tr>
      </table>
    </div>
  </body>
</html>