Created
October 3, 2014 15:30
-
-
Save sydlawrence/e446dd391cc0c3000532 to your computer and use it in GitHub Desktop.
Simple music viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import Minim library | |
import ddf.minim.*; | |
//for displaying the sound's frequency | |
import ddf.minim.analysis.*; | |
Minim minim; | |
//to make it play song files | |
AudioPlayer song; | |
//for displaying the sound's frequency | |
FFT fft; | |
void setup() { | |
//sketch size | |
int w = 7016; | |
int h = 9933; | |
float scale = 0.333; | |
size(int(w*scale), int(h*scale)); | |
background(#000000); | |
minim = new Minim(this); | |
//load the song you want to play | |
//drag the file into your sketch window | |
//and replace "mysong.mp3" with the file name | |
song = minim.loadFile("mysong.mp3"); | |
song.play(); | |
fft = new FFT(song.bufferSize(), song.sampleRate()); | |
} | |
void draw() { | |
fft.forward(song.mix); | |
strokeWeight(1); | |
stroke(#FFF700, 30); | |
pushMatrix(); | |
translate(0, 0); | |
int chunk = height / 200; | |
for(int i = 0; i < 0+100; i++) | |
{ | |
line(width/2, i + height/2, width/2 - fft.getBand(i)*3 * chunk, height/2 - i * chunk); | |
line(width/2, i + height/2, width/2 + fft.getBand(i)*3 * chunk, height/2 - i * chunk); | |
line(width/2, i + height/2, width/2 - fft.getBand(i)*3 * chunk, i * chunk + height/2); | |
line(width/2, i + height/2, width/2 + fft.getBand(i)*3 * chunk, i * chunk + height/2); | |
} | |
popMatrix(); | |
for(int i = 0; i < height / chunk; i++) | |
{ | |
float x = random(30); | |
stroke(x,x,x, 30); | |
line(width/2 + song.mix.get(i)*800, i * chunk, width/2 + song.mix.get(i+1)*10, i * chunk +chunk); | |
} | |
} | |
void stop() | |
{ | |
song.close(); | |
minim.stop(); | |
super.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment