aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/leanconvert.c
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2003-01-19 21:11:59 +0000
committerThomas Grill <xovo@users.sourceforge.net>2003-01-19 21:11:59 +0000
commitcada39a002fbbe9bc848f963c3eb7faa65122228 (patch)
treea6b4c611989fa15cf0f59c656c81a2e388041324 /externals/grill/fftease/src/leanconvert.c
parent9ff5ccdea43ff2a954c1a400516dc6858e188e9c (diff)
""
svn path=/trunk/; revision=345
Diffstat (limited to 'externals/grill/fftease/src/leanconvert.c')
-rw-r--r--externals/grill/fftease/src/leanconvert.c57
1 files changed, 49 insertions, 8 deletions
diff --git a/externals/grill/fftease/src/leanconvert.c b/externals/grill/fftease/src/leanconvert.c
index ecb6bc54..0c567ca8 100644
--- a/externals/grill/fftease/src/leanconvert.c
+++ b/externals/grill/fftease/src/leanconvert.c
@@ -1,23 +1,49 @@
#include "pv.h"
-void leanconvert( float *S, float *C, int N2 )
+void leanconvert( float *S, float *C, int N2 , int amp, int ph)
{
+#if 1
register int i;
- float a = S[0]; // real value at f=0
- float b = S[1]; // real value at f=Nyquist
+ float a = fabs(S[0]); // real value at f=0
+ float b = fabs(S[1]); // real value at f=Nyquist
- C[0] = fabs(a);
+ C[0] = a;
C[1] = 0;
S += 2,C += 2;
- for ( i = 1; i < N2; i++,S += 2,C += 2 ) {
- C[0] = hypot( S[0], S[1] );
- C[1] = -atan2( S[1], S[0] );
+ if(amp && ph) {
+ for ( i = 1; i < N2; i++,S += 2,C += 2 ) {
+ C[0] = hypot( S[0], S[1] );
+ C[1] = -atan2( S[1], S[0] );
+ }
+ }
+ else if(amp) {
+ for ( i = 1; i < N2; i++,S += 2,C += 2 )
+ C[0] = hypot( S[0], S[1] );
+ }
+ else if(ph) {
+ for ( i = 1; i < N2; i++,S += 2,C += 2 )
+ C[1] = -atan2( S[1], S[0] );
}
- C[0] = fabs(b);
+ C[0] = b;
C[1] = 0;
+#else
+
+ int real, imag,
+ amp, phase;
+ float a, b;
+ int i;
+
+ for ( i = 0; i <= N2; i++ ) {
+ imag = phase = ( 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 );
+ C[phase] = -atan2( b, a );
+ }
+#endif
}
@@ -29,6 +55,7 @@ void leanconvert( float *S, float *C, int N2 )
void leanunconvert( float *C, float *S, int N2 )
{
+#if 1
register int i;
S[0] = fabs(C[0]);
@@ -39,5 +66,19 @@ void leanunconvert( float *C, float *S, int N2 )
S[0] = C[0] * cos( C[1] );
S[1] = -C[0] * sin( C[1] );
}
+#else
+ int real, imag,
+ amp, phase;
+ float a, b;
+ register int i;
+
+ for ( i = 0; i <= N2; i++ ) {
+ imag = phase = ( real = amp = i<<1 ) + 1;
+ S[real] = *(C+amp) * cos( *(C+phase) );
+ if ( i != N2 )
+ S[imag] = -*(C+amp) * sin( *(C+phase) );
+ }
+
+#endif
}