Last active
June 22, 2018 06:58
-
-
Save 8q/f7a644a48a1ac728a596bd38c357f7cb to your computer and use it in GitHub Desktop.
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 ddf.minim.spi.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.ugens.*; | |
import ddf.minim.effects.*; | |
Minim minim; | |
AudioPlayer player; | |
FFT fft; | |
boolean isFileSelected = false; | |
void setup() | |
{ | |
fullScreen(); | |
minim = new Minim(this); | |
selectInput("Select a file to process:", "fileSelected"); | |
noFill(); | |
} | |
void fileSelected(File selection) | |
{ | |
player = minim.loadFile(selection.getAbsolutePath(), 1024); | |
fft = new FFT(player.bufferSize(), player.sampleRate()); | |
isFileSelected = true; | |
} | |
void draw() | |
{ | |
if (!isFileSelected) return; | |
background(0); | |
strokeWeight(1); | |
fft.forward(player.mix); | |
pushMatrix(); | |
translate(0, height/2); | |
stroke(100); | |
for(int i = 0; i < player.bufferSize() - 1; i++) | |
{ | |
float x1 = map( i, 0, player.bufferSize(), 0, width ); | |
float x2 = map( i+1, 0, player.bufferSize(), 0, width ); | |
line( x1, player.left.get(i) * 50, x2, player.left.get(i+1) * 50 ); | |
} | |
popMatrix(); | |
pushMatrix(); | |
translate(width / 2, height / 2); | |
rotate(frameCount * 0.01); | |
stroke(127, 255, 212); | |
for (int i = 0; i <= fft.specSize(); i++) | |
{ | |
float r = 80; | |
float rad = map(i, 0, fft.specSize() / 2, 0, 2*PI) ; | |
float len = constrain(fft.getBand(i), 0, 80) * 3; | |
line(r * cos(rad), r * sin(rad), (r + len) * cos(rad), (r + len) * sin(rad)); | |
} | |
popMatrix(); | |
pushMatrix(); | |
stroke(200, 0, 0); | |
translate(width/2, height/2); | |
rotate(frameCount * 0.01); | |
beginShape(); | |
for (int i = 0; i < player.bufferSize(); i++) | |
{ | |
float rad = map( i, 0, player.bufferSize(), 0, 2*PI); | |
float r = 80 + player.left.get(i) * 40; | |
float x = r * cos(rad); | |
float y = r * sin(rad); | |
curveVertex(x, y); | |
} | |
endShape(); | |
popMatrix(); | |
float posx = map(player.position(), 0, player.length(), 0, width); | |
stroke(0, 200, 0); | |
line(posx, height-30, posx, height); | |
if ( player.isPlaying() ) | |
{ | |
text("Press any key to pause playback.", 10, 20 ); | |
} else | |
{ | |
text("Press any key to start playback.", 10, 20 ); | |
} | |
} | |
void keyPressed() | |
{ | |
if ( player.isPlaying() ) | |
{ | |
player.pause(); | |
} else if ( player.position() == player.length() ) | |
{ | |
player.rewind(); | |
player.play(); | |
} else | |
{ | |
player.play(); | |
} | |
} |
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 ddf.minim.spi.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.ugens.*; | |
import ddf.minim.effects.*; | |
Minim minim; | |
AudioPlayer player; | |
FFT fft; | |
boolean isFileSelected = false; | |
void setup() | |
{ | |
fullScreen(); | |
rectMode(CENTER); | |
minim = new Minim(this); | |
selectInput("Select a file to process:", "fileSelected"); | |
} | |
void fileSelected(File selection) | |
{ | |
player = minim.loadFile(selection.getAbsolutePath(), 1024); | |
fft = new FFT(player.bufferSize(), player.sampleRate()); | |
isFileSelected = true; | |
} | |
void draw() | |
{ | |
if (!isFileSelected) return; | |
background(0); | |
fft.forward(player.mix); | |
pushMatrix(); | |
translate(width /2, height / 2); | |
colorMode(HSB, 360, 100, 100, 100); | |
noStroke(); | |
for(int i = 0; i <= fft.specSize(); i++) | |
{ | |
fill(int(map(i, 0, fft.specSize(), 0, 720)) % 360, 80, 80, 80); | |
float diam = constrain(fft.getBand(i), 0, 80); | |
rect(map(i, 0, fft.specSize(), 0, width/2), 0, diam, diam * 3); | |
rect(map(i, 0, fft.specSize(), 0, -width/2), 0, diam, diam * 3); | |
} | |
popMatrix(); | |
colorMode(RGB); | |
float posx = map(player.position(), 0, player.length(), 0, width); | |
stroke(0, 200, 0); | |
line(posx, height-30, posx, height); | |
fill(255); | |
if ( player.isPlaying() ) | |
{ | |
text("Press any key to pause playback.", 10, 20 ); | |
} else | |
{ | |
text("Press any key to start playback.", 10, 20 ); | |
} | |
} | |
void keyPressed() | |
{ | |
if ( player.isPlaying() ) | |
{ | |
player.pause(); | |
} else if ( player.position() == player.length() ) | |
{ | |
player.rewind(); | |
player.play(); | |
} else | |
{ | |
player.play(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment