Created
February 14, 2015 16:43
-
-
Save zeroeth/4c5886e7347597a91c5e to your computer and use it in GitHub Desktop.
dueling tracks
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 is an example of how to use the <code>level</code> method of an <code>AudioBuffer</code> to get the | |
| * level of one of an <code>AudioSource</code>'s sample buffers. The classes in Minim that extend <code>AudioSource</code> | |
| * and therefore inherit the <code>left</code>, <code>right</code>, and <code>mix</code> buffers of that class, are | |
| * <code>AudioInput</code>, <code>AudioOutput</code>, <code>AudioSample</code>, and <code>AudioPlayer</code>. | |
| * Not coincidentally, these are also all of the classes in Minim that are <code>Recordable</code>. | |
| * <p> | |
| * The value returned by <code>level</code> will always be between zero and one, but you may find that the value | |
| * returned is often smaller than you expect. The level is found by calculating the root-mean-squared amplitude of the | |
| * samples in the buffer. First the samples are all squared, then the average (mean) of all the samples is taken (sum | |
| * and then divide by the number of samples), then the square root of the average is returned. This is why the range can be | |
| * determined as [0, 1] because the largest value a squared sample can have is 1. However, in order for the RMS amplitude | |
| * to equal 1, every sample must have either -1 or 1 as its value (amplitude). This is only going to be the case | |
| * if your sound is a square wave at full amplitude. If your sound is a song or other complex sound source, | |
| * the level is generally going to be much lower. | |
| */ | |
| import ddf.minim.*; | |
| import ddf.minim.signals.*; | |
| Minim minim; | |
| AudioPlayer groove; | |
| AudioPlayer jam; | |
| void setup() | |
| { | |
| size(200, 200, P3D); | |
| minim = new Minim(this); | |
| groove = minim.loadFile("Dyman_-_03_-_Kill_The_Flesh.mp3"); | |
| jam = minim.loadFile("nervous_testpilot - Deus Ex - UNATCO remix.mp3"); | |
| groove.loop(); | |
| jam.loop(); | |
| rectMode(CORNERS); | |
| } | |
| void draw() | |
| { | |
| background(0); | |
| fill(255); | |
| groove.setGain(map(mouseX, 0, width, 0, -15)); | |
| jam.setGain(map(mouseX, 0, width, -15, 0)); | |
| rect(0, height, width/2, height - groove.mix.level()*height); | |
| rect(width/2, height, width, height - jam.mix.level()*height); | |
| } | |
| void stop() | |
| { | |
| // always close Minim audio classes when you finish with them | |
| groove.close(); | |
| jam.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