<?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>GEN03</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="ScoregensTop.html" title="Score Statements and GEN Routines" /> <link rel="prev" href="GEN02.html" title="GEN02" /> <link rel="next" href="GEN04.html" title="GEN04" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">GEN03</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="GEN02.html">Prev</a> </td> <th width="60%" align="center">Score Statements and GEN Routines</th> <td width="20%" align="right"> <a accesskey="n" href="GEN04.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="GEN03"> <a id="GEN03"></a> <div class="titlepage"></div> <a id="IndexGEN03" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">GEN03</span> </h2> <p>GEN03 — Generates a stored function table by evaluating a polynomial. </p> </div> <div class="refsect1" title="Description"> <a id="id3729240"></a> <h2>Description</h2> <p> This subroutine generates a stored function table by evaluating a polynomial in x over a fixed interval and with specified coefficients. </p> </div> <div class="refsect1" title="Syntax"> <a id="id3729255"></a> <h2>Syntax</h2> <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size 3 xval1 xval2 c0 c1 c2 ... cn</pre> </div> <div class="refsect1" title="Initialization"> <a id="id3730093"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>size </em></span> -- number of points in the table. Must be a power of 2 or a power-of-2 plus 1. </p> <p> <span class="emphasis"><em>xval1, xval2 </em></span> -- left and right values of the x interval over which the polynomial is defined (<span class="emphasis"><em>xval1</em></span> < <span class="emphasis"><em>xval2</em></span>). These will produce the 1st stored value and the (power-of-2 plus l)th stored value respectively in the generated function table. </p> <p> <span class="emphasis"><em>c0, c1, c2, ..., cn</em></span> -- coefficients of the nth-order polynomial </p> <p> <span class="emphasis"><em>C<sub>0</sub></em></span> + <span class="emphasis"><em>C<sub>1</sub>x</em></span> + <span class="emphasis"><em>C<sub>2</sub>x<sup>2</sup></em></span> + . . . + <span class="emphasis"><em>C<sub>n</sub>x<sup>n</sup></em></span> </p> <p> Coefficients may be positive or negative real numbers; a zero denotes a missing term in the polynomial. The coefficient list begins in p7, providing a current upper limit of 144 terms. </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> </p> <div class="itemizedlist"> <ul class="itemizedlist" type="disc"> <li class="listitem"> <p> The defined segment [fn(<span class="emphasis"><em>xval1</em></span>), fn(<span class="emphasis"><em>xval2</em></span>)] is evenly distributed. Thus a 512-point table over the interval [-1,1] will have its origin at location 257 (at the start of the 2nd half). Provided the extended guard point is requested, both fn(-1) and fn(1) will exist in the table. </p> </li> <li class="listitem"> <p> <span class="emphasis"><em>GEN03</em></span> is useful in conjunction with <a class="link" href="table.html" title="table"><em class="citetitle">table</em></a> or <a class="link" href="tablei.html" title="tablei"><em class="citetitle">tablei</em></a> for audio waveshaping (sound modification by non-linear distortion). Coefficients to produce a particular formant from a sinusoidal lookup index of known amplitude can be determined at preprocessing time using algorithms such as Chebyshev formulae. See also <a class="link" href="GEN13.html" title="GEN13"><em class="citetitle">GEN13</em></a>. </p> </li> </ul> </div> <p> </p> </td> </tr> </table> </div> </div> <div class="refsect1" title="Examples"> <a id="id3730256"></a> <h2>Examples</h2> <p> Here is a simple example of the GEN03 routine. It uses the files <a class="ulink" href="examples/gen03.csd" target="_top"><em class="citetitle">gen03.csd</em></a>. It fills a table with a 4th order polynomial function over the x-interval -1 to 1. The origin will be at the offset position 512. The function is post-normalized. Here is its diagram: </p> <div class="mediaobject"> <img src="images/gen03.png" alt="Diagram of the waveform generated by GEN03." /> <div class="caption"> <p>Diagram of the waveform generated by GEN03.</p> </div> </div> <p> </p> <div class="example"> <a id="id3730307"></a> <p class="title"> <b>Example 735. A simple example of the GEN03 routine.</b> </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> <span class="comment">; Audio out Audio in</span> -odac -iadc <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o gen03.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">; Initialize the global variables.</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">kr</span> <span class="op">=</span> 4410 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="comment">; Instrument #1.</span> <span class="oblock">instr</span> 1 <span class="comment">; Create an index over the length of our entire note.</span> kcps <span class="opc">init</span> 1<span class="op">/</span>p3 kndx <span class="opc">phasor</span> kcps <span class="comment">; Read Table #1 with our index.</span> ifn <span class="op">=</span> 1 ixmode <span class="op">=</span> 1 kamp <span class="opc">table</span> kndx, ifn, ixmode <span class="comment">; Create a sine wave, use the Table #1 values to control</span> <span class="comment">; the amplitude.</span> a1 <span class="opc">oscil</span> kamp<span class="op">*</span>30000, 440, 2 <span class="opc">out</span> a1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Table #1: a polynomial function (using GEN03).</span> <span class="stamnt">f</span> 1 0 1025 3 -1 1 5 4 3 2 2 1 <span class="comment">; Table #2, a sine wave.</span> <span class="stamnt">f</span> 2 0 16384 10 1 <span class="comment">; Play Instrument #1 for 2 seconds.</span> <span class="stamnt">i</span> 1 0 2 <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="id3730325"></a> <h2>See Also</h2> <p> <a class="link" href="GEN13.html" title="GEN13"><em class="citetitle">GEN13</em></a>, <a class="link" href="GEN14.html" title="GEN14"><em class="citetitle">GEN14</em></a>, and <a class="link" href="GEN15.html" title="GEN15"><em class="citetitle">GEN15</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="GEN02.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="ScoregensTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="GEN04.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">GEN02 </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> GEN04</td> </tr> </table> </div> </body> </html>