Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. float highestValue;
  2. float lastValue;
  3. float lastAvgFreq;
  4. float avgFreq;
  5. float freq;
  6. int whaleDirection;
  7. float lastWhale;
  8. float kAvg;
  9. int j;
  10. int c;
  11. int k;
  12. float time;
  13. float baseFreq = 0;
  14. int t;
  15. int lastc;
  16. float wiggle = 2;
  17. float peaks[] = new float[1000];
  18. float distanceBetweenPeaks[] = new float[1000];
  19. float v;
  20.  
  21.  
  22. int checkFreq(){
  23. // perform a forward FFT on the samples in jingle's left buffer
  24. // note that if jingle were a MONO file,
  25. // this would be the same as using jingle.right or jingle.left
  26. fft.forward(in.mix);
  27. // freq = 0;
  28. c = 0;
  29. v = 0;
  30. k = 0;
  31. j = 0;
  32. kAvg = 0;
  33. highestValue = 0;
  34.  
  35. for(int i = 0; i < fft.specSize(); i++)
  36. {
  37. lastValue = fft.getBand(i);
  38. if(lastValue > highestValue){
  39. highestValue = lastValue;
  40. //println("highest"+ highestValue);
  41. }
  42. }
  43.  
  44. for(int i = 0; i < fft.specSize(); i++)
  45. {
  46. // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
  47. lastValue = fft.getBand(i);
  48. if(lastValue > (highestValue-(highestValue/1.05))&& highestValue > 4 ){
  49. peaks[c] = i;
  50. c ++;
  51. }
  52. } //END of FORLOOP
  53.  
  54. for(int i = 0; i < c; i ++){
  55. if(peaks[i+1]-peaks[i]> 1 && peaks[i+1]-peaks[i] < 70){
  56. distanceBetweenPeaks[k] = peaks[i+1]-peaks[i];
  57. k++;
  58. }
  59. }
  60. //println(h);
  61. // println("AvgFreq"+avgFreq);
  62. for(int i = 0; i < k; i++){
  63. //println(distanceBetweenPeaks[i]);
  64. kAvg += distanceBetweenPeaks[i];
  65. }
  66. avgFreq = kAvg/k;
  67. //println(avgFreq);
  68. if(j<width && avgFreq > 4){
  69. j += 1;
  70. }else if(j>=width){
  71. j = 0;
  72. background(0);
  73. }
  74.  
  75. if(keyPressed == true && key == 'r'){
  76. baseFreq = avgFreq;
  77. // println(baseFreq);
  78. go = true;
  79. }
  80. if(avgFreq > baseFreq+1){
  81. whaleDirection = 1;
  82. }
  83. else if(avgFreq < baseFreq-1 && avgFreq> baseFreq - 4){
  84. whaleDirection = -1;
  85. }
  86. else if (avgFreq > baseFreq-1 && avgFreq < baseFreq+1){
  87. whaleDirection = 0;
  88. }
  89. //Om det är tyst
  90. else if(avgFreq < baseFreq-4){
  91. whaleDirection = 3;
  92. }
  93.  
  94.  
  95. lastAvgFreq = avgFreq;
  96. lastWhale = whaleDirection;
  97. //println(avgFreq);
  98. return(whaleDirection);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement