<?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>GEN13</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="GEN12.html" title="GEN12" /> <link rel="next" href="GEN14.html" title="GEN14" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">GEN13</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="GEN12.html">Prev</a> </td> <th width="60%" align="center">Score Statements and GEN Routines</th> <td width="20%" align="right"> <a accesskey="n" href="GEN14.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="GEN13"> <a id="GEN13"></a> <div class="titlepage"></div> <a id="IndexGEN13" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">GEN13</span> </h2> <p>GEN13 — Stores a polynomial whose coefficients derive from the Chebyshev polynomials of the first kind. </p> </div> <div class="refsect1" title="Description"> <a id="id3735308"></a> <h2>Description</h2> <p> Uses Chebyshev coefficients to generate stored polynomial functions which, under waveshaping, can be used to split a sinusoid into harmonic partials having a pre-definable spectrum. </p> </div> <div class="refsect1" title="Syntax"> <a id="id3735325"></a> <h2>Syntax</h2> <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size 13 xint xamp h0 h1 h2 ...</pre> </div> <div class="refsect1" title="Initialization"> <a id="id3735540"></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 (see <a class="link" href="f.html" title="f Statement (or Function Table Statement)"><em class="citetitle">f statement</em></a>). The normal value is power-of-2 plus 1. </p> <p> <span class="emphasis"><em>xint</em></span> -- provides the left and right values [<span class="emphasis"><em>-xint, +xint</em></span>] of the x interval over which the polynomial is to be drawn. These subroutines both call <a class="link" href="GEN03.html" title="GEN03"><em class="citetitle">GEN03</em></a> to draw their functions; the p5 value here is therefor expanded to a negative-positive p5, p6 pair before <span class="emphasis"><em>GEN03</em></span> is actually called. The normal value is 1. </p> <p> <span class="emphasis"><em>xamp </em></span> -- amplitude scaling factor of the sinusoid input that is expected to produce the following spectrum. </p> <p> <span class="emphasis"><em>h0, h1, h2,</em></span> etc. -- relative strength of partials 0 (DC), 1 (fundamental), 2 ... that will result when a sinusoid of amplitude </p> <div class="literallayout"> <p><br /> xamp * int(size/2)/xint<br /> </p> </div> <p> is waveshaped using this function table. These values thus describe a frequency spectrum associated with a particular factor <span class="emphasis"><em>xamp</em></span> of the input signal. </p> <p> <span class="emphasis"><em>GEN13</em></span> is the function generator normally employed in standard waveshaping. It stores a polynomial whose coefficients derive from the Chebyshev polynomials of the first kind, so that a driving sinusoid of strength <span class="emphasis"><em>xamp</em></span> will exhibit the specified spectrum at output. Note that the evolution of this spectrum is generally not linear with varying <span class="emphasis"><em>xamp</em></span>. However, it is bandlimited (the only partials to appear will be those specified at generation time); and the partials will tend to occur and to develop in ascending order (the lower partials dominating at low <span class="emphasis"><em>xamp</em></span>, and the spectral richness increasing for higher values of <span class="emphasis"><em>xamp</em></span>). A negative <span class="emphasis"><em>hn</em></span> value implies a 180 degree phase shift of that partial; the requested full-amplitude spectrum will not be affected by this shift, although the evolution of several of its component partials may be. The pattern +,+,-,-,+,+,... for <span class="emphasis"><em>h0,h1,h2..</em></span>. will minimize the normalization problem for low <span class="emphasis"><em>xamp</em></span> values (see above), but does not necessarily provide the smoothest pattern of evolution. </p> </div> <div class="refsect1" title="Examples"> <a id="id3736310"></a> <h2>Examples</h2> <p> Here is a simple example of the GEN13 routine. It uses the file <a class="ulink" href="examples/gen13.csd" target="_top"><em class="citetitle">gen13.csd</em></a>. It creates a function which, under waveshaping, will split a sinusoid into 3 odd-harmonic partials of relative strength 5:3:1. Here is its diagram: </p> <div class="mediaobject"> <img src="images/gen13.png" alt="Diagram of the waveform generated by GEN13." /> <div class="caption"> <p>Diagram of the waveform generated by GEN13.</p> </div> </div> <p> </p> <div class="example"> <a id="id3736360"></a> <p class="title"> <b>Example 745. A simple example of the GEN13 routine.</b> </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"> <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 gen13.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 kval <span class="opc">table</span> kndx, ifn, ixmode <span class="comment">; Generate a sine waveform, use our Table #1 value to</span> <span class="comment">; vary its frequency by 100 Hz from its base frequency.</span> ibasefreq <span class="op">=</span> 440 kfreq <span class="op">=</span> kval <span class="op">*</span> 100 a1 <span class="opc">oscil</span> 20000, ibasefreq <span class="op">+</span> kfreq, 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 GEN13).</span> <span class="stamnt">f</span> 1 0 1025 13 1 1 0 5 0 3 0 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="id3736399"></a> <h2>See Also</h2> <p> <a class="link" href="GEN03.html" title="GEN03"><em class="citetitle">GEN03</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="GEN12.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="GEN14.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">GEN12 </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> GEN14</td> </tr> </table> </div> </body> </html>