Processing Audio

I got into Processing when I saw that it was a way to interface my desktop computer with an Arduino. Since then I’ve been exploring Processing more and seeing what it can do.

The latest excursion has been into audio, and I found a library called minim to play with. Download it, unzip it, and drop the ‘minim’ folder into your ‘libraries’ folder in your Processing folder, and you’re ready to go. Here’s my first experiment.

There’s an example for AudioInput which shows audio waveforms, so I grabbed the example and modified it slightly, I mainly twiddled the numbers a bit for a larger display.

Audio Waveform

Here’s the (slightly modified) code. (1280×800 being the screen size of my MacBook.)

 * WavyLines.pde

import ddf.minim.*;

Minim minim;
AudioInput in;

void setup()
  size(1280, 800, P3D);
  minim = new Minim(this);
  in = minim.getLineIn(Minim.STEREO, 1280);

void draw()
  // draw the waveforms
  for(int i = 0; i < in.bufferSize() - 1; i++)
    line(i, 250 + in.left.get(i)*150, i+1, 250 + in.left.get(i+1)*150);
    line(i, 550 + in.right.get(i)*150, i+1, 550 + in.right.get(i+1)*150);

void stop()
  // always close Minim audio classes when you are done with them

This code (at least on Mac OS X) runs and expects the sound input to be the built-in mic on the MacBook. This is pretty fun, and my daughter (who plays the trumpet) had a good time making all sorts of strange noises and watching the waveforms that were generated. If you export it from Processing as an application, you can run it full screen with no menubar, etc.

While the mic input is fun, you can also build yourself a little audio visualizer that reacts to what audio your computer is playing. There’s a bit in the manual about Setting the System Mixers, but I just went the Soundflower route here.

Once you’ve got Soundflower installed, you can set up your audio routing…

Sound Out
Sound In

Here’s my sound output and sound input settings in System Preferences.

Fire up Soundflowerbed, and then choose a song in iTunes and our “WavyLines” application should respond appropriately.


Here’s what you should get… well, depending on the audio playing. Maybe I can team up with the guys in the Handmade Music Group at the Milwaukee Makerspace and come up with some ways to enhance this into something even cooler.