<?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>upsamp</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="until.html" title="until" /> <link rel="next" href="urandom.html" title="urandom" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">upsamp</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="until.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="urandom.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="upsamp"> <a id="upsamp"></a> <div class="titlepage"></div> <a id="IndexUpsamp" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">upsamp</span> </h2> <p>upsamp — Modify a signal by up-sampling. </p> </div> <div class="refsect1" title="Description"> <a id="idp49841848"></a> <h2>Description</h2> <p> Modify a signal by up-sampling. </p> </div> <div class="refsect1" title="Syntax"> <a id="idp49842488"></a> <h2>Syntax</h2> <pre class="synopsis">ares <span class="command"><strong>upsamp</strong></span> ksig</pre> </div> <div class="refsect1" title="Performance"> <a id="idp49887272"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>upsamp</em></span> converts a control signal to an audio signal. It does it by simple repetition of the kval. <span class="emphasis"><em>upsamp</em></span> is a slightly more efficient form of the assignment, <span class="emphasis"><em>asig</em></span> = <span class="emphasis"><em>ksig</em></span>. </p> </div> <div class="refsect1" title="Examples"> <a id="idp49888880"></a> <h2>Examples</h2> <p> Here is an example of the upsamp opcode. It uses the file <a class="ulink" href="examples/upsamp.csd" target="_top"><em class="citetitle">upsamp.csd</em></a>. </p> <div class="example"> <a id="idp49889848"></a> <p class="title"> <strong>Example 909. Example of the upsamp opcode.</strong> </p> <div class="example-contents"> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></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 RT audio input is needed too</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o upsamp.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">;;with code from Steven Cook / David Akbari, Menno Knevel and Joachim Heintz</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">seed</span> 0 <span class="oblock">opcode</span> Decimator, a, akk <span class="comment">;UDO Sample rate / Bit depth reducer</span> <span class="comment">;see http://www.csounds.com/udo/displayOpcode.php?opcode_id=73</span> <span class="opc">setksmps</span> 1 ain, kbit, ksrate <span class="opc">xin</span> kbits <span class="op">=</span> 2^kbit <span class="comment">;bit depth (1 to 16)</span> kfold <span class="op">=</span> (<span class="ohdr">sr</span><span class="op">/</span>ksrate) <span class="comment">;sample rate</span> kin <span class="opc">downsamp</span> ain <span class="comment">;convert to kr</span> kin <span class="op">=</span> (kin<span class="op">+</span>0dbfs) <span class="comment">;add DC to avoid (-)</span> kin <span class="op">=</span> kin<span class="op">*</span>(kbits<span class="op">/</span>(<span class="ohdr">0dbfs</span><span class="op">*</span>2)) <span class="comment">;scale signal level</span> kin <span class="op">=</span> <span class="opc">int</span>(kin) <span class="comment">;quantise</span> aout <span class="opc">upsamp</span> kin <span class="comment">;convert to sr</span> aout <span class="op">=</span> aout<span class="op">*</span>(2<span class="op">/</span>kbits)<span class="op">-</span><span class="ohdr">0dbfs</span> <span class="comment">;rescale and remove DC</span> a0ut <span class="opc">fold</span> aout, kfold <span class="comment">;resample</span> <span class="opc">xout</span> a0ut <span class="oblock">endop</span> <span class="oblock">instr</span> 1 <span class="comment">;avoid playing this too loud</span> kbit <span class="op">=</span> p4 ksr <span class="op">=</span> 44100 asig <span class="opc">diskin</span> "fox.wav", 1 aout Decimator asig, kbit, ksr <span class="opc">printks</span> "bitrate <span class="op">=</span> <span class="op">%</span>d, ", 3, kbit <span class="opc">printks</span> "with samplerate <span class="op">=</span> <span class="op">%</span>d\\n", 3, ksr <span class="opc">outs</span> aout<span class="op">*</span>.7, aout<span class="op">*</span>.7 <span class="oblock">endin</span> <span class="oblock">instr</span> 2 <span class="comment">;moving randomly between different bit values (1 - 6)</span> kbit <span class="opc">randomi</span> 1, 6, .5, 1 asig <span class="opc">diskin</span> "fox.wav", 1, 0, 1 <span class="comment">;loop play</span> aout Decimator asig, kbit, 44100 <span class="opc">printks</span> "bitrate <span class="op">=</span> <span class="op">%</span>f\n", .3, kbit <span class="opc">outs</span> aout<span class="op">*</span>.7, aout<span class="op">*</span>.7 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">i</span> 1 0 3 16 <span class="comment">;sounds allright but</span> <span class="stamnt">i</span> 1 + 3 5 <span class="comment">;it's getting worse</span> <span class="stamnt">i</span> 1 + 3 2 <span class="comment">;and worse...</span> <span class="stamnt">i</span> 2 9 22 <span class="comment">;or quality moves randomly</span> <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1" title="See Also"> <a id="idp49890856"></a> <h2>See Also</h2> <p> <a class="link" href="diff.html" title="diff"><em class="citetitle">diff</em></a>, <a class="link" href="downsamp.html" title="downsamp"><em class="citetitle">downsamp</em></a>, <a class="link" href="integ.html" title="integ"><em class="citetitle">integ</em></a>, <a class="link" href="interp.html" title="interp"><em class="citetitle">interp</em></a>, <a class="link" href="samphold.html" title="samphold"><em class="citetitle">samphold</em></a> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="until.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="urandom.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">until </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> urandom</td> </tr> </table> </div> </body> </html>