Created
November 30, 2011 17:01
-
-
Save atduskgreg/1409809 to your computer and use it in GitHub Desktop.
Filtering an mp3 file with minim
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.effects.*; | |
float passBand; | |
float bandWidth; | |
Minim minim; | |
AudioPlayer player; | |
BandPass bandFilter; | |
void setup() | |
{ | |
size(500, 200); | |
minim = new Minim(this); | |
player = minim.loadFile("Example.mp3"); | |
player.loop(); | |
// make a band pass filter with a center frequency of 440 Hz and a bandwidth of 20 Hz | |
// the third argument is the sample rate of the audio that will be filtered | |
// it is required to correctly compute values used by the filter | |
bandFilter = new BandPass(440, 20, player.sampleRate()); | |
player.addEffect(bandFilter); | |
textSize(20); | |
} | |
void draw() | |
{ | |
background(0); | |
text("passBand: " + passBand + "\nbandWidth: " + bandWidth, 50, 50); | |
} | |
void mouseMoved() | |
{ | |
// map the mouse position to the range [100, 10000], an arbitrary range of passBand frequencies | |
passBand = map(mouseX, 0, width, 100, 2000); | |
bandFilter.setFreq(passBand); | |
//bandWidth = map(mouseY, 0, height, 50, 500); | |
bandWidth = 200; | |
bandFilter.setBandWidth(bandWidth); | |
} | |
void stop() | |
{ | |
// always close Minim audio classes when you finish with them | |
player.close(); | |
// always stop Minim before exiting | |
minim.stop(); | |
super.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment