Created
December 30, 2015 19:19
-
-
Save coreygo/47ece7955e53d07eb781 to your computer and use it in GitHub Desktop.
Processing with Minim FFT/BeatDetection audio visualization. Includes code for Lissajous X/Y analysis and Fibonacci spirals.
This file contains 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 ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.signals.*; | |
Minim minim; | |
AudioPlayer player; | |
BeatDetect beat; | |
BeatListener bl; | |
ArrayList pos = new ArrayList(0); | |
float[] playerBuffer; | |
float A, X, Y; | |
float g = (sqrt(7) - 1) / 2.0; | |
float L = 1; | |
float theta; | |
int counter; | |
void setup() { | |
size(1920, 1080, P3D); | |
// bug: required for proper alpha opacity layering in P3D | |
hint(DISABLE_OPTIMIZED_STROKE); | |
smooth(); | |
frameRate(240); // overly optimistic, we're aiming for 60 | |
colorMode(HSB, 255, 255, 255); | |
minim = new Minim(this); | |
player = minim.loadFile("InTheLightOfKashmir.mp3", 2048); | |
playerBuffer = new float[player.bufferSize()]; | |
X = Y = 0; | |
beat = new BeatDetect(); | |
bl = new BeatListener(beat, player); | |
beat.setSensitivity(50); | |
counter = 1337*3; | |
} | |
void keyPressed() | |
{ | |
if (player.isPlaying()) | |
{ | |
player.pause(); | |
} else | |
{ | |
player.loop(); | |
} | |
} | |
void draw() { | |
background(0); | |
spiral(width/2, height/2, 0, counter); | |
lissajous(); | |
println("FPS: " + frameRate); // debug to show current framerate | |
} | |
void lissajous() { | |
// Lissajous + Bowditch | |
strokeWeight(1.5); | |
beginShape(); | |
for (int i = 0; i < player.bufferSize() - 1; i++) | |
{ | |
//stroke((i*.15), 0, 255, 255/32); | |
stroke(0, 0, 255, 255/32); | |
line(width/2+player.left.get(i+1)*1280, height/2-player.right.get(i+1)*720, width/2, height/2); | |
//point(width/2+player.left.get(i+1)*720, height/2-player.right.get(i+1)*720); | |
} | |
endShape(); | |
} | |
void spiral(float x, float y, float start, int many) { | |
// Fibonacci | |
beat.detect(player.mix); | |
X = x; | |
Y = y; | |
L = start; | |
//if ( L >= 10) { L += start; } | |
theta = map(counter, 0, width/2, 0, PI/4); | |
counter += ((player.mix.level()*60)/2); | |
if (beat.isOnset()) { | |
counter += 1337/2; | |
} | |
// prevents madness though there's room to improve counter reduction | |
// this is currently necessary but isn't smoothly implemented | |
// try commenting out this if statement to see the results | |
if (counter > 1337*3) { | |
counter -= 1337/1.85; | |
} | |
println("Counter: " + counter); // debug to show number of current lines in fib sequence | |
pushMatrix(); | |
for (int i = 0; i < many; i++) { | |
translate(X, Y); | |
rotate(theta); | |
strokeWeight(1); | |
stroke(255, 127/1.5); | |
line(0, L, 0, 0); | |
rotate(radians(noise((frameCount - i) * 0.001 * g) * 30.0 + 600)); | |
stroke((i * 0.22), 255, 255, 127); | |
line(L, 0, 0, 0); | |
translate(-X, -Y); | |
L += g; | |
X += L; | |
} | |
popMatrix(); | |
} | |
class BeatListener implements AudioListener | |
{ | |
private BeatDetect beat; | |
private AudioPlayer player; | |
BeatListener(BeatDetect beat, AudioPlayer source) | |
{ | |
this.player = source; | |
this.player.addListener(this); | |
this.beat = beat; | |
} | |
void samples(float[] samps) | |
{ | |
beat.detect(player.mix); | |
} | |
void samples(float[] sampsL, float[] sampsR) | |
{ | |
beat.detect(player.mix); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment