src/spectral/fft.c: fix horrible bug where norm[0] and norm[n/2+1] could be negative
authorPaul Brossier <piem@piem.org>
Mon, 21 Sep 2009 16:15:05 +0000 (18:15 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 21 Sep 2009 16:15:05 +0000 (18:15 +0200)
src/spectral/fft.c

index 31159a563d87e83f61ede1fe1e2a1f6a8075ff89..7c77083220ac7a25231dc43e42f8ecc7b3fdfa83 100644 (file)
@@ -169,12 +169,13 @@ void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
   uint_t i, j = 0;
   for (i = 0; i < spectrum->channels; i++) {
-    spectrum->norm[i][0] = compspec->data[i][0];
+    spectrum->norm[i][0] = ABS(compspec->data[i][0]);
     for (j=1; j < spectrum->length - 1; j++) {
       spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j]) 
           + SQR(compspec->data[i][compspec->length - j]) );
     }
-    spectrum->norm[i][spectrum->length-1] = compspec->data[i][compspec->length/2];
+    spectrum->norm[i][spectrum->length-1] = 
+      ABS(compspec->data[i][compspec->length/2]);
   }
 }