Created
July 3, 2018 22:53
-
-
Save msurguy/7599f22bf6e6c46e682526dc1d601a91 to your computer and use it in GitHub Desktop.
soundwave plotter
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
| // Original : http://arch-2226-01.softlabnyc.com/class-1c-radial-sound-wave/ | |
| // Modified by Maksim Surguy to have constantly increasing diameter, different colors, more samples per second | |
| import ddf.minim.*; | |
| Minim minim; | |
| AudioInput sound; | |
| //set the buffer for the sound input: | |
| //this is how many samples are taken per frame | |
| int buffer = 4096; | |
| //array to hold the multiplied amplitude of samples | |
| float[] rad = new float[buffer]; | |
| void setup() { | |
| size(1024, 1024, P3D); | |
| pixelDensity(2); | |
| //frameRate(100); | |
| background(255); | |
| minim = new Minim(this); | |
| sound = minim.getLineIn(Minim.STEREO, buffer); | |
| } | |
| //the sound samples are between 0.0-1.0 | |
| //multiplier will amplify this to 0.0- the value of multiplier; | |
| int multiplier = 200; | |
| //initrad sets the initial radius of the circle | |
| float initrad = 100.0; | |
| void draw() { | |
| //background(0); | |
| for (int i = 0; i < sound.mix.size() - 1; i++) { | |
| //store the new multiplied values in an array | |
| rad[i] = sound.mix.get(i) * multiplier + initrad; | |
| } | |
| //multiplier += 1; | |
| initrad += 0.08; | |
| //get the step of the angle count to make one full revolution | |
| float angstep = 360.00/buffer; | |
| float angcount = 0; | |
| stroke(100, 0, 200, 20); | |
| strokeWeight(1); | |
| for (int i = 0; i < rad.length - 2; i++) { | |
| //get first x and y coordinate for the line | |
| float xpos1 = width/2 + rad[i] * cos(radians(angcount)); | |
| float ypos1 = height/2 + rad[i] * sin(radians(angcount)); | |
| //get second x and y coordinate for the line by getting the value | |
| //one step ahead in rad[] | |
| float xpos2 = width/2 + rad[i+1] * cos(radians(angcount)); | |
| float ypos2 = height/2 + rad[i+1] * sin(radians(angcount)); | |
| line(xpos1, ypos1, xpos2, ypos2); | |
| angcount = angcount + angstep; | |
| } | |
| } | |
| void keyPressed(){ | |
| if(key == 's'){ | |
| println("Saving..."); | |
| saveFrame("screen-####.jpg"); | |
| println("Done saving."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment