Sophie

Sophie

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

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>pdhalf</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="pdclip.html" title="pdclip" />
    <link rel="next" href="pdhalfy.html" title="pdhalfy" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pdhalf</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pdclip.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pdhalfy.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry" title="pdhalf">
      <a id="pdhalf"></a>
      <div class="titlepage"></div>
      <a id="IndexPdhalf" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pdhalf</span>
        </h2>
        <p>pdhalf — 
      Distorts a phasor for reading the two halves of a table at different rates.
    </p>
      </div>
      <div class="refsect1" title="Description">
        <a id="idp35871512"></a>
        <h2>Description</h2>
        <p>
      The <span class="emphasis"><em>pdhalf</em></span> opcode is designed to emulate the "classic" phase distortion synthesis method of the Casio CZ-series of synthesizers from the mid-1980's.  This technique reads the first and second halves of a function table at different rates in order to warp the waveform.  For example, <span class="emphasis"><em>pdhalf</em></span> can smoothly transform a sine wave into something approximating the shape of a saw wave.
    </p>
      </div>
      <div class="refsect1" title="Syntax">
        <a id="idp35949976"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">aout <span class="command"><strong>pdhalf</strong></span> ain, kShapeAmount [, ibipolar [, ifullscale]]</pre>
      </div>
      <div class="refsect1" title="Initialization">
        <a id="idp35951104"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ibipolar</em></span> -- an optional parameter specifying either unipolar (0) or bipolar (1) mode.  Defaults to unipolar mode.
    </p>
        <p>
      <span class="emphasis"><em>ifullscale</em></span> -- an optional parameter specifying the range of input and output values. The maximum will be <span class="emphasis"><em>ifullscale</em></span>. The minimum depends on the mode of operation: zero for unipolar or -<span class="emphasis"><em>ifullscale</em></span> for bipolar.  Defaults to 1.0 -- you should set this parameter to the maximum expected input value.
    </p>
      </div>
      <div class="refsect1" title="Performance">
        <a id="idp35953144"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ain</em></span> --  the input signal to be distorted.
    </p>
        <p>
      <span class="emphasis"><em>aout</em></span> --  the output signal.
    </p>
        <p>
      <span class="emphasis"><em>kShapeAmount</em></span> --  the amount of distortion applied to the input.  Must be between negative one and one (-1 to 1). An amount of zero means no distortion.
    </p>
        <p>
      </p>
        <div class="mediaobject">
          <img src="images/pdhalf.png" alt="Transfer function created by pdhalf and a negative kShapeAmount." />
          <div class="caption">
            <p>Transfer function created by pdhalf and a negative kShapeAmount.</p>
          </div>
        </div>
        <p>

      The <span class="emphasis"><em>pdhalf</em></span> opcode calculates a transfer function that is composed of two linear segments (see the graph).  These segments meet at a "pivot point" which always lies on the same horizontal axis.  (In unipolar mode, the axis is y = 0.5, and for bipolar mode it is the x axis).  The <span class="emphasis"><em>kShapeAmount</em></span> parameter specifies where on the horizontal axis this point falls.  When <span class="emphasis"><em>kShapeAmount</em></span> is zero, the pivot point is in the middle of the input range, forming a straight line for the transfer function and thus causing no change in the input signal.  As <span class="emphasis"><em>kShapeAmount</em></span> changes from zero (0) to negative one (-1), the pivot point moves towards the left side of the graph, producing a phase distortion pattern like the Casio CZ's "sawtooth waveform".  As it changes from zero (0) to positive one (1), the pivot point moves toward the right, producing an inverted pattern.
    </p>
        <p>
      If the input to <span class="emphasis"><em>pdhalf</em></span> is a phasor and the output is used to index a table, values for <span class="emphasis"><em>kShapeAmount</em></span> that are less than zero will cause the first half of the table to be read more quickly than the second half.  The reverse is true for values of <span class="emphasis"><em>kShapeAmount</em></span> greater than zero. The rates at which the halves are read are calculated so that the frequency of the phasor is unchanged.  Thus, this method of phase distortion can only produce higher partials in a harmonic series.  It cannot produce inharmonic sidebands in the way that frequency modulation does. 
    </p>
        <p>
      <span class="emphasis"><em>pdhalf</em></span> can work in either unipolar or bipolar modes. Unipolar mode is appropriate for signals like phasors that range between zero and some maximum value (selectable with <span class="emphasis"><em>ifullscale</em></span>). Bipolar mode is appropriate for signals that range above and below zero by roughly equal amounts such as most audio signals.  Applying <span class="emphasis"><em>pdhalf</em></span> directly to an audio signal in this way results in a crude but adjustable sort of waveshaping/distortion.
    </p>
        <p>
      A typical example of the use of pdhalf is

      </p>
        <div class="informalexample">
          <pre class="programlisting">
    aphase    <span class="opc">phasor</span>    ifreq
    apd       <span class="opc">pdhalf</span>    aphase, kamount
    aout      <span class="opc">tablei</span>    apd, 1, 1</pre>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1" title="Examples">
        <a id="idp35963128"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the pdhalf opcode. It uses the file <a class="ulink" href="examples/pdhalf.csd" target="_top"><em class="citetitle">pdhalf.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp35964096"></a>
          <p class="title">
            <strong>Example 580. Example of the pdhalf 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>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pdhalf.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="oblock">instr</span> 4

    idur        <span class="op">=</span> p3
    iamp        <span class="op">=</span> p4
    ifreq       <span class="op">=</span> p5
    itable      <span class="op">=</span> p6
    
    aenv        <span class="opc">linseg</span>      0, .001, 1.0, idur <span class="op">-</span> .051, 1.0, .05, 0
    aosc        <span class="opc">phasor</span>      ifreq
    kamount     <span class="opc">linseg</span>      0.0, 0.02, <span class="op">-</span>0.99, 0.05, <span class="op">-</span>0.9, idur<span class="op">-</span>0.06, 0.0
    apd         <span class="opc">pdhalf</span>      aosc, kamount
    aout        <span class="opc">tablei</span>      apd, itable, 1
    
                <span class="opc">outs</span>         aenv<span class="op">*</span>aout<span class="op">*</span>iamp, aenv<span class="op">*</span>aout<span class="op">*</span>iamp     
<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>2 0 16385 10 1 .5 .3333 .25 .5
<span class="stamnt">f</span>3 0 16385  9 1 1 270           <span class="comment">; inverted cosine</span>

<span class="comment">; descending "just blues" scale</span>

<span class="comment">; pdhalf with cosine table</span>
<span class="comment">; (imitates the CZ-101 "sawtooth waveform")</span>
<span class="stamnt">t</span> 0 100
<span class="stamnt">i</span>4 0 3   .6     512     3
<span class="stamnt">i</span>. + .    .     448
<span class="stamnt">i</span>. + .    .     384
<span class="stamnt">i</span>. + .    .     358.4
<span class="stamnt">i</span>. + .    .     341.33
<span class="stamnt">i</span>. + .    .     298.67
<span class="stamnt">i</span>. + 5    .     256
<span class="stamnt">s</span>
<span class="comment">; pdhalf with a sine table</span>
<span class="stamnt">t</span> 0 120
<span class="stamnt">i</span>4 0 3   .6     512     1
<span class="stamnt">i</span>. + .    .     448
<span class="stamnt">i</span>. + .    .     384
<span class="stamnt">i</span>. + .    .     358.4
<span class="stamnt">i</span>. + .    .     341.33
<span class="stamnt">i</span>. + .    .     298.67
<span class="stamnt">i</span>. + 5    .     256
<span class="stamnt">s</span>
<span class="comment">; pdhalf with a sawtooth-like table</span>
<span class="stamnt">t</span> 0 150
<span class="stamnt">i</span>4 0 3   .6     512     2
<span class="stamnt">i</span>. + .    .     448
<span class="stamnt">i</span>. + .    .     384
<span class="stamnt">i</span>. + .    .     358.4
<span class="stamnt">i</span>. + .    .     341.33
<span class="stamnt">i</span>. + .    .     298.67
<span class="stamnt">i</span>. + 5    .     256
<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="idp35966368"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="pdhalfy.html" title="pdhalfy"><em class="citetitle">pdhalfy</em></a>,
      <a class="link" href="pdclip.html" title="pdclip"><em class="citetitle">pdclip</em></a>
    </p>
        <p> More information about phase distortion on Wikipedia: <a class="ulink" href="http://en.wikipedia.org/wiki/Phase_distortion_synthesis" target="_top"><em class="citetitle">http://en.wikipedia.org/wiki/Phase_distortion_synthesis</em></a></p>
      </div>
      <div class="refsect1" title="Credits">
        <a id="idp35968584"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: 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="pdclip.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="pdhalfy.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pdclip </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pdhalfy</td>
        </tr>
      </table>
    </div>
  </body>
</html>