Created
February 14, 2015 16:41
-
-
Save zeroeth/19bf31689290c6e5577a to your computer and use it in GitHub Desktop.
wave form trail
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
| /** | |
| * This sketch demonstrates how to play a file with Minim using an AudioPlayer. <br /> | |
| * It's also a good example of how to draw the waveform of the audio. | |
| * <p> | |
| * For more information about Minim and additional features, | |
| * visit http://code.compartmental.net/minim/ | |
| */ | |
| import ddf.minim.*; | |
| Minim minim; | |
| AudioPlayer player; | |
| void setup() | |
| { | |
| size(512, 200, P3D); | |
| // we pass this to Minim so that it can load files from the data directory | |
| minim = new Minim(this); | |
| // loadFile will look in all the same places as loadImage does. | |
| // this means you can find files that are in the data folder and the | |
| // sketch folder. you can also pass an absolute path, or a URL. | |
| player = minim.loadFile("Dyman_-_03_-_Kill_The_Flesh.mp3"); | |
| // play the file from start to finish. | |
| // if you want to play the file again, | |
| // you need to call rewind() first. | |
| player.play(); | |
| } | |
| void draw() | |
| { | |
| background(0); | |
| stroke(255); | |
| // draw the waveforms | |
| // the values returned by left.get() and right.get() will be between -1 and 1, | |
| // so we need to scale them up to see the waveform | |
| // note that if the file is MONO, left.get() and right.get() will return the same value | |
| for(int i = 0; i < player.bufferSize() - 1; i++) | |
| { | |
| // use player.mix.level() for kirby scaling | |
| float x1 = map( i, 0, player.bufferSize(), 0, width ); | |
| float x2 = map( i+1, 0, player.bufferSize(), 0, width ); | |
| stroke(map(i, 0, 1024, 0, 255), 0, 0); | |
| line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 ); | |
| line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment