Processing music

screen-shot-2016-10-11-at-9-06-18-pm

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer player;
AudioInput input;
AudioPlayer song;
BeatDetect beat;
// cube code taken from processing org tutorial
PGraphics cubeA;
boolean lines;
int X2 = 0;
int Y2 = 500;
int depth = 500;
int step = 0;

void setup()
{
size(1024, 400, P3D);
lights();

minim = new Minim(this);

// specify 512 for the length of the sample buffers
// the default buffer size is 1024
song = minim.loadFile(“funtonight.mp3”,1024);
song.play();
beat = new BeatDetect();
cubeA = createGraphics(width, height, P3D);
}

void draw()
{

//sphere code from processing tutorial
pushMatrix();
translate(width/2, height/2,-depth);
noFill();
stroke(255);
sphere(280);
popMatrix();

if (depth >= 250) {
step = 1;
}
if (step == 1) {
depth = depth-11;
}
if (depth <= -40) {
step = 2;
}
if (step == 2) {
depth = depth+11;
}

while (X2 <= 500) {
fill(3, 3, 3);
line(0, X2, 1024, Y2);
X2 = X2 + 10;
Y2 = Y2 – 10;
}
beat.detect(song.mix);
stroke(30, 120, 23);
// we draw the waveform by connecting neighbor values with a line
// we multiply each of the values by 50
// because the values in the buffers are normalized
// this means that they have values between -1 and 1.
// If we don’t scale them up our waveform
// will look more or less like a straight line.
for (int i = 0; i < song.bufferSize() – 1; i++)
{
line(i, 100 + song.left.get(i)*50, i+1, 100 + song.left.get(i+1)*50);
line(i, 300 + song.right.get(i)*50, i+1, 300 + song.right.get(i+1)*50);
}
if ( beat.isOnset() ) drawCube(cubeA, 100, 200);
tint(53, 11, 158);
image(cubeA, 0, 0);
}

//cube code from processing tutorial

void drawCube(PGraphics cube, float xd, float yd) {
cube.beginDraw();
cube.lights();
cube.clear();
cube.noStroke();
cube.translate(width/2, height/2);
cube.rotateX(frameCount/xd);
cube.rotateY(frameCount/yd);
cube.box(160);
cube.endDraw();
}

 

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