Prototyping – Second Iteration

I have now developed the second Iteration of my audio visualizer, with changes made to the way lines draw input from the audio and reflect the sound that plays.

import ddf.minim.*;

Minim minim;
AudioPlayer player;

int col1 = 100;
int col2 = 100;
int x ;
int y ;

void setup()
  size(1280, 620, P3D);
  background(0) ;
  smooth ();
  float x = 6;
  minim = new Minim(this);  
  player = minim.loadFile("time.mp3");

void draw()

  translate(0, 310);
  for (int i = 0; i < player.bufferSize () - 1; i++) {
      if (col1 < 255) {
    col1 = 75+int(player.right.get(i)*255) ;
    } else {
    col1 = 0;
    if (col2 < 255) {
      col2 = 75+int(player.left.get(i)*255) ;
    } else {
      col2 = 0;
  int y1 = int(player.left.get(i)*305);
  int y2 = int(player.right.get(i)*305);
    if (i == 0) {
  if (x < width) {
    x = x + 6;
  } else {
    x = 6;

void mousePressed (){
  background (0);

This iteration gets the values y1 and y2 in a different manner, I have translated the sketch’s origin point to halfway down the Y axis (line 26), and then calculated the values for y1 and y2 identically, but note that when it comes to drawing the lines (50, 52) the first line’s end Y value is 0-y1. As the origin is now halfway down the screen, one set of lines can be drawn with positive values (going down from 0, 0) and the other set can be drawn with negative Y values (sending them up from 0, 0).

The lines drawn start from the center and grow with amplitude.
The lines drawn start from the center and grow with amplitude.

The result appears to show a solution to one problem that was framed by my previous iteration – that the quietest amplitudes displayed full length bars. By using this new method to determine the height values of the lines, they now start small and grow at louder amplitudes, which more accurately reflects the audio input from a user’s perspective – as the track gets louder, the lines grow and light up more.

Closer inspection of the output of this iteration, however, shows some overlapping lines from the top and bottom half of the sketch. This would suggest that y1 and y2 are drawing negative values now, which poses a problem as my intention is for the top half of the screen to represent one side of the stereo audio and the bottom half, the other side. Still, this version shows a marked improvement in appearing to visualize audio to an audience, as the visual activity and vibrancy now matches the volume and complexity of the audio input.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s