Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- import java.util.ArrayList;
- SoundFile sample;
- Amplitude rms;
- int m = 10;
- int dim = 900;
- ArrayList<Float> loudness = new ArrayList<Float>();
- public void setup() {
- size(900, 900);
- sample = new SoundFile(this, "name.wav");
- sample.play();
- rms = new Amplitude(this);
- rms.input(sample);
- frameRate(24);
- }
- public void draw() {
- background(0);
- stroke(255);
- strokeWeight(4);
- float vol = rms.analyze();
- loudness.add(vol);
- for(int i = 0; i < loudness.size(); i++) {
- float y1 = map(loudness.get(i), 0, 1, dim/2, 0);
- float y2 = map(loudness.get(i), 0, 1, dim/2, dim);
- strokeCap(ROUND);
- line(i*m, dim/2, i*m, y1);
- line(i*m, dim/2, i*m, y2);
- }
- if (loudness.size() * m > width - 100) {
- loudness.remove(0);
- }
- if(!sample.isPlaying()) {
- noLoop();
- }
- }
- void draw1() {
- background(0);
- textSize(48);
- text(frameCount/60, width/2, height/2);
- if(!sample.isPlaying()) {
- noLoop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement