This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

This sketch demonstrates how to use a SineWave with an AudioOutput.
Move the mouse up and down to change the frequency, left and right to change the panning.

SineWave is a subclass of Oscillator, which is an abstract class that implements the interface AudioSignal.
This means that it can be added to an AudioOutput and the AudioOutput will call one of the two generate() 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 Oscillator that actually produces sound, you have to extend Oscillator and define the value function. This function takes a step value and returns a sample value between -1 and 1. In the case of the SineWave, the value function returns this: sin(freq * TWO_PI * step)
freq is the current frequency (in Hertz) of the Oscillator. It is multiplied by TWO_PI to set the period of the sine wave properly and then that sine wave is sampled at step.

Source code: SineWaveSignal

Built with Processing