Created
October 17, 2011 19:56
-
-
Save ipa/1293613 to your computer and use it in GitHub Desktop.
mp3 player with fouriertransformation
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.signals.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.effects.*; | |
boolean isPlaying = false; | |
String filename; | |
AudioOutput out; | |
AudioPlayer song; | |
Minim minim; | |
FFT fft; | |
void setup() | |
{ | |
size(500, 300); | |
// init minim and sound playback | |
minim = new Minim(this); | |
//filename = getFile().getName(); | |
filename = "sample.mp3"; | |
song = minim.loadFile(filename); | |
out = minim.getLineOut(Minim.STEREO, 2048); | |
// fourier transformation | |
fft = new FFT(song.bufferSize(), song.sampleRate()); | |
} | |
void draw() | |
{ | |
background(0); | |
// show trackname | |
stroke(255, 255, 255); | |
text("Playing: " + filename, 5, 20); | |
// draw amplitude | |
stroke(0, 255, 0); | |
for (int i = 0; i < song.bufferSize() - 2; i++) | |
{ | |
line(i, 50-song.left.get(i)*90, i+1, 50- song.left.get(i+1)*90); | |
line(i, 150-song.right.get(i)*90, i+1, 150- song.right.get(i+1)*90); | |
} | |
// draw the foureir analysis | |
stroke(0, 0, 255); | |
fft.forward(song.mix); | |
for (int i = 0; i < fft.specSize(); i++) | |
{ | |
line(i, height, i, height - fft.getBand(i)*4); | |
} | |
} | |
void mousePressed() | |
{ | |
if (isPlaying) | |
{ | |
song.pause(); | |
fft.window(FFT.NONE); | |
isPlaying = false; | |
} | |
else | |
{ | |
song.play(); | |
fft.window(FFT.HAMMING); | |
isPlaying = true; | |
} | |
} | |
void stop() | |
{ | |
minim.stop(); | |
super.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment