Advertisement
xeromino

sound

Mar 9th, 2017
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Processing Sound Library, Example 6
  3.  *
  4.  * This sketch shows how to use the Amplitude class to analyze a
  5.  * stream of sound. In this case a sample is analyzed. The smoothFactor
  6.  * variable determines how much the signal will be smoothed on a scale
  7.  * from 0 - 1.
  8.  */
  9.  
  10. import processing.sound.*;
  11.  
  12. // Declare the processing sound variables
  13. SoundFile sample;
  14. Amplitude rms;
  15.  
  16. // Declare a scaling factor
  17. float scale = 5.0;
  18.  
  19. // Declare a smooth factor
  20. float smoothFactor = 0.25;
  21.  
  22. // Used for smoothing
  23. float sum;
  24.  
  25. void setup() {
  26.   size(640, 360);
  27.  
  28.   //Load and play a soundfile and loop it
  29.   sample = new SoundFile(this, "beat.aiff");
  30.   sample.loop();
  31.  
  32.   // Create and patch the rms tracker
  33.   rms = new Amplitude(this);
  34.   rms.input(sample);
  35. }      
  36.  
  37. void draw() {
  38.  
  39.   // Smooth the rms data by smoothing factor
  40.   sum += (rms.analyze() - sum) * smoothFactor;  
  41.  
  42. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement