Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Processing Sound Library, Example 6
- *
- * This sketch shows how to use the Amplitude class to analyze a
- * stream of sound. In this case a sample is analyzed. The smoothFactor
- * variable determines how much the signal will be smoothed on a scale
- * from 0 - 1.
- */
- import processing.sound.*;
- // Declare the processing sound variables
- SoundFile sample;
- Amplitude rms;
- Boolean on = false;
- String title = "4seasons";
- // Declare a scaling factor
- float scale = 4.0;
- // Declare a smooth factor
- float smoothFactor = 0.25;
- // Used for smoothing
- float sum;
- void setup() {
- size(800, 800, P2D);
- smooth(8);
- background(238);
- //Load and play a soundfile and loop it
- sample = new SoundFile(this, title+".mp3");
- sample.loop();
- // Create and patch the rms tracker
- rms = new Amplitude(this);
- rms.input(sample);
- }
- void draw() {
- strokeWeight(1);
- noFill();
- if (on) {
- stroke(238, 10);
- } else {
- stroke(35, 10);
- }
- if (frameCount==4000) {
- save(title + "_" + frameCount +".png"); //on =! on;
- noLoop();
- }
- // 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);
- println(frameCount);
- }
- void keyPressed() {
- save(title + "_" + frameCount +".png");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement