aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/convert.c
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2003-01-07 00:28:39 +0000
committerThomas Grill <xovo@users.sourceforge.net>2003-01-07 00:28:39 +0000
commit0182bbff2871114a4e93cc97942da621491f0e02 (patch)
tree039da4b12120b8481391c0fc904664c3dcbe7449 /externals/grill/fftease/src/convert.c
parentea175e0b95f848dcd203e7fbc1941c20616ec4f5 (diff)
""
svn path=/trunk/; revision=325
Diffstat (limited to 'externals/grill/fftease/src/convert.c')
-rw-r--r--externals/grill/fftease/src/convert.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/externals/grill/fftease/src/convert.c b/externals/grill/fftease/src/convert.c
new file mode 100644
index 00000000..8eb238f0
--- /dev/null
+++ b/externals/grill/fftease/src/convert.c
@@ -0,0 +1,55 @@
+#include "pv.h"
+
+/* S is a spectrum in rfft format, i.e., it contains N real values
+ arranged as real followed by imaginary values, except for first
+ two values, which are real parts of 0 and Nyquist frequencies;
+ convert first changes these into N/2+1 PAIRS of magnitude and
+ phase values to be stored in output array C; the phases are then
+ unwrapped and successive phase differences are used to compute
+ estimates of the instantaneous frequencies for each phase vocoder
+ analysis channel; decimation rate D and sampling rate R are used
+ to render these frequency values directly in Hz. */
+
+void convert(float *S, float *C, int N2, float *lastphase, float fundamental, float factor )
+{
+ float phase,
+ phasediff;
+ int real,
+ imag,
+ amp,
+ freq;
+ float a,
+ b;
+ int i;
+
+ float myTWOPI, myPI;
+
+ myTWOPI = 8.*atan(1.);
+ myPI = 4.*atan(1.);
+
+
+ for ( i = 0; i <= N2; i++ ) {
+ imag = freq = ( real = amp = i<<1 ) + 1;
+ a = ( i == N2 ? S[1] : S[real] );
+ b = ( i == 0 || i == N2 ? 0. : S[imag] );
+
+ C[amp] = hypot( a, b );
+ if ( C[amp] == 0. )
+ phasediff = 0.;
+ else {
+ phasediff = ( phase = -atan2( b, a ) ) - lastphase[i];
+ lastphase[i] = phase;
+
+ while ( phasediff > myPI )
+ phasediff -= myTWOPI;
+ while ( phasediff < -myPI )
+ phasediff += myTWOPI;
+ }
+ C[freq] = phasediff*factor + i*fundamental;
+ /*
+ if( i > 8 && i < 12 ) {
+ fprintf(stderr,"convert freq %d: %f\n",i, C[freq]);
+ }
+ */
+ }
+}