Visual Music Project

 

Code:

import processing.video.*;
import blobDetection.*;
import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer player;
AudioInput input;
AudioPlayer song;
BeatDetect beat;
Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;
int i = 0;
float eRadius;

void setup() {
size(1280,720,P3D);
background(100,0,255);

minim = new Minim(this);
song = minim.loadFile(“Disco_Medusae2.mp3”,1280);
song.play();
beat = new BeatDetect();

ellipseMode(RADIUS);
eRadius = 20;

String[] cameras = Capture.list();

if (cameras == null) {
println(“Failed to retrieve the list of available cameras, will try the default…”);
cam = new Capture(this, 640, 480, 30);
} if (cameras.length == 0) {
println(“There are no cameras available for capture.”);
exit();
} else {
println(“Available cameras:”);
printArray(cameras);

cam = new Capture(this, cameras[0]);

cam.start();
}

img = new PImage(80,60);
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(true);
theBlobDetection.setThreshold(0.4f);

}

void captureEvent(Capture cam)
{
cam.read();
newFrame = true;
}

void draw() {
beat.detect(song.mix);
float a = map(eRadius, 20, 80, 60, 255);
if ( beat.isOnset() ) eRadius = 80;
eRadius *= 0.95;
if ( eRadius < 20 ) eRadius = 20;

if (cam.available() == true) {
cam.read();
}
if (newFrame)
{
newFrame=false;
img.copy(cam, 0, 0, cam.width, cam.height,
0, 0, img.width, img.height);
fastblur(img, 2);
theBlobDetection.computeBlobs(img.pixels);
drawBlobsAndEdges(true,true);
}
}

void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges){
for(int i = 0; i < song.bufferSize() – 1; i++)
noFill();
Blob b;
EdgeVertex eA,eB;
for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
{
b=theBlobDetection.getBlob(n);
if (b!=null)
{
if (drawEdges)
{
strokeWeight(75);
stroke(100+ song.right.get(i)*100, 150 + eRadius, 50 * song.left.get(i)*100);
for (int m=0;m<b.getEdgeNb();m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(eA.x*width, eA.y*height, eB.x*width, eB.y*height );
}
}

if (drawBlobs)
{
fill(255,0,0,100);
ellipse(b.xMin*width, b.yMin*height ,eRadius, eRadius);
}

}

}
}

void fastblur(PImage img,int radius)
{
if (radius<1){
return;
}
int w=img.width;
int h=img.height;
int wm=w-1;
int hm=h-1;
int wh=w*h;
int div=radius+radius+1;
int r[]=new int[wh];
int g[]=new int[wh];
int b[]=new int[wh];
int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
int vmin[] = new int[max(w,h)];
int vmax[] = new int[max(w,h)];
int[] pix=img.pixels;
int dv[]=new int[256*div];
for (i=0;i<256*div;i++){
dv[i]=(i/div);
}

yw=yi=0;

for (y=0;y<h;y++){
rsum=gsum=bsum=0;
for(i=-radius;i<=radius;i++){
p=pix[yi+min(wm,max(i,0))];
rsum+=(p & 0xff0000)>>16;
gsum+=(p & 0x00ff00)>>8;
bsum+= p & 0x0000ff;
}
for (x=0;x<w;x++){

r[yi]=dv[rsum];
g[yi]=dv[gsum];
b[yi]=dv[bsum];

if(y==0){
vmin[x]=min(x+radius+1,wm);
vmax[x]=max(x-radius,0);
}
p1=pix[yw+vmin[x]];
p2=pix[yw+vmax[x]];

rsum+=((p1 & 0xff0000)-(p2 & 0xff0000))>>16;
gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8;
bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff);
yi++;
}
yw+=w;
}

for (x=0;x<w;x++){
rsum=gsum=bsum=0;
yp=-radius*w;
for(i=-radius;i<=radius;i++){
yi=max(0,yp)+x;
rsum+=r[yi];
gsum+=g[yi];
bsum+=b[yi];
yp+=w;
}
yi=x;
for (y=0;y<h;y++){
pix[yi]=0xff000000 | (dv[rsum]<<16) | (dv[gsum]<<8) | dv[bsum];
if(x==0){
vmin[y]=min(y+radius+1,hm)*w;
vmax[y]=max(y-radius,0)*w;
}
p1=x+vmin[y];
p2=x+vmax[y];

rsum+=r[p1]-r[p2];
gsum+=g[p1]-g[p2];
bsum+=b[p1]-b[p2];

yi+=w;
}
}

}

 

For this Project I decided to use webcam visuals along with music to create a the program. I chose music that had a good beat to it so it had a similar feel to the visuals with the spiky circles and other blobs. By having the spiky visuals and vibrant intense colors, it helps you feel and see the music better than just listening. You could also use other electronic or beat heavy music to have a similar effect. At the end, when the song is over, the color of the blobs stays the same, so when the music ends, basically so does the program, and it makes for an very intense short burst of energy while it the visuals are happening. I used blob detection to create the spiky looking lines and circles for the visuals. It tracks movement and is based on a certain brightness that is shown on objects. For the music, I used beat detection and used the sounds from the music to change the sizes of the circles and also change the color of the blobs.

Advertisements
This entry was posted in Time-Based and tagged , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s