Creating a synthesizer
The second instrument we'll create is a synthesizer. We'll use a sine wave and a saw wave to generate an interesting sound. The keyboard will be used to hit notes, and the mouse will pan the sound from left to right.
How to do it...
You need to start by importing the minim
library and declare a Minim
object and an AudioOutput
object. We also need a SineWave
and a SawWave
object to generate the sound. In the setup()
function, we'll create both waves and add them to the output so you'll hear them.
import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; Minim minim; AudioOutput out; SineWave sine; SawWave saw; void setup() { size( 1024, 480 ); smooth(); strokeWeight( 2 ); minim = new Minim( this ); out = minim.getLineOut( Minim.STEREO ); sine = new SineWave( 130.816, 0.5, out.sampleRate() ); out.addSignal( sine ); saw = new SawWave( 65.4064, 1.0, out.sampleRate() ); out.addSignal( saw...