[vlc-devel] commit: Moved static arrays to fft context. (Laurent Aimar )

git version control git at videolan.org
Sun Aug 3 16:41:52 CEST 2008


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Aug  3 16:41:40 2008 +0200| [d26adda5fb9eaf2b9987ca8cbbe2e35702488529] | committer: Laurent Aimar 

Moved static arrays to fft context.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d26adda5fb9eaf2b9987ca8cbbe2e35702488529
---

 modules/visualization/visual/fft.c |   32 +++++++++++++-------------------
 modules/visualization/visual/fft.h |    8 ++++++++
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/modules/visualization/visual/fft.c b/modules/visualization/visual/fft.c
index 82bd591..2151e9b 100644
--- a/modules/visualization/visual/fft.c
+++ b/modules/visualization/visual/fft.c
@@ -38,20 +38,13 @@
 /******************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void fft_prepare(const sound_sample *input, float * re, float * im);
-static void fft_calculate(float * re, float * im);
+static void fft_prepare(const sound_sample *input, float * re, float * im,
+                        const unsigned int *bitReverse);
+static void fft_calculate(float * re, float * im,
+                          const float *costable, const float *sintable );
 static void fft_output(const float *re, const float *im, float *output);
 static int reverseBits(unsigned int initial);
 
-
-/* Table to speed up bit reverse copy */
-static unsigned int bitReverse[FFT_BUFFER_SIZE];
-
-/* The next two tables could be made to use less space in memory, since they
- * overlap hugely, but hey. */
-static float sintable[FFT_BUFFER_SIZE / 2];
-static float costable[FFT_BUFFER_SIZE / 2];
-
 /*****************************************************************************
  * These functions are the ones called externally
  *****************************************************************************/
@@ -67,19 +60,19 @@ fft_state *visual_fft_init(void)
     fft_state *p_state;
     unsigned int i;
 
-    p_state = (fft_state *) malloc (sizeof(fft_state));
+    p_state = malloc( sizeof(*p_state) );
     if(! p_state )
         return NULL;
 
     for(i = 0; i < FFT_BUFFER_SIZE; i++)
     {
-        bitReverse[i] = reverseBits(i);
+        p_state->bitReverse[i] = reverseBits(i);
     }
     for(i = 0; i < FFT_BUFFER_SIZE / 2; i++)
     {
         float j = 2 * PI * i / FFT_BUFFER_SIZE;
-        costable[i] = cos(j);
-        sintable[i] = sin(j);
+        p_state->costable[i] = cos(j);
+        p_state->sintable[i] = sin(j);
     }
 
     return p_state;
@@ -96,10 +89,10 @@ fft_state *visual_fft_init(void)
  */
 void fft_perform(const sound_sample *input, float *output, fft_state *state) {
     /* Convert data from sound format to be ready for FFT */
-    fft_prepare(input, state->real, state->imag);
+    fft_prepare(input, state->real, state->imag, state->bitReverse );
 
     /* Do the actual FFT */
-    fft_calculate(state->real, state->imag);
+    fft_calculate(state->real, state->imag, state->costable, state->sintable);
 
     /* Convert the FFT output into intensities */
     fft_output(state->real, state->imag, output);
@@ -119,7 +112,8 @@ void fft_close(fft_state *state) {
 /*
  * Prepare data to perform an FFT on
  */
-static void fft_prepare(const sound_sample *input, float * re, float * im) {
+static void fft_prepare( const sound_sample *input, float * re, float * im,
+                         const unsigned int *bitReverse ) {
     unsigned int i;
     float *p_real = re;
     float *p_imag = im;
@@ -158,7 +152,7 @@ static void fft_output(const float * re, const float * im, float *output)
 /*
  * Actually perform the FFT
  */
-static void fft_calculate(float * re, float * im)
+static void fft_calculate(float * re, float * im, const float *costable, const float *sintable )
 {
     unsigned int i, j, k;
     unsigned int exchanges;
diff --git a/modules/visualization/visual/fft.h b/modules/visualization/visual/fft.h
index c423305..942fd5d 100644
--- a/modules/visualization/visual/fft.h
+++ b/modules/visualization/visual/fft.h
@@ -36,6 +36,14 @@ struct _struct_fft_state {
      /* Temporary data stores to perform FFT in. */
      float real[FFT_BUFFER_SIZE];
      float imag[FFT_BUFFER_SIZE];
+
+     /* */
+     unsigned int bitReverse[FFT_BUFFER_SIZE];
+
+     /* The next two tables could be made to use less space in memory, since they
+      * overlap hugely, but hey. */
+     float sintable[FFT_BUFFER_SIZE / 2];
+     float costable[FFT_BUFFER_SIZE / 2];
 };
 
 /* FFT prototypes */




More information about the vlc-devel mailing list