Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 6ed14ebfd686aa32f7956e552aa2e21d > files > 2352

csound-manual-5.13.0-5.fc15.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>pconvolve</title>
    <link rel="stylesheet" href="csound.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.75.2" />
    <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="pchoct.html" title="pchoct" />
    <link rel="next" href="pcount.html" title="pcount" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pconvolve</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pchoct.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pcount.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry" title="pconvolve">
      <a id="pconvolve"></a>
      <div class="titlepage"></div>
      <a id="IndexPconvolve" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pconvolve</span>
        </h2>
        <p>convolve — 
      Convolution based on a uniformly partitioned overlap-save algorithm
    </p>
      </div>
      <div class="refsect1" title="Description">
        <a id="id3092843"></a>
        <h2>Description</h2>
        <p>
      Convolution based on a uniformly partitioned overlap-save algorithm. Compared to the <a class="link" href="convolve.html" title="convolve"><em class="citetitle">convolve</em></a> opcode, <span class="emphasis"><em>pconvolve</em></span> has these benefits:
    </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" type="disc">
            <li class="listitem">
              <p>small delay</p>
            </li>
            <li class="listitem">
              <p>possible to run in real-time for shorter impulse files</p>
            </li>
            <li class="listitem">
              <p>no pre-process analysis pass</p>
            </li>
            <li class="listitem">
              <p>can often render faster than <span class="emphasis"><em>convolve</em></span></p>
            </li>
          </ul>
        </div>
      </div>
      <div class="refsect1" title="Syntax">
        <a id="id3092937"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ar1 [, ar2] [, ar3] [, ar4] <span class="command"><strong>pconvolve</strong></span> ain, ifilcod [, ipartitionsize, ichannel]</pre>
      </div>
      <div class="refsect1" title="Initialization">
        <a id="id3092957"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ifilcod</em></span>
      -- integer or character-string denoting an impulse response soundfile. Multichannel files are supported, the file must have the same sample-rate as the orc. [Note: <span class="emphasis"><em>cvanal</em></span> files cannot be used!]  Keep in mind that longer files require more calculation time [and probably larger partition sizes and more latency].  At current processor speeds, files longer than a few seconds may not render in real-time.
    </p>
        <p>
      <span class="emphasis"><em>ipartitionsize</em></span>
      (optional, defaults to the output buffersize [-b]) -- the size in samples of each partition of the impulse file.  This is the parameter that needs tweaking for best performance depending on the impulse file size. Generally, a small size means smaller latency but more computation time. If you specify a value that is not a power-of-2 the opcode will find the next power-of-2 greater and use that as the actual partition size.
    </p>
        <p>
      <span class="emphasis"><em>ichannel</em></span>
      (optional) -- which channel to use from the impulse response data
      file.
    </p>
      </div>
      <div class="refsect1" title="Performance">
        <a id="id3093936"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ain</em></span> -- input audio signal.
    </p>
        <p>
      The overall latency of the opcode can be calculated as such [assuming <span class="emphasis"><em>ipartitionsize</em></span> is a power of 2]
    </p>
        <pre class="programlisting">
    ilatency = (ksmps &lt; ipartitionsize ? ipartitionsize + ksmps : ipartitionsize)/sr</pre>
      </div>
      <div class="refsect1" title="Examples">
        <a id="id3093968"></a>
        <h2>Examples</h2>
        <p>
      Instrument 1 shows an example of real-time convolution.
    </p>
        <p>
    Instrument 2 shows how to do file-based convolution with a 'look ahead' method to remove all delay.
    </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>
	You will need to download the impulse response files from noisevault.com
	or replace the filenames with your own impulse files
	</p>
              </td>
            </tr>
          </table>
        </div>
        <div class="informalexample">
          <pre class="programlisting">
        <span class="ohdr">sr</span> <span class="op">=</span> 44100
        <span class="ohdr">ksmps</span> <span class="op">=</span> 100
        <span class="ohdr">nchnls</span> <span class="op">=</span> 2


        <span class="oblock">instr   1</span>
kmix <span class="op">=</span> .5    <span class="comment">; Wet/dry mix. Vary as desired.</span>
kvol <span class="op">=</span> .5<span class="op">*</span>kmix    <span class="comment">; Overall volume level of reverb. May need to adjust</span>
                    <span class="comment">; when wet/dry mix is changed, to avoid clipping.</span>

<span class="comment">; do some safety checking to make sure we the parameters a good</span>
kmix <span class="op">=</span> (kmix <span class="op">&lt;</span> 0  <span class="op">||</span> kmix <span class="op">&gt;</span> 1 <span class="op">?</span> .5 <span class="op">:</span> kmix)
kvol <span class="op">=</span> (kvol <span class="op">&lt;</span> 0 <span class="op">?</span> 0 <span class="op">:</span> .5<span class="op">*</span>kvol<span class="op">*</span>kmix)

<span class="comment">; size of each convolution partion -- for best performance, this parameter needs to be tweaked</span>
ipartitionsize <span class="op">=</span> p4

<span class="comment">; calculate latency of pconvolve opcode</span>
idel    <span class="op">=</span> (ksmps <span class="op">&lt;</span> ipartitionsize <span class="op">?</span> ipartitionsize <span class="op">+</span> ksmps <span class="op">:</span> ipartitionsize)<span class="op">/</span><span class="ohdr">sr</span>
<span class="opc">prints</span> "Convolving with a latency of %f seconds%n", idel

<span class="comment">; actual processing</span>
al, ar    <span class="opc">ins</span>

awetl, awetr <span class="opc">pconvolve</span>    kvol<span class="op">*</span>(al<span class="op">+</span>ar), "Mercedes-van.wav", ipartitionsize

<span class="comment">; Delay dry signal, to align it with the convoled sig</span>
adryl        <span class="opc">delay</span>  (1<span class="op">-</span>kmix)<span class="op">*</span>al, idel
adryr        <span class="opc">delay</span>  (1<span class="op">-</span>kmix)<span class="op">*</span>ar, idel

     <span class="opc">outs</span>    adryl<span class="op">+</span>awetl, adryr<span class="op">+</span>awetr

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




        <span class="oblock">instr   2</span>
imix <span class="op">=</span> 0.5         <span class="comment">; Wet/dry mix. Vary as desired.</span>
ivol <span class="op">=</span> .5<span class="op">*</span>imix    <span class="comment">; Overall volume level of reverb. May need to adjust</span>
                <span class="comment">; when wet/dry mix is changed, to avoid clipping.</span>

ipartitionsize <span class="op">=</span>    32768    <span class="comment">; size of each convolution partion</span>
idel    <span class="op">=</span> (ksmps <span class="op">&lt;</span> ipartitionsize <span class="op">?</span> ipartitionsize <span class="op">+</span> ksmps <span class="op">:</span> ipartitionsize)<span class="op">/</span><span class="ohdr">sr</span>    <span class="comment">; latency of pconvolve opcode</span>

kcount <span class="opc">init</span> idel<span class="op">*</span><span class="ohdr">kr</span>

<span class="comment">; since we are using a soundin [instead of ins] we can</span>
<span class="comment">; do a kind of "look ahead" by looping during one k-pass</span>
<span class="comment">; without output, creating zero-latency</span>

<span class="olabel">loop</span>:
    al, ar    <span class="opc">soundin</span> "John_Cage_1.aif", 0

    awetl, awetr <span class="opc">pconvolve</span> ivol<span class="op">*</span>(al<span class="op">+</span>ar),"FactoryHall.aif", ipartitionsize

    adryl        <span class="opc">delay</span>  (1<span class="op">-</span>imix)<span class="op">*</span>al,idel  <span class="comment">; Delay dry signal, to align it with</span>
    adryr        <span class="opc">delay</span>  (1<span class="op">-</span>imix)<span class="op">*</span>ar,idel

    kcount <span class="op">=</span> kcount <span class="op">-</span> 1
 <span class="opc">if</span> kcount <span class="op">&gt;</span> 0  <span class="opc">kgoto</span> <span class="olabel">loop</span>

         <span class="opc">outs</span>    awetl<span class="op">+</span>adryl, awetr<span class="op">+</span>adryr

        <span class="oblock">endin</span></pre>
        </div>
      </div>
      <div class="refsect1" title="See also">
        <a id="id3094570"></a>
        <h2>See also</h2>
        <p>
      <a class="link" href="convolve.html" title="convolve"><em class="citetitle">convolve</em></a>, <a class="link" href="dconv.html" title="dconv"><em class="citetitle">dconv</em></a>.
    </p>
      </div>
      <div class="refsect1" title="Credits">
        <a id="id3094596"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Matt Ingalls</td>
          </tr>
          <tr>
            <td>2004</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pchoct.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="pcount.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pchoct </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pcount</td>
        </tr>
      </table>
    </div>
  </body>
</html>