ref: 5a703bdbe5426d3328311e60db0a33bd34a951d1
parent: 22ec93ac96befd2fdec8b2d975a5ba7a68e15b6d
author: Paul Brossier <piem@piem.org>
date: Wed Nov 14 21:03:02 EST 2018
[fft] fix reconstruction for odd sizes (fftw only)
--- a/src/spectral/fft.c
+++ b/src/spectral/fft.c
@@ -493,11 +493,22 @@
compspec->data[i]);
}
#endif
- if (compspec->data[compspec->length/2] < 0) {
- spectrum->phas[spectrum->length - 1] = PI;
+#ifdef HAVE_FFTW3
+ // for even length only, make sure last element is 0 or PI
+ if (2 * (compspec->length / 2) == compspec->length) {
+#endif
+ if (compspec->data[compspec->length/2] < 0) {
+ spectrum->phas[spectrum->length - 1] = PI;
+ } else {
+ spectrum->phas[spectrum->length - 1] = 0.;
+ }
+#ifdef HAVE_FFTW3
} else {
- spectrum->phas[spectrum->length - 1] = 0.;
+ i = spectrum->length - 1;
+ spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
+ compspec->data[i]);
}
+#endif
}
void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) {
@@ -507,8 +518,19 @@
spectrum->norm[i] = SQRT(SQR(compspec->data[i])
+ SQR(compspec->data[compspec->length - i]) );
}
- spectrum->norm[spectrum->length-1] =
- ABS(compspec->data[compspec->length/2]);
+#ifdef HAVE_FFTW3
+ // for even length, make sure last element is > 0
+ if (2 * (compspec->length / 2) == compspec->length) {
+#endif
+ spectrum->norm[spectrum->length-1] =
+ ABS(compspec->data[compspec->length/2]);
+#ifdef HAVE_FFTW3
+ } else {
+ i = spectrum->length - 1;
+ spectrum->norm[i] = SQRT(SQR(compspec->data[i])
+ + SQR(compspec->data[compspec->length - i]) );
+ }
+#endif
}
void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {