Advertisement
Guest User

Untitled

a guest
May 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import processing.sound.*;
  2.  
  3. FFT fft;
  4. AudioIn in;
  5. Amplitude amp;
  6. int bands = 4096;
  7. float[] spectrum = new float[bands];
  8. int f = 1;
  9.  
  10. static final int NUM_LINES = 10;
  11. float t;
  12.  
  13. void setup() {
  14. background(20);
  15. size(500, 500);
  16.  
  17. // Create an Input stream which is routed into the Amplitude analyzer
  18. fft = new FFT(this, bands);
  19. in = new AudioIn(this, 0);
  20. amp = new Amplitude(this);
  21. // start the Audio Input
  22. in.start();
  23. amp.input(in);
  24. // patch the AudioIn
  25. fft.input(in);
  26. }
  27.  
  28. void draw() {
  29. fft.analyze(spectrum);
  30. background(20);
  31. stroke(255);
  32. strokeWeight(5);
  33.  
  34. translate(width/2, height/2);
  35.  
  36. int highestIndex = 0;
  37. for (int i = 0; i < bands / 4; i++) {
  38. if (spectrum[i] > spectrum[highestIndex]) {
  39. highestIndex = i;
  40. }
  41. }
  42.  
  43. for (int i = 0; i < NUM_LINES; i++) {
  44. line(x1(t + i), y1(t + i), x2(t + i), y2(t + i));
  45. }
  46.  
  47. println((int) (amp.analyze() * 100));
  48.  
  49. f = (int) (amp.analyze() * 50);
  50.  
  51. t += f;
  52. }
  53.  
  54. float x1(float t) {
  55. return sin(t / 5) * 100 + sin(t / 5) * 20;
  56. }
  57.  
  58. float y1(float t) {
  59. return cos(t / 10) * 100;
  60. }
  61.  
  62. float x2(float t) {
  63. return sin(t / 10) * 200 + sin(t) * 2 + sin(t) * 2;
  64. }
  65.  
  66. float y2(float t) {
  67. return cos(t / 20) * 200 + cos(t / 12) * 20;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement