graphic-processing-site-examples-Libraries-Minim--Sound--SineWaveSignal-SineWaveSignal.pde / pde
Sine Wave Signal
by Damien Di Fede.
This sketch demonstrates how to use a <code>SineWave</code> with
an <code>AudioOutput</code>. Move the mouse up and down to change
the frequency, left and right to change the panning.
<code>SineWave</code> is a subclass of <code>Oscillator</code>, which
is an abstract class that implements the interface AudioSignal
.
This means that it can be added to an <code>AudioOutput</code> and the
<code>AudioOutput</code> will call one of the two <code>generate()</code>
functions, depending on whether the AudioOutput is STEREO or MONO.
Since it is an abstract class, it can't be directly instantiated, it
merely provides the functionality of smoothly changing frequency, amplitude
and pan. In order to have an <code>Oscillator</code> that actually
produces sound, you have to extend <code>Oscillator</code> and define
the value function. This function takes a <b>step</b> value and returns
a sample value between -1 and 1. In the case of the SineWave,
the value function returns this: <b>sin(freq * TWO_PI * step)</b>
<b>freq</b> is the current frequency (in Hertz) of the <code>Oscillator</code>.
It is multiplied by <b>TWO_PI</b> to set the period of the sine wave
properly and then that sine wave is sampled at <b>step</b>.
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.