Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float highestValue;
- float lastValue;
- float lastAvgFreq;
- float avgFreq;
- float freq;
- int whaleDirection;
- float lastWhale;
- float kAvg;
- int j;
- int c;
- int k;
- float time;
- float baseFreq = 0;
- int t;
- int lastc;
- float wiggle = 2;
- float peaks[] = new float[1000];
- float distanceBetweenPeaks[] = new float[1000];
- float v;
- int checkFreq(){
- // perform a forward FFT on the samples in jingle's left buffer
- // note that if jingle were a MONO file,
- // this would be the same as using jingle.right or jingle.left
- fft.forward(in.mix);
- // freq = 0;
- c = 0;
- v = 0;
- k = 0;
- j = 0;
- kAvg = 0;
- highestValue = 0;
- for(int i = 0; i < fft.specSize(); i++)
- {
- lastValue = fft.getBand(i);
- if(lastValue > highestValue){
- highestValue = lastValue;
- //println("highest"+ highestValue);
- }
- }
- for(int i = 0; i < fft.specSize(); i++)
- {
- // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
- lastValue = fft.getBand(i);
- if(lastValue > (highestValue-(highestValue/1.05))&& highestValue > 4 ){
- peaks[c] = i;
- c ++;
- }
- } //END of FORLOOP
- for(int i = 0; i < c; i ++){
- if(peaks[i+1]-peaks[i]> 1 && peaks[i+1]-peaks[i] < 70){
- distanceBetweenPeaks[k] = peaks[i+1]-peaks[i];
- k++;
- }
- }
- //println(h);
- // println("AvgFreq"+avgFreq);
- for(int i = 0; i < k; i++){
- //println(distanceBetweenPeaks[i]);
- kAvg += distanceBetweenPeaks[i];
- }
- avgFreq = kAvg/k;
- //println(avgFreq);
- if(j<width && avgFreq > 4){
- j += 1;
- }else if(j>=width){
- j = 0;
- background(0);
- }
- if(keyPressed == true && key == 'r'){
- baseFreq = avgFreq;
- // println(baseFreq);
- go = true;
- }
- if(avgFreq > baseFreq+1){
- whaleDirection = 1;
- }
- else if(avgFreq < baseFreq-1 && avgFreq> baseFreq - 4){
- whaleDirection = -1;
- }
- else if (avgFreq > baseFreq-1 && avgFreq < baseFreq+1){
- whaleDirection = 0;
- }
- //Om det är tyst
- else if(avgFreq < baseFreq-4){
- whaleDirection = 3;
- }
- lastAvgFreq = avgFreq;
- lastWhale = whaleDirection;
- //println(avgFreq);
- return(whaleDirection);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement