Skip to content

Instantly share code, notes, and snippets.

@jaywon
Forked from anonymous/processingAudioDemo.java
Created March 16, 2016 10:38
Show Gist options
  • Save jaywon/7b86d3c49bd35c07758d to your computer and use it in GitHub Desktop.
Save jaywon/7b86d3c49bd35c07758d to your computer and use it in GitHub Desktop.
Processing demo visualizing audio input data
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