summaryrefslogtreecommitdiff
path: root/tests/test5/fft.c
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2012-06-09 08:16:31 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2012-06-09 08:16:31 +0000
commit4e623f07d088fb98edb6595bf315ab4026d559b7 (patch)
tree850047c6d2fcf3d42ee8f3b11c728c902fe91e5f /tests/test5/fft.c
parent22079050f23cd4e019fc7dc98c25d5e06b1f8ead (diff)
download2012-violon-leds-4e623f07d088fb98edb6595bf315ab4026d559b7.tar.gz
2012-violon-leds-4e623f07d088fb98edb6595bf315ab4026d559b7.tar.bz2
2012-violon-leds-4e623f07d088fb98edb6595bf315ab4026d559b7.zip
Clean code, reorg, ajout licence Audacity, test6 pour la mysterieuse fonction todb_a. Ca n'est pas la courbe de ponderation A, c'est just une conversion en dB pour une puissance. La constante 4.34 est un mystère... c'est le log d'une valeur de ref sûrement, mais j'ai pas trouvé laquelle
git-svn-id: file:///var/svn/2012-violon-leds/trunk@15 6be1fa4d-33ac-4c33-becc-79fcb3794bb6
Diffstat (limited to 'tests/test5/fft.c')
-rw-r--r--tests/test5/fft.c80
1 files changed, 79 insertions, 1 deletions
diff --git a/tests/test5/fft.c b/tests/test5/fft.c
index 902d7f0..a9957a7 100644
--- a/tests/test5/fft.c
+++ b/tests/test5/fft.c
@@ -2,12 +2,18 @@
#include <math.h>
#include <stdlib.h>
+/* Everything here comes from Audacity 1.3.13
+ (orignally in C++ and with more genericity and functionnality)
+ Original Author : Dominic Mazzoni
+ Licenced under GPL 2.0 (see LICENCE)
+*/
+
#define MaxFastBits 16
int **gFFTBitTable = NULL;
void FFT(int NumSamples,
- gboolean InverseTransform,
+ int InverseTransform,
float *RealIn, float *ImagIn, float *RealOut, float *ImagOut)
{
int NumBits; /* Number of bits needed to store indices */
@@ -151,3 +157,75 @@ int ReverseBits(int index, int NumBits)
}
+/*
+ * PowerSpectrum
+ *
+ * This function computes the same as RealFFT, above, but
+ * adds the squares of the real and imaginary part of each
+ * coefficient, extracting the power and throwing away the
+ * phase.
+ *
+ * For speed, it does not call RealFFT, but duplicates some
+ * of its code.
+ */
+
+void PowerSpectrum(float *In, float *Out)
+{
+ int i;
+
+ float theta = M_PI / 128;
+
+ float tmpReal[128];
+ float tmpImag[128];
+ float RealOut[128];
+ float ImagOut[128];
+
+ for (i = 0; i < 128; i++) {
+ tmpReal[i] = In[2 * i];
+ tmpImag[i] = In[2 * i + 1]; //FIXME : WTFFFF ?
+ tmpImag[i]=0;
+ }
+
+ FFT(128, 0, tmpReal, tmpImag, RealOut, ImagOut);
+
+ float wtemp = sin(0.5 * theta);
+
+ float wpr = -2.0 * wtemp * wtemp;
+ float wpi = -1.0 * sin(theta);
+ float wr = 1.0 + wpr;
+ float wi = wpi;
+
+ int i3;
+
+ float h1r, h1i, h2r, h2i, rt, it;
+ for (i = 1; i < 128 / 2; i++) {
+
+ i3 = 128 - i;
+
+ h1r = 0.5 * (RealOut[i] + RealOut[i3]);
+ h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
+ h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
+ h2i = -0.5 * (RealOut[i] - RealOut[i3]);
+
+ rt = h1r + wr * h2r - wi * h2i;
+ it = h1i + wr * h2i + wi * h2r;
+
+ Out[i] = rt * rt + it * it;
+
+ rt = h1r - wr * h2r + wi * h2i;
+ it = -h1i + wr * h2i + wi * h2r;
+
+ Out[i3] = rt * rt + it * it;
+
+ wr = (wtemp = wr) * wpr - wi * wpi + wr;
+ wi = wi * wpr + wtemp * wpi + wi;
+ }
+
+ rt = (h1r = RealOut[0]) + ImagOut[0];
+ it = h1r - ImagOut[0];
+ Out[0] = rt * rt + it * it;
+ rt = RealOut[128 / 2];
+ it = ImagOut[128 / 2];
+ Out[128 / 2] = rt * rt + it * it;
+}
+