minim(al) visualization

minim(al) visual

So I was playing around with the minim library, recording voices and wondering If that’s how I really sound. My original plan was to save a recording, and play it back using the FSR, but I could only get it to work sometimes with the FilePlayer.

Instead, here’s a pretty/cool visualization of any song that plays. Personally, the visualization reminds me of Mega Man/Transformers.

To add your own song, just put the song file into the same Processing folder, and replace “Friend.mp3” with the name of the song file. To play the song, the force applied to the FSR has to be higher than 150.

//importing minim and serial libraries
import ddf.minim.*;
import processing.serial.*;

//for to play music
Minim minim; 
AudioPlayer player; 

//for the arduino connection
Serial myPort;

//force applied to fsr
int force;

float y = 0;
float x = 0;

void setup() {
  size(600, 600);
  smooth();
  colorMode(RGB);

  //code from class
  printArray(Serial.list());
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
  myPort.readStringUntil('\n'); 

  //start minim with this
  minim = new Minim (this);

  if (force > 150) //force applied to pressure sensor has to be higher than 150 
  {
    player = minim.loadFile ("Friend.mp3"); //replace this .mp3 file with the name of your .mp3 file
    player.play ( );
  }
}

//draws rectangles using matrix
void draw() {
  x+=0.02;
  y+=0.005;
  float n = noise(x);
  float t = noise(y);

  pushMatrix();
  stroke(70, 3, 11, 20);
  translate(310, -140);
  rotate(.8);
  fill (60, 170, 205, t*4);
  rect(t*(width)-50, n*height+10, 50*n, height/2*n);
  rect( n*height+10, t*(width)-50, height/2*n, 50*n);
  popMatrix();
}

//code from class for serial communication
void serialEvent(Serial _port) { //this is a callback function
  if (myPort == null) return;  //this is a hack to cover a bug where the port does not get set up in time.  
  //this says if the port is not set up yet, bail (for now.) 
  String input = myPort.readStringUntil('\n');
  if (input != null) {  //if a '\n' character has in fact now arrived
    input = input.trim();  //Take off the '\n' character
    force = int(input);  //Turn it into number 
    println(force);
  }
}

 

Leave a Reply