Page 217 - Hacking Roomba
P. 217
198 Part II — Fun Things to Do
easier to use than JavaSound normally is. For example, the following snippet is a complete
Processing sketch that loads an MP3 file, pitch shifts it up five semitones, and plays it.
import krisker.Ess.*;
Ess.start(this);
AudioChannel myChannel = new AudioChannel(“somesong.mp3”);
myChannel.filter(new PitchShift(Ess.calcShift(7)));
myChannel.play();
You can use Ess instead of the playNote() command in RoombaComm. Granted then the
sound is coming out of the computer instead of Roomba, but by using Ess’s pitch shifting abil-
ity you can get a fairly smooth glissando from pitch to pitch.
Ess is available at www.tree-axis.com/Ess/ and, like any Processing library, is installed by
unzipping its downloaded zip file into the libraries folder of the main Processing applica-
tion. After restarting Processing, Ess is visible when you use the Sketch ➪ Import Library menu
command.
Touchless Sensing
Another way of triggering pitch changes that is perhaps more theremin-like is to flip Roomba
over and use the cliff sensors as hand proximity sensors. Figure 10-8 shows how this works. By
holding your hand over one or more of the cliff sensors, you un-detect a cliff. The cliff sensors
are barrier sensors just like the wall sensor, but its logical sense is flipped and it’s called a cliff
sensor instead of a floor sensor. It’s more logical (and marketable) to say cliff sensor instead of
floor sensor.
But flipped over and used as a theremin, these cliff sensors work well detecting hands, as long
as your hand has its fingers together and is mostly parallel to the surface of Roomba. Listing 10-3
shows a variation of the previous code, called RoombaThereminToo. It includes the Ess library
method of making sound and has a modified version of parseRoombaSensors() to deal
with the fact that it should change pitch when not detecting a cliff. The other features of that
method are that by pressing both wheels down, it mutes the audio. Pressing the bump sensor
starts the audio back up again.
You’ve probably noticed that parseRoombaSensors() doesn’t actually change the pitch. It
sets the pshift variable but doesn’t act on it. That’s because changing the pitch of a sound
while it’s playing causes an audible glitch. By waiting for the sound to finish playing through
and changing its pitch before it loops again, the pitch transitions are smooth. In Ess, if the
method channelLoop() is declared in your sketch, it will be called when a sound is finished
playing. By adding that method and a check to see if pshift is actually set, the pitch (actu-
ally the rate here since it’s a faster computation and yields the same result) can be changed
seamlessly.