Created
March 16, 2016 10:38
-
-
Save anonymous/ea7418b0556705ea710b to your computer and use it in GitHub Desktop.
Processing demo visualizing audio input data
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
import processing.sound.*; | |
// Declare the processing sound variables | |
SoundFile sample; | |
Amplitude rms; | |
// Declare a scaling factor | |
float scale = 5.0; | |
// Declare a smooth factor | |
float smoothFactor = 0.25; | |
// Used for smoothing | |
float sum; | |
void setup() { | |
size(640, 360); | |
//Load and play a soundfile and loop it | |
sample = new SoundFile(this, "04 Stumble.mp3"); | |
sample.loop(); | |
// Create and patch the rms tracker | |
rms = new Amplitude(this); | |
rms.input(sample); | |
} | |
void draw() { | |
// Set background color, noStroke and fill color | |
background(0, 0, 255); | |
noStroke(); | |
fill(255, 0, 150); | |
// Smooth the rms data by smoothing factor | |
sum += (rms.analyze() - sum) * smoothFactor; | |
// rms.analyze() return a value between 0 and 1. It's | |
// scaled to height/2 and then multiplied by a scale factor | |
float rmsScaled = sum * (height/2) * scale; | |
// Draw an ellipse at a size based on the audio analysis | |
ellipse(width/2, height/2, rmsScaled, rmsScaled); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment