Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. import ddf.minim.*;
  3. import ddf.minim.analysis.*;
  4.  
  5.  
  6. Minim minim;
  7. AudioPlayer song;
  8. FFT fft;
  9.  
  10. float[][] lineArray; //holds the FFT data
  11. float[][] tempLineArray; //holds the temp FFT data to shift FFT data down the screen
  12.  
  13. int cols = 600; //width of lines across
  14. int rows = 62; //number of lines down
  15. int xoffset = 150; //X offset
  16. int yoffset = 12; //distance between lines
  17. int yshift = 100; //Y shift from top of screen
  18.  
  19.  
  20. void setup(){
  21. size(900,900);
  22. background(0);
  23. smooth();
  24.  
  25. minim = new Minim(this);
  26. song = minim.loadFile("song.mp3",1024);
  27. song.play();
  28. fft = new FFT( song.bufferSize(), song.sampleRate() );
  29.  
  30. lineArray = new float[cols][rows];
  31. tempLineArray = new float[cols][rows];
  32. }
  33.  
  34. void draw(){
  35. background(0);
  36. stroke(180);
  37. strokeWeight(2);
  38. fill(0);
  39. sound();
  40. displayLines();
  41. }
  42.  
  43.  
  44. void sound(){ //writes current band to 0 position of lineArray
  45.  
  46. for(int i = 0; i < cols; i++)
  47. {
  48. lineArray[i][0]=song.left.get(i)*30;
  49. }
  50.  
  51. }
  52.  
  53. void displayLines(){
  54.  
  55. for(int x = 0; x<rows-1;x++){ //shifts all lineArray data to tempLineArray down one then writes it back to lineArray
  56. for(int i = 0; i < cols;i++){
  57. tempLineArray[i][x+1]=lineArray[i][x];
  58. lineArray[i][x]=tempLineArray[i][x];
  59.  
  60. }
  61. }
  62.  
  63. for(int y =1;y<rows-1;y++){
  64.  
  65. beginShape();
  66. vertex(xoffset,height);
  67.  
  68. for(int x=0;x<cols;x++){
  69.  
  70. vertex(xoffset+x,lineArray[x][y]+y*yoffset+yshift);
  71.  
  72. }
  73.  
  74. vertex(width-xoffset,height);
  75. endShape(CLOSE);
  76. }
  77. noStroke();
  78. rect(0,0,xoffset+5,height);
  79. rect(width-xoffset-5,0,width,height);
  80. fill(180);
  81. textFont(createFont("arial.ttf",75));
  82. text("TALKING HEADS", xoffset, yshift-15);
  83. fill(255);
  84. textFont(createFont("arialbd.ttf",49));
  85. text("NOTHING BUT FLOWERS", xoffset, height-10);
  86.  
  87. }
  88.  
  89.  
  90. void mousePressed(){
  91. noLoop();
  92. }
  93.  
  94.  
  95. void stop(){
  96. minim.stop();
  97. super.stop();
  98. song.close();
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement