<?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>pvsbufread</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" /> <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /> <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="pvsbuffer.html" title="pvsbuffer" /> <link rel="next" href="pvsbufread2.html" title="pvsbufread2" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">pvsbufread</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="pvsbuffer.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="pvsbufread2.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="pvsbufread"></a> <div class="titlepage"></div> <a id="Indexpvsbufread" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">pvsbufread</span> </h2> <p>pvsbufread — This opcode reads a circular buffer of f-signals (streaming PV signals). </p> </div> <div class="refsect1"> <a id="idm281472899857720"></a> <h2>Description</h2> <p> This opcode reads from a circular buffer of length ilen (secs), taking a handle for the buffer and a time pointer, which holds the current read position (also in seconds). It is used in conjunction with a <span class="emphasis"><em>pvsbuffer</em></span> opocde. Reading is circular, wrapping around at the end of the buffer. </p> </div> <div class="refsect1"> <a id="idm281472899796776"></a> <h2>Syntax</h2> <pre class="synopsis">fsig <span class="command"><strong>pvsbufread</strong></span> ktime, khandle[, ilo, ihi, iclear] </pre> </div> <div class="refsect1"> <a id="idm281472899794552"></a> <h2>Initialisation</h2> <p> <span class="emphasis"><em>ilo, ihi</em></span> -- set the lowest and highest freqs to be read from the buffer (defaults to 0, Nyquist). </p> <p> <span class="emphasis"><em>iclear</em></span> -- set to 1 to clear output fsig before every write (default 1), 0 tells the opcode not to clear the output fsig. This is relevant when writing to subsets of an fsig frame using <span class="emphasis"><em>ilo</em></span>, <span class="emphasis"><em>ihi</em></span>. </p> </div> <div class="refsect1"> <a id="idm281472899791032"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>fsig</em></span> -- output pv stream </p> <p> <span class="emphasis"><em>ktime</em></span> -- time position of reading pointer (in secs). </p> <p> <span class="emphasis"><em>khandle</em></span> -- handle identifying the buffer to be read. When using k-rate handles, it is important to initialise the k-rate variable to a given existing handle. When changing buffers, fsig buffers need to be compatible (same fsig format). </p> <p> With this opcode and <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>, it is possible to, among other things: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem">time-stretch/compress a fsig stream, by reading it at different rates</li> <li class="listitem">delay a fsig or portions of it.</li> <li class="listitem">'brassage' two or more fsigs by switching buffers, since the reading handles are k-rate. Note that, when using k-rate handles, it is important to initialise the k-rate variable to a given handle (so that the fsig initialisation can take place) and it is only possible to switch handles between compatible fsig buffers (with the same fftsize and overlap).</li> </ul> </div> <p> </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <table border="0" summary="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>It is important that the handle value passed to <span class="emphasis"><em>pvsbufread</em></span> is valid and was created by <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>. Csound will crash with invalid handles. </p> </td> </tr> </table> </div> </div> <div class="refsect1"> <a id="idm281472899781272"></a> <h2>Examples</h2> <p> Here is an example of the pvsbufread opcode. It does 'brassage' by switching between two buffers. </p> <div class="example"> <a id="idm281472899780216"></a> <p class="title"> <strong>Example 745. Example of the pvsbufread 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"> fsig1 <span class="opc">pvsanal</span> asig1, 1024, 256, 1024, 1 fsig2 <span class="opc">pvsanal</span> asig2, 1024, 256, 1024, 1 ibuf1, kt1 <span class="opc">pvsbuffer</span> fsig1, 10 <span class="comment">; 10-sec buf with fsig1</span> ibuf2, kt2 <span class="opc">pvsbuffer</span> fsig2, 7 <span class="comment">; 7-sec buf with fsig2</span> khan <span class="opc">init</span> ibuf1 <span class="comment">; initialise handle to buf1</span> <span class="opc">if</span> ktrig <span class="op">></span> 0 <span class="opc">then</span> <span class="comment">; switch buffers according to trigger</span> khan <span class="op">=</span> ibuf2 <span class="opc">else</span> khan <span class="op">=</span> ibuf1 <span class="opc">endif</span> fsb <span class="opc">pvsbufread</span> kt1, khan <span class="comment">; read buffer</span></pre> </div> </div> <p><br class="example-break" /> </p> <p> Here is an example of the pvsbufread opcode. It uses the file <a class="ulink" href="examples/pvsbufread.csd" target="_top"><em class="citetitle">pvsbufread.csd</em></a>. </p> <div class="example"> <a id="idm281472899762728"></a> <p class="title"> <strong>Example 746. Example of the pvsbufread 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> <div class="refsect1"> <a id="idm281472720926760"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> <span class="c1">; Audio out Audio in</span> -odac <span class="c1">;;;RT audio I/O</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o pvsbufread.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">16</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">1</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1">;; example written by joachim heintz 2009</span> <span class="kd">opcode</span> <span class="nf">FileToPvsBuf</span><span class="p">,</span> <span class="kt">iik</span><span class="p">,</span> <span class="kt">Siiii</span> <span class="c1">;;writes an audio file at the first k-cycle to a fft-buffer (via pvsbuffer)</span> S<span class="n">file</span><span class="p">,</span> i<span class="n">fftsize</span><span class="p">,</span> i<span class="n">overlap</span><span class="p">,</span> i<span class="n">winsize</span><span class="p">,</span> i<span class="n">winshape</span> <span class="nb">xin</span> k<span class="n">timek</span> <span class="nb">timeinstk</span> <span class="k">if</span> k<span class="n">timek</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">then</span> i<span class="n">len</span> <span class="nb">filelen</span> S<span class="n">file</span> k<span class="n">cycles</span> <span class="o">=</span> i<span class="n">len</span> <span class="o">*</span> <span class="vg">kr</span><span class="c1">; number of k-cycles to write the fft-buffer</span> k<span class="n">count</span> <span class="nb">init</span> <span class="mi">0</span> <span class="nl">loop</span><span class="p">:</span> a<span class="n">in</span> <span class="nb">soundin</span> S<span class="n">file</span> <span class="n">fftin</span> <span class="nb">pvsanal</span> a<span class="n">in</span><span class="p">,</span> i<span class="n">fftsize</span><span class="p">,</span> i<span class="n">overlap</span><span class="p">,</span> i<span class="n">winsize</span><span class="p">,</span> i<span class="n">winshape</span> i<span class="n">buf</span><span class="p">,</span> k<span class="n">tim</span> <span class="nb">pvsbuffer</span> <span class="n">fftin</span><span class="p">,</span> i<span class="n">len</span> <span class="o">+</span> <span class="p">(</span>i<span class="n">fftsize</span> <span class="o">/</span> <span class="vg">sr</span><span class="p">)</span> <span class="k">loop_lt</span> k<span class="n">count</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> k<span class="n">cycles</span><span class="p">,</span> <span class="nl">loop</span> <span class="nb">xout</span> i<span class="n">buf</span><span class="p">,</span> i<span class="n">len</span><span class="p">,</span> k<span class="n">tim</span> <span class="k">endif</span> <span class="kd">endop</span> <span class="kd">instr</span> <span class="nf">1</span> i<span class="n">fftsize</span> <span class="o">=</span> <span class="mi">1024</span> i<span class="n">overlap</span> <span class="o">=</span> i<span class="n">fftsize</span> <span class="o">/</span> <span class="mi">4</span> i<span class="n">winsize</span> <span class="o">=</span> i<span class="n">fftsize</span> i<span class="n">winshape</span> <span class="o">=</span> <span class="mi">1</span><span class="c1">; von-Hann window</span> i<span class="n">buffer</span><span class="p">,</span> i<span class="n">len</span><span class="p">,</span> k<span class="n">0</span> <span class="nf">FileToPvsBuf</span> <span class="s">"fox.wav"</span><span class="p">,</span> i<span class="n">fftsize</span><span class="p">,</span> i<span class="n">overlap</span><span class="p">,</span> i<span class="n">winsize</span><span class="p">,</span> i<span class="n">winshape</span> k<span class="n">tmpnt</span> <span class="nb">linseg</span> i<span class="n">len</span><span class="p">,</span> <span class="nb">p3</span><span class="p">,</span> <span class="mi">0</span><span class="c1">; reads the buffer backwards in p3 seconds</span> <span class="n">fread</span> <span class="nb">pvsbufread</span> k<span class="n">tmpnt</span><span class="p">,</span> i<span class="n">buffer</span> a<span class="n">out</span> <span class="nb">pvsynth</span> <span class="n">fread</span> <span class="nb">out</span> a<span class="n">out</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">i</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">5</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1"> <a id="idm281472899758440"></a> <h2>See Also</h2> <p> <a class="link" href="pvsanal.html" title="pvsanal"><em class="citetitle">pvsanal</em></a>, <a class="link" href="pvsynth.html" title="pvsynth"><em class="citetitle">pvsynth</em></a>, <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>, <a class="link" href="pvsadsyn.html" title="pvsadsyn"><em class="citetitle">pvsadsyn</em></a> </p> </div> <div class="refsect1"> <a id="idm281472899753512"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Victor Lazzarini</td> </tr> <tr> <td>July 2007</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="pvsbuffer.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="pvsbufread2.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">pvsbuffer </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> pvsbufread2</td> </tr> </table> </div> </body> </html>