<?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>xtratim</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="xscanu.html" title="xscanu" /> <link rel="next" href="xyin.html" title="xyin" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">xtratim</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="xscanu.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="xyin.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="xtratim"> <a id="xtratim"></a> <div class="titlepage"></div> <a id="IndexXtratim" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">xtratim</span> </h2> <p>xtratim — Extend the duration of real-time generated events. </p> </div> <div class="refsect1" title="Description"> <a id="idp54455224"></a> <h2>Description</h2> <p> Extend the duration of real-time generated events and handle their extra life (Usually for usage along with <a class="link" href="release.html" title="release"><em class="citetitle">release</em></a> instead of <a class="link" href="linenr.html" title="linenr"><em class="citetitle">linenr</em></a>, <a class="link" href="linsegr.html" title="linsegr"><em class="citetitle">linsegr</em></a>, etc). </p> </div> <div class="refsect1" title="Syntax"> <a id="idp54457376"></a> <h2>Syntax</h2> <pre class="synopsis"><span class="command"><strong>xtratim</strong></span> iextradur</pre> </div> <div class="refsect1" title="Initialization"> <a id="idp54514920"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>iextradur</em></span> -- additional duration of current instrument instance </p> </div> <div class="refsect1" title="Performance"> <a id="idp54515872"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>xtratim</em></span> extends current MIDI-activated note duration by <span class="emphasis"><em>iextradur</em></span> seconds after the corresponding noteoff message has deactivated the current note itself. It is usually used in conjunction with <a class="link" href="release.html" title="release"><em class="citetitle">release</em></a>. This opcode has no output arguments. </p> <p> This opcode is useful for implementing complex release-oriented envelopes, whose duration is not known when the envelope starts (e.g. for real-time MIDI generated events). </p> </div> <div class="refsect1" title="Examples"> <a id="idp54518216"></a> <h2>Examples</h2> <p> Here is a simple example of the xtratim opcode. It uses the file <a class="ulink" href="examples/xtratim.csd" target="_top"><em class="citetitle">xtratim.csd</em></a>. </p> <div class="example"> <a id="idp54519208"></a> <p class="title"> <strong>Example 1005. Example of the xtratim 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> <p>This example shows how to generate a release segment for an ADSR envelope after a MIDI noteoff is received, extending the duration with <span class="emphasis"><em>xtratim</em></span> and using <a class="link" href="release.html" title="release"><em class="citetitle">release</em></a> to check whether the note is on the release phase.</p> <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> <span class="comment">; Audio out Audio in Silent MIDI in</span> -odac -iadc -d -M0 <span class="comment">;;;realtime I/O</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">;Simple usage of the xtratim opcode</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="comment">; sine wave for oscillators</span> gisin <span class="ohdr">ftgen</span> 1, 0, 4096, 10, 1 <span class="oblock">instr</span> 1 inum <span class="opc">notnum</span> icps <span class="opc">cpsmidi</span> iamp <span class="opc">ampmidi</span> 4000 <span class="comment">;</span> <span class="comment">;------- complex envelope block ------</span> <span class="opc">xtratim</span> 1 <span class="comment">;extra-time, i.e. release dur</span> krel <span class="opc">init</span> 0 krel <span class="opc">release</span> <span class="comment">;outputs release-stage flag (0 or 1 values)</span> <span class="octrl">if</span> (krel <span class="op">==</span> 1) <span class="octrl">kgoto</span> rel <span class="comment">;if in release-stage goto release section</span> <span class="comment">;</span> <span class="comment">;************ attack and sustain section ***********</span> kmp1 <span class="opc">linseg</span> 0, .03, 1, .05, 1, .07, 0, .08, .5, 4, 1, 50, 1 kmp <span class="op">=</span> kmp1<span class="op">*</span>iamp <span class="octrl">kgoto</span> done <span class="comment">;</span> <span class="comment">;--------- release section --------</span> rel<span class="op">:</span> kmp2 <span class="opc">linseg</span> 1, .3, .2, .7, 0 kmp <span class="op">=</span> kmp1<span class="op">*</span>kmp2<span class="op">*</span>iamp done<span class="op">:</span> <span class="comment">;------</span> a1 <span class="opc">oscili</span> kmp, icps, gisin <span class="opc">outs</span> a1, a1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">f</span> 0 3600 <span class="comment">;dummy table to wait for realtime MIDI events</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> <p> Here is a more elaborate example of the xtratim opcode. It uses the file <a class="ulink" href="examples/xtratim-2.csd" target="_top"><em class="citetitle">xtratim-2.csd</em></a>. </p> <div class="example"> <a id="idp54523152"></a> <p class="title"> <strong>Example 1006. More complex example of the xtratim opcode.</strong> </p> <div class="example-contents"> <p>This example shows how to generate a release segment for an ADSR envelope after a MIDI noteoff is received, extending the duration with <span class="emphasis"><em>xtratim</em></span> and using <a class="link" href="release.html" title="release"><em class="citetitle">release</em></a> to check whether the note is on the release phase. Two envelopes are generated simultaneously for the left and right channels.</p> <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> <span class="comment">; Audio out Audio in Silent MIDI in</span> -odac -iadc -d -M0 <span class="comment">;;;realtime I/O</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">;xtratim example by Jonathan Murphy Dec. 2006</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="comment">; sine wave for oscillators</span> gisin <span class="ohdr">ftgen</span> 1, 0, 4096, 10, 1 <span class="comment">; set volume initially to midpoint</span> <span class="ohdr">ctrlinit</span> 1, 7,64 <span class="comment">;;; simple two oscil, two envelope synth</span> <span class="oblock">instr</span> 1 <span class="comment">; frequency</span> kcps <span class="opc">cpsmidib</span> <span class="comment">; initial velocity (noteon)</span> ivel <span class="opc">veloc</span> <span class="comment">; master volume</span> kamp <span class="opc">ctrl7</span> 1, 7, 0, 127 kamp <span class="op">=</span> kamp <span class="op">*</span> ivel <span class="comment">; parameters for aenv1</span> iatt1 <span class="op">=</span> 0.03 idec1 <span class="op">=</span> 1 isus1 <span class="op">=</span> 0.25 irel1 <span class="op">=</span> 1 <span class="comment">; parameters for aenv2</span> iatt2 <span class="op">=</span> 0.06 idec2 <span class="op">=</span> 2 isus2 <span class="op">=</span> 0.5 irel2 <span class="op">=</span> 2 <span class="comment">; extra (release) time allocated</span> <span class="opc">xtratim</span> (irel1<span class="op">></span>irel2 <span class="op">?</span> irel1 <span class="op">:</span> irel2) <span class="comment">; krel is used to trigger envelope release</span> krel <span class="opc">init</span> 0 krel <span class="opc">release</span> <span class="comment">; if noteoff received, krel == 1, otherwise krel == 0</span> <span class="octrl">if</span> (krel <span class="op">==</span> 1) <span class="octrl">kgoto</span> <span class="olabel">rel</span> <span class="comment">; attack, decay, sustain segments</span> atmp1 <span class="opc">linseg</span> 0, iatt1, 1, idec1, isus1 , 1, isus1 atmp2 <span class="opc">linseg</span> 0, iatt2, 1, idec2, isus2 , 1, isus2 aenv1 <span class="op">=</span> atmp1 aenv2 <span class="op">=</span> atmp2 <span class="octrl">kgoto</span> <span class="olabel">done</span> <span class="comment">; release segment</span> <span class="olabel">rel</span><span class="op">:</span> atmp3 <span class="opc">linseg</span> 1, irel1, 0, 1, 0 atmp4 <span class="opc">linseg</span> 1, irel2, 0, 1, 0 aenv1 <span class="op">=</span> atmp1 <span class="op">*</span> atmp3 <span class="comment">;to go from the current value (in case</span> aenv2 <span class="op">=</span> atmp2 <span class="op">*</span> atmp4 <span class="comment">;the attack hasn't finished) to the release.</span> <span class="comment">; control oscillator amplitude using envelopes</span> <span class="olabel">done</span><span class="op">:</span> aosc1 <span class="opc">oscil</span> aenv1, kcps, gisin aosc2 <span class="opc">oscil</span> aenv2, kcps <span class="op">*</span> 1.5, gisin aosc1 <span class="op">=</span> aosc1 <span class="op">*</span> kamp aosc2 <span class="op">=</span> aosc2 <span class="op">*</span> kamp <span class="comment">; send aosc1 to left channel, aosc2 to right,</span> <span class="comment">; release times are noticably different</span> <span class="opc">outs</span> aosc1, aosc2 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">f</span> 0 3600 <span class="comment">;dummy table to wait for realtime MIDI events</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="idp54525320"></a> <h2>See Also</h2> <p> <a class="link" href="linenr.html" title="linenr"><em class="citetitle">linenr</em></a>, <a class="link" href="release.html" title="release"><em class="citetitle">release</em></a> </p> </div> <div class="refsect1" title="Credits"> <a id="idp54526856"></a> <h2>Credits</h2> <p>Author: Gabriel Maldonado</p> <p>Italy</p> <p>Examples by Gabriel Maldonado and Jonathan Murphy</p> <p>New in Csound version 3.47</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="xscanu.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="xyin.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">xscanu </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> xyin</td> </tr> </table> </div> </body> </html>