aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/convert.c
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/fftease/src/convert.c')
-rw-r--r--externals/grill/fftease/src/convert.c85
1 files changed, 45 insertions, 40 deletions
diff --git a/externals/grill/fftease/src/convert.c b/externals/grill/fftease/src/convert.c
index 8eb238f0..07500f90 100644
--- a/externals/grill/fftease/src/convert.c
+++ b/externals/grill/fftease/src/convert.c
@@ -12,44 +12,49 @@
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]);
- }
- */
- }
+ float phase, phasediff;
+ int even,odd;
+ float a,b;
+ int i;
+
+ for ( i = 0; i <= N2; i++ ) {
+ odd = ( even = i<<1 ) + 1;
+ a = ( i == N2 ? S[1] : S[even] );
+ b = ( i == 0 || i == N2 ? 0. : S[odd] );
+
+ C[even] = hypot( a, b );
+ if ( C[even] == 0. )
+ phasediff = 0.;
+ else {
+ phasediff = ( phase = -atan2( b, a ) ) - lastphase[i];
+ lastphase[i] = phase;
+
+ while ( phasediff > PV_PI ) phasediff -= PV_2PI;
+ while ( phasediff < -PV_PI ) phasediff += PV_2PI;
+ }
+
+ C[odd] = phasediff*factor + i*fundamental;
+ }
+}
+
+
+void unconvert(float *C, float *S, int N2, float *lastphase, float fundamental, float factor )
+{
+ int i,even,odd;
+ float mag,phase;
+
+ for ( i = 0; i <= N2; i++ ) {
+ odd = ( even = i<<1 ) + 1;
+
+ mag = C[even];
+ lastphase[i] += C[odd] - i*fundamental;
+ phase = lastphase[i]*factor;
+
+ if(i != N2) {
+ S[even] = mag*cos( phase );
+ S[odd] = -mag*sin( phase );
+ }
+ else
+ S[1] = mag*cos( phase );
+ }
}