loudness-wave

Generates a video recording of a .wav file's loudness.
git clone http://git.hanabi.in/repos/loudness-wave.git
Log | Files | Refs | README | LICENSE

wave.pde (1510B)


      1 import processing.sound.*;
      2 import java.util.ArrayList;
      3 import com.hamoid.*;
      4 
      5 SoundFile sample;
      6 Amplitude rms;
      7 VideoExport videoExport;
      8 
      9 int m = 10;
     10 int dim = 900;
     11 boolean record = true; 
     12 ArrayList<Float> loudness = new ArrayList<Float>();
     13 String audioFile = "/Users/acagastya/documents/repo/wave/sound.wav";
     14 String videoFile = "/Users/acagastya/video.mkv";
     15 
     16 public void setup() {
     17   size(1000, 900);
     18   sample = new SoundFile(this, audioFile);
     19   sample.play();
     20   rms = new Amplitude(this);
     21   rms.input(sample);
     22   frameRate(24);
     23   videoExport = new VideoExport(this, videoFile);
     24   videoExport.setFrameRate(24);  
     25   if(record) {
     26     videoExport.startMovie();
     27   }
     28 }      
     29 
     30 public void draw() {
     31   textSize(48);
     32   if(record) {
     33     videoExport.saveFrame();
     34   }
     35   background(0);
     36   stroke(255);
     37   strokeWeight(4);
     38   float vol = rms.analyze();
     39   loudness.add(vol);
     40   for(int i = 0; i < loudness.size(); i++) {
     41     float y1 = map(loudness.get(i), 0, 1, dim/2, dim*0.1);
     42     float y2 = map(loudness.get(i), 0, 1, dim/2, dim*0.9);
     43     strokeCap(ROUND);
     44     line(i*m, dim/2, i*m, y1);
     45     line(i*m, dim/2, i*m, y2);
     46   }
     47   stroke(255, 0, 0);
     48   strokeWeight(1);
     49   line(loudness.size() * m, height/2, width, height/2);
     50   line(loudness.size() * m, 0, loudness.size() * m, height);
     51   fill(255, 0, 0);
     52   circle(loudness.size() * m, height/2, 12);
     53   if (loudness.size() * m > width - 100) {
     54     loudness.remove(0);
     55   }
     56   if(!sample.isPlaying()) {
     57     noLoop();
     58     if(record) {
     59       videoExport.endMovie();
     60     }
     61     exit();
     62   }
     63 }