Advertisement
Guest User

Untitled

a guest
Jul 19th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import processing.sound.*;
  2. import java.util.ArrayList;
  3.  
  4. SoundFile sample;
  5. Amplitude rms;
  6. int m = 10;
  7. int dim = 900;
  8. ArrayList<Float> loudness = new ArrayList<Float>();
  9.  
  10. public void setup() {
  11. size(900, 900);
  12. sample = new SoundFile(this, "name.wav");
  13. sample.play();
  14. rms = new Amplitude(this);
  15. rms.input(sample);
  16. frameRate(24);
  17. }
  18.  
  19. public void draw() {
  20. background(0);
  21. stroke(255);
  22. strokeWeight(4);
  23. float vol = rms.analyze();
  24. loudness.add(vol);
  25. for(int i = 0; i < loudness.size(); i++) {
  26. float y1 = map(loudness.get(i), 0, 1, dim/2, 0);
  27. float y2 = map(loudness.get(i), 0, 1, dim/2, dim);
  28. strokeCap(ROUND);
  29. line(i*m, dim/2, i*m, y1);
  30. line(i*m, dim/2, i*m, y2);
  31. }
  32. if (loudness.size() * m > width - 100) {
  33. loudness.remove(0);
  34. }
  35. if(!sample.isPlaying()) {
  36. noLoop();
  37. }
  38. }
  39.  
  40. void draw1() {
  41. background(0);
  42. textSize(48);
  43. text(frameCount/60, width/2, height/2);
  44. if(!sample.isPlaying()) {
  45. noLoop();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement