aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/leanconvert.c
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/fftease/src/leanconvert.c')
-rw-r--r--externals/grill/fftease/src/leanconvert.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/externals/grill/fftease/src/leanconvert.c b/externals/grill/fftease/src/leanconvert.c
index 36b1452a..ecb6bc54 100644
--- a/externals/grill/fftease/src/leanconvert.c
+++ b/externals/grill/fftease/src/leanconvert.c
@@ -2,18 +2,42 @@
void leanconvert( float *S, float *C, int N2 )
{
+ register int i;
- 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 );
- }
+ float a = S[0]; // real value at f=0
+ float b = S[1]; // real value at f=Nyquist
+
+ C[0] = fabs(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] );
+ }
+
+ C[0] = fabs(b);
+ C[1] = 0;
+}
+
+
+/* unconvert essentially undoes what convert does, i.e., it
+ turns N2+1 PAIRS of amplitude and frequency values in
+ C into N2 PAIR of complex spectrum data (in rfft format)
+ in output array S; sampling rate R and interpolation factor
+ I are used to recompute phase values from frequencies */
+
+void leanunconvert( float *C, float *S, int N2 )
+{
+ register int i;
+
+ S[0] = fabs(C[0]);
+ S[1] = fabs(C[N2*2]);
+ S += 2,C += 2;
+
+ for (i = 1; i < N2; i++,S += 2,C += 2 ) {
+ S[0] = C[0] * cos( C[1] );
+ S[1] = -C[0] * sin( C[1] );
+ }
}