diff --git a/src/fft.c b/src/fft.c index 0436c24..41a7756 100644 --- a/src/fft.c +++ b/src/fft.c @@ -2,7 +2,9 @@ #include "settings.h" /** - * FFT algorithm + * === + * FFT + * === */ /** @@ -140,7 +142,9 @@ /** - * Average algorithm: + * =================================== + * Average frequency signal algorithm + * =================================== * - while (!bin limit reached): * --- compute bin upper and lower bound from bfreq * --- sum each fftBuf[i] for i in (lower, upper) @@ -152,12 +156,13 @@ average_signal(unsigned int *fftBuf, const int inLen, const int max, const double bf, const int oratio, unsigned int* fftAvg) { int i = 0; - int j = 0; int amp = 0; int first = 0; int last = 1; int div = 43/(N_SAMPLES/1024); // 1024 samples -> 43 reads / second double f = bf; + unsigned int noteIdx = 0; + unsigned int noteVal = 0; while(last <= N_SAMPLES/2) { @@ -172,15 +177,20 @@ last = ceil(upperbound(f, oratio) / div); if(last == first) first--; - for(j=first; j noteVal && i >= 1) { + noteVal = val; + noteIdx = i; + } for(int j=i; j max) break; f = next_bfreq(f, oratio); } + + for(i=0; i