Index: src/fft.c
===================================================================
--- src/fft.c	(revision 17db1cde81719f3e7b3c85179d40105df19c209b)
+++ src/fft.c	(revision 237f63204499e5915eeb62088d4454c50d0aa84a)
@@ -29,4 +29,5 @@
 #define fftw_plan_dft_r2c_1d 	fftwf_plan_dft_r2c_1d
 #define fftw_plan_dft_c2r_1d 	fftwf_plan_dft_c2r_1d
+#define fftw_plan_r2r_1d      fftwf_plan_r2r_1d
 #define fftw_plan		fftwf_plan
 #define fftw_destroy_plan	fftwf_destroy_plan
@@ -47,4 +48,6 @@
 };
 
+static void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size);
+
 aubio_fft_t * new_aubio_fft(uint_t size) {
 	aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
@@ -54,6 +57,11 @@
 	s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
 	/* create plans */
+#ifdef HAVE_COMPLEX_H
 	s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
 	s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
+#else
+	s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
+	s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
+#endif
 	return s;
 }
@@ -89,15 +97,53 @@
 }
 
+#ifdef HAVE_COMPLEX_H
 
 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
 	uint_t i;
-	for (i=0;i<size;i++) norm[i] = ABSC(spectrum[i]);
+	for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
+	//for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
 }
 
 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
 	uint_t i;
-	for (i=0;i<size;i++) phas[i] = ARGC(spectrum[i]);
+	for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
+	//for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
 }
 
+void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
+  uint_t j;
+  for (j=0; j<size/2+1; j++) {
+    spectrum[j]  = CEXPC(I*phas[j]);
+    spectrum[j] *= norm[j];
+  }
+}
+
+#else
+
+void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
+	uint_t i;
+  norm[0] = -spectrum[0];
+	for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i]));
+	//for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
+}
+
+void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
+	uint_t i;
+  phas[0] = PI;
+	for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
+	//for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
+}
+
+void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
+  uint_t j;
+  for (j=0; j<size/2+1; j++) {
+    spectrum[j]       = norm[j]*COS(phas[j]);
+  }
+  for (j=1; j<size/2+1; j++) {
+    spectrum[size-j]  = norm[j]*SIN(phas[j]);
+  }
+}
+
+#endif
 
 /* new interface aubio_mfft */
@@ -128,6 +174,6 @@
                 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
                 /* put norm and phase into fftgrain */
-                aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize/2+1);
-                aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize/2+1);
+                aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
+                aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
         }
 }
@@ -135,10 +181,7 @@
 /* execute inverse fourier transform */
 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
-        uint_t i=0,j;
+        uint_t i=0;
         for (i=0; i < fft->channels; i++) {
-                for (j=0; j<fft->winsize/2+1; j++) {
-                        fft->spec[i][j]  = CEXPC(I*aubio_unwrap2pi(fftgrain->phas[i][j]));
-                        fft->spec[i][j] *= fftgrain->norm[i][j];
-                }
+                aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
                 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
         }
Index: src/onsetdetection.c
===================================================================
--- src/onsetdetection.c	(revision 17db1cde81719f3e7b3c85179d40105df19c209b)
+++ src/onsetdetection.c	(revision 237f63204499e5915eeb62088d4454c50d0aa84a)
@@ -77,4 +77,5 @@
 					-2.0*o->theta1->data[i][j]+
 					o->theta2->data[i][j]);
+#ifdef HAVE_COMPLEX_H
 			o->meas[j] = fftgrain->norm[i][j]*CEXPC(I*o->dev1->data[i][j]);
 			/* sum on all bins */
@@ -83,4 +84,13 @@
 						+  SQR( IMAG(o->oldmag->data[i][j]-o->meas[j]) )
 						);
+#else
+			o->meas[j]             = (fftgrain->norm[i][j])*COS(o->dev1->data[i][j]);
+			o->meas[(nbins-1)*2-j] = (fftgrain->norm[i][j])*SIN(o->dev1->data[i][j]);
+			/* sum on all bins */
+			onset->data[i][0]		 += //(fftgrain->norm[i][j]);
+					SQRT(SQR( (o->oldmag->data[i][j]-o->meas[j]) )
+						+  SQR( (-o->meas[(nbins-1)*2-j]) )
+						);
+#endif
 			/* swap old phase data (need to remember 2 frames behind)*/
 			o->theta2->data[i][j] = o->theta1->data[i][j];
@@ -200,4 +210,5 @@
 	aubio_onsetdetection_t * o = AUBIO_NEW(aubio_onsetdetection_t);
 	uint_t rsize = size/2+1;
+  uint_t i;
 	switch(type) {
 		/* for both energy and hfc, only fftgrain->norm is required */
@@ -210,5 +221,6 @@
 			o->oldmag = new_fvec(rsize,channels);
 			/** bug: must be complex array */
-			o->meas = AUBIO_ARRAY(fft_data_t,size);
+			o->meas = AUBIO_ARRAY(fft_data_t,size+1);
+			for (i=0; i<size+1; i++) o->meas[i] = 0;
 			o->dev1	 = new_fvec(rsize,channels);
 			o->theta1 = new_fvec(rsize,channels);
