<!-- Converted to DocBook/SGML by Kevin Conder -->
<refentry id="GEN33">
  <refmeta>
    <refentrytitle>GEN33</refentrytitle>
  </refmeta>

  <refnamediv>
    <refname>GEN33</refname>
    <refpurpose>
      Generate composite waveforms by mixing simple sinusoids.
      <indexterm id="IndexGEN33"><primary>GEN33</primary></indexterm>
    </refpurpose>
  </refnamediv>
  
  <refsect1>
    <title>Description</title>
    <para>
      These routines generate composite waveforms by mixing simple sinusoids, similarly to <link linkend="GEN09"><citetitle>GEN09</citetitle></link>, but the parameters of the partials are specified in an already existing table, which makes it possible to calculate any number of partials in the orchestra.
    </para>

    <para>
      The difference between <emphasis>GEN33</emphasis> and <link linkend="GEN34"><citetitle>GEN34</citetitle></link> is that <emphasis>GEN33</emphasis> uses inverse FFT to generate output, while <emphasis>GEN34</emphasis> is based on the algorithm used in oscils opcode. <emphasis>GEN33</emphasis> allows integer partials only, and does not support power of two plus 1 table size, but may be significantly faster with a large number of partials. On the other hand, with <emphasis>GEN34</emphasis>, it is possible to use non-integer partial numbers and extended guard point, and this routine may be faster if there is only a small number of partials (note that <emphasis>GEN34</emphasis> is also several times faster than <link linkend="GEN09"><citetitle>GEN09</citetitle></link>, although the latter may be more accurate).
    </para>
  </refsect1>

  <refsect1>
    <title>Syntax</title>
    <synopsis><command>f</command> # time size  33  src nh scl [fmode]</synopsis>
  </refsect1>

  <refsect1>
    <title>Initialization</title>
    <para>
      <emphasis>size</emphasis> -- number of points in the table. Must be power of two and at least 4.
    </para>

    <para>
      <emphasis>src</emphasis> -- source table number. This table contains the parameters of each partial in the following format:
      <literallayout>
stra, pna, phsa, strb, pnb, phsb, ...
     </literallayout>

     the parameters are:

     <itemizedlist>
       <listitem><para>stra, strb, etc.: relative strength of partials. The actual amplitude depends on the value of scl, or normalization (if enabled).</para></listitem>
       <listitem><para>pna, pnb, etc.:   partial number, or frequency, depending on fmode (see below); zero and negative values are allowed, however, if the absolute value of the partial number exceeds (size / 2), the partial will not be rendered. With <emphasis>GEN33</emphasis>, partial number is rounded to the nearest integer.</para></listitem>
       <listitem><para>phsa, phsb, etc.: initial phase, in the range 0 to 1.</para></listitem>
     </itemizedlist>

     Table length (not including the guard point) should be at least 3 * nh. If the table is too short, the number of partials (nh) is reduced to (table length) / 3, rounded towards zero.
    </para>

    <para>
      <emphasis>nh</emphasis> -- number of partials. Zero or negative values are allowed, and result in an empty table (silence). The actual number may be reduced if the source table (src) is too short, or some partials have too high frequency.
    </para>

    <para>
      <emphasis>scl</emphasis> -- amplitude scale.
    </para>

    <para>
      <emphasis>fmode</emphasis> (optional, default = 0) -- a non-zero value can be used to set frequency in Hz instead of partial numbers in the source table.  The sample rate is assumed to be fmode if it is positive, or -(sr * fmode) if any negative value is specified.
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      <informalexample>
        <programlisting>
; partials 1, 4, 7, 10, 13, 16, etc. with base frequency of 400 Hz

ibsfrq  =  400
; estimate number of partials
inumh   =  int(1.5 + sr * 0.5 / (3 * ibsfrq))
; source table length
isrcln  =  int(0.5 + exp(log(2) * int(1.01 + log(inumh * 3) / log(2))))
; create empty source table
itmp    ftgen 1, 0, isrcln, -2, 0
ifpos   =  0
ifrq    =  ibsfrq
inumh   =  0
l1:
        tableiw ibsfrq / ifrq, ifpos, 1         ; amplitude
        tableiw ifrq, ifpos + 1, 1              ; frequency
        tableiw 0, ifpos + 2, 1                 ; phase
ifpos   =  ifpos + 3
ifrq    =  ifrq + ibsfrq * 3
inumh   =  inumh + 1
        if (ifrq < (sr * 0.5)) igoto l1

; store output in ftable 2 (size = 262144)

itmp    ftgen 2, 0, 262144, -34, 1, inumh, 1, -1
        </programlisting>
      </informalexample>
    </para>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="GEN09"><citetitle>GEN09</citetitle></link>,
      <link linkend="GEN34"><citetitle>GEN34</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>
      <simplelist>
        <member>Programmer: &nameistvan;</member>
        <member>March 2002</member>
      </simplelist>
    </para>

    <para>New in version 4.19</para>
  </refsect1>
</refentry>
