<?xml version="1.0"?>
<!DOCTYPE ladspa SYSTEM "ladspa-swh.dtd">
<?xml-stylesheet href="ladspa.css" type="text/css"?>

<ladspa>
  <global>
    <meta name="maker" value="Steve Harris &lt;steve@plugin.org.uk&gt;"/>
    <meta name="copyright" value="GPL"/>
    <meta name="properties" value="HARD_RT_CAPABLE"/>
    <code>
      #include "ladspa-util.h"
      #include "util/blo.h"
    </code>
  </global>

  <plugin label="fmOsc" id="1415" class="OscillatorPlugin">
    <name>FM Oscillator</name>

    <callback event="instantiate"><![CDATA[
      tables = blo_h_tables_new(1024);
      osc = blo_h_new(tables, BLO_SINE, (float)s_rate);
    ]]></callback>

    <callback event="run"><![CDATA[
      unsigned long pos;
      osc->wave = LIMIT(f_round(wave) - 1, 0, BLO_N_WAVES-1);

      tables = tables; // So gcc doesn't think it's unused

      for (pos = 0; pos < sample_count; pos++) {
	blo_hd_set_freq(osc, fm[pos]);
        buffer_write(output[pos], blo_hd_run_cub(osc));
      }
    ]]></callback>

    <callback event="cleanup"><![CDATA[
      blo_h_tables_free(plugin_data->tables);
      blo_h_free(plugin_data->osc);
    ]]></callback>

    <port label="wave" dir="input" type="control" hint="integer,default_1">
      <name>Waveform (1=sin, 2=tri, 3=squ, 4=saw)</name>
      <p>The shape of the waveform.</p>
      <p><![CDATA[
	\begin{tabular}{|r|l|}
	\hline
	Value & Waveform \\
	\hline \hline
	1 & Sine \\
	2 & Triangle \\
	3 & Square \\
	4 & Saw \\
        \hline
	\end{tabular}
      ]]></p>
      <range min="1" max="BLO_N_WAVES"/>
    </port>

    <port label="fm" dir="input" type="audio" hint="sample_rate,default_440">
      <name>Frequency (Hz)</name>
      <p>The frequency of the output (in Hertz).</p>
      <range min="-0.25" max="0.25"/>
    </port>

    <port label="output" dir="output" type="audio">
      <name>Output</name>
    </port>

    <instance-data label="tables" type="blo_h_tables *" />
    <instance-data label="osc" type="blo_h_osc *" />
  </plugin>
</ladspa>
