| 1 | |
| 2 | <refentry id="vco2init"> |
| 3 | <indexterm id="IndexVco2init"><primary>vco2init</primary></indexterm> |
| 4 | <refentryinfo><title>Signal Generators:Dynamic Spectrum Oscillators</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>vco2init</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>vco2init</refname> |
| 13 | <refpurpose> |
| 14 | Calculates tables for use by vco2 opcode. |
| 15 | </refpurpose> |
| 16 | </refnamediv> |
| 17 | |
| 18 | <refsect1> |
| 19 | <title>Description</title> |
| 20 | <para> |
| 21 | <emphasis>vco2init</emphasis> calculates tables for use by <link linkend="vco2"><citetitle>vco2</citetitle></link> opcode. Optionally, it is also possible to access these tables as standard Csound function tables. In this case, <link linkend="vco2ft"><citetitle>vco2ft</citetitle></link> can be used to find the correct table number for a given oscillator frequency. |
| 22 | </para> |
| 23 | |
| 24 | <para> |
| 25 | In most cases, this opcode is called from the orchestra header. Using <emphasis>vco2init</emphasis> in instruments is possible but not recommended. This is because replacing tables during performance can result in a Csound crash if other opcodes are accessing the tables at the same time. |
| 26 | </para> |
| 27 | |
| 28 | <para> |
| 29 | Note that <emphasis>vco2init</emphasis> is not required for <emphasis>vco2</emphasis> to work (tables are automatically allocated by the first <emphasis>vco2</emphasis> call, if not done yet), however it can be useful in some cases: |
| 30 | |
| 31 | <itemizedlist> |
| 32 | <listitem><para>Pre-calculate tables at orchestra load time. This is useful to avoid generating the tables during performance, which could interrupt real-time processing.</para></listitem> |
| 33 | <listitem><para>Share the tables as Csound ftables. By default, the tables can be accessed only by <link linkend="vco2"><citetitle>vco2</citetitle></link>.</para></listitem> |
| 34 | <listitem><para>Change the default parameters of tables (e.g. size) or use an user-defined waveform specified in a function table.</para></listitem> |
| 35 | </itemizedlist> |
| 36 | </para> |
| 37 | </refsect1> |
| 38 | |
| 39 | <refsect1> |
| 40 | <title>Syntax</title> |
| 41 | <synopsis>ifn <command>vco2init</command> iwave [, ibasfn] [, ipmul] [, iminsiz] [, imaxsiz] [, isrcft]</synopsis> |
| 42 | </refsect1> |
| 43 | |
| 44 | <refsect1> |
| 45 | <title>Initialization</title> |
| 46 | <para> |
| 47 | <emphasis>ifn</emphasis> -- the first free ftable number after the allocated tables. If <emphasis>ibasfn</emphasis> was not specified, -1 is returned. |
| 48 | </para> |
| 49 | |
| 50 | <para> |
| 51 | <emphasis>iwave</emphasis> -- sum of the following values selecting which waveforms are to be calculated: |
| 52 | |
| 53 | <itemizedlist> |
| 54 | <listitem><para>16: triangle</para></listitem> |
| 55 | <listitem><para>8: square wave</para></listitem> |
| 56 | <listitem><para>4: pulse (not normalized)</para></listitem> |
| 57 | <listitem><para>2: 4 * x * (1 - x) (integrated sawtooth)</para></listitem> |
| 58 | <listitem><para>1: sawtooth</para></listitem> |
| 59 | </itemizedlist> |
| 60 | </para> |
| 61 | |
| 62 | <para> |
| 63 | Alternatively, <emphasis>iwave</emphasis> can be set to a negative integer that selects an user-defined waveform. This also requires the <emphasis>isrcft</emphasis> parameter to be specified. <link linkend="vco2"><citetitle>vco2</citetitle></link> can access waveform number -1. However, other user-defined waveforms are usable only with <link linkend="vco2ft"><citetitle>vco2ft</citetitle></link> or <link linkend="vco2ift"><citetitle>vco2ift</citetitle></link>. |
| 64 | </para> |
| 65 | |
| 66 | <para> |
| 67 | <emphasis>ibasfn</emphasis> (optional, default=-1) -- ftable number from which the table set(s) can be accessed by opcodes other than <emphasis>vco2</emphasis>. This is required by user defined waveforms, with the exception of -1. If this value is less than 1, it is not possible to access the tables calculated by <emphasis>vco2init</emphasis> as Csound function tables. |
| 68 | </para> |
| 69 | |
| 70 | <para> |
| 71 | <emphasis>ipmul</emphasis> (optional, default=1.05) -- multiplier value for number of harmonic partials. If one table has n partials, the next one will have n * <emphasis>ipmul</emphasis> (at least n + 1). The allowed range for <emphasis>ipmul</emphasis> is 1.01 to 2. Zero or negative values select the default (1.05). |
| 72 | </para> |
| 73 | |
| 74 | <para> |
| 75 | <emphasis>iminsiz</emphasis> (optional, default=-1) -- minimum table size. |
| 76 | </para> |
| 77 | |
| 78 | <para> |
| 79 | <emphasis>imaxsiz</emphasis> (optional, default=-1) -- maximum table size. |
| 80 | </para> |
| 81 | |
| 82 | <para> |
| 83 | The actual table size is calculated by multiplying the square root of the number of harmonic partials by <emphasis>iminsiz</emphasis>, rounding up the result to the next power of two, and limiting this not to be greater than <emphasis>imaxsiz</emphasis>. |
| 84 | </para> |
| 85 | |
| 86 | <para> |
| 87 | Both parameters, <emphasis>iminsiz</emphasis> and <emphasis>imaxsiz</emphasis>, must be power of two, and in the allowed range. The allowed range is 16 to 262144 for <emphasis>iminsiz</emphasis> to up to 16777216 for <emphasis>imaxsiz</emphasis>. Zero or negative values select the default settings: |
| 88 | |
| 89 | <itemizedlist> |
| 90 | <listitem><para>The minimum size is 128 for all waveforms except pulse (<emphasis>iwave</emphasis>=4). Its minimum size is 256.</para></listitem> |
| 91 | <listitem><para>The default maximum size is usually the minimum size multiplied by 64, but not more than 16384 if possible. It is always at least the minimum size.</para></listitem> |
| 92 | </itemizedlist> |
| 93 | </para> |
| 94 | |
| 95 | <para> |
| 96 | <emphasis>isrcft</emphasis> (optional, default=-1) -- source ftable number for user-defined waveforms (if <emphasis>iwave</emphasis> < 0). <emphasis>isrcft</emphasis> should point to a function table containing the waveform to be used for generating the table array. The table size is recommended to be at least <emphasis>imaxsiz</emphasis> points. If <emphasis>iwave</emphasis> is not negative (built-in waveforms are used), <emphasis>isrcft</emphasis> is ignored. |
| 97 | </para> |
| 98 | |
| 99 | <warning> |
| 100 | <title>Warning</title> |
| 101 | <para> |
| 102 | The number and size of tables is not fixed. Orchestras should not depend on these parameters, as they are subject to changes between releases. |
| 103 | </para> |
| 104 | |
| 105 | <para> |
| 106 | If the selected table set already exists, it is replaced. If any opcode is accessing the tables at the same time, it is very likely that a crash will occur. This is why it is recommended to use <emphasis>vco2init</emphasis> only in the orchestra header. |
| 107 | </para> |
| 108 | |
| 109 | <para> |
| 110 | These tables should not be replaced/overwritten by GEN routines or the <emphasis>ftgen</emphasis> opcode. Otherwise, unpredictable behavior or a Csound crash may occur if <link linkend="vco2"><citetitle>vco2</citetitle></link> is used. The first free ftable after the table array(s) is returned in <emphasis>ifn</emphasis>. |
| 111 | </para> |
| 112 | </warning> |
| 113 | </refsect1> |
| 114 | |
| 115 | <refsect1> |
| 116 | <title>Examples</title> |
| 117 | <para> |
| 118 | Here is an example of the vco2init opcode. It uses the file <ulink url="examples/vco2init.csd"><citetitle>vco2init.csd</citetitle></ulink>. |
| 119 | <example> |
| 120 | <title>Example of the vco2init opcode.</title> |
| 121 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 122 | <xi:include href="examples-xml/vco2init.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 123 | </example> |
| 124 | Its output should include a line like these: |
| 125 | <screen> |
| 126 | i 1 time 0.00002: 103.00000 |
| 127 | i 1 time 0.10000: 103.00000 |
| 128 | i 1 time 0.20000: 103.00000 |
| 129 | i 1 time 0.30002: 103.00000 |
| 130 | i 1 time 0.40000: 104.00000 |
| 131 | i 1 time 0.50000: 104.00000 |
| 132 | ....... |
| 133 | ...... |
| 134 | i 1 time 4.80002: 135.00000 |
| 135 | i 1 time 4.90000: 136.00000 |
| 136 | i 1 time 5.00000: 138.00000 |
| 137 | </screen> |
| 138 | </para> |
| 139 | <para> |
| 140 | See the example for the <link linkend="vco2"><citetitle>vco2</citetitle></link> opcode too. |
| 141 | </para> |
| 142 | </refsect1> |
| 143 | |
| 144 | <refsect1> |
| 145 | <title>See Also</title> |
| 146 | <para> |
| 147 | <link linkend="SiggenDynamic"><citetitle>Dynamic Spectrum Oscillators</citetitle></link> |
| 148 | </para> |
| 149 | </refsect1> |
| 150 | |
| 151 | <refsect1> |
| 152 | <title>Credits</title> |
| 153 | <para>Author: &nameistvan;</para> |
| 154 | <para>New in version 4.22</para> |
| 155 | </refsect1> |
| 156 | </refentry> |