Home‎ > ‎Unit 11‎ > ‎

Create a Tone

We can make tones in processing using the Minim library. The easiest way to experiment with it is to go to File->Examples->Libraries->Minim. For this Lesson you should open up SineWaveSignal.

Run the program. As you move your mouse around in the window you should hear changes in the sound. You'll notice that both the volume and the pitch change.

Lets break down what we see:
The opening block imports the piece of the Minim library that we need, just like we had to import the Arduino library. 

Minim minim;  //Creates an instance of Minim called minim
AudioOutput out;  //Creates an instance of the AudioOut procedure called "out"
SineWave sine;  //Creates an instance of the SineWave procedure called "sine"

These names could be anything. For example you could just as easily have:  SineWave bob;


Our setup procedure has some new stuff. The comments do a pretty good job of explaining, I'll just expand a little. Portamento is an actual term used in music and is very important for electronic synthesizers. It deals with how quickly the note will change. Set it to 20 and then 2000, or try sine.noPortamento(). You should hear clear differences.

If you're going to want to play more than one note at a time you'll need to create more instances of SineWave at the top and then reproduce some of the setup lines, for example:


The code above will set us up to play two notes at the same time. Think chords here. If you want three or four notes you'll need three or four instances of SineWave. The draw procedure of this sketch just shows us the wave form of the sound we're hearing. We'll go into how it works in another lesson.

In the mouseMoved() procedure you see where the frequency changes happen. The table below shows some basic commands.
 sine.setFreq(##)Will create a frequency(pitch) at the number specified
 sine.setPan(##)Sets speaker ballance. The number should be between -1 and 1. -1 Means left speaker only +1 means right speaker only
 sine.setAmp(##)Adjusts volume. The number should be between 0 and 1. 0 means off and 1 means full volume

Other fun stuff to try. This sketch produces a sine wave, but can als produce a square wave or sawtooth wave. Try each and see how the sound differs. To do this you need to change the SineWave instance to SquareWave or SawWave. You need to do this both at the top and in the setup procedure.

Assignment 11.2:
Build an optical Theremin (hook up your Arduino with a photoresistor). Modify the SineWaveSignal sketch to use the sensor values to change the frequency. Bonus: Change the circuit so that you can get two analog values and use one of them to change the volume while the other still changes pitch or use the two analog values to create two notes at the same time.
Comments