X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fvisualization%2Fvisual%2Ffft.c;h=2151e9be79b9600f0c983117ad7bd64eb5ef6e83;hb=be3d7a79bd8abb7f12db00e6d6b8a9f09782df17;hp=465c3be958ce0d23ec95549e64bb8c0e24ed0bd3;hpb=5ca0ebcca2e3f55a1087811048684a3b9b1eecbf;p=vlc diff --git a/modules/visualization/visual/fft.c b/modules/visualization/visual/fft.c index 465c3be958..2151e9be79 100644 --- a/modules/visualization/visual/fft.c +++ b/modules/visualization/visual/fft.c @@ -1,7 +1,7 @@ /***************************************************************************** * fft.c: Iterative implementation of a FFT ***************************************************************************** - * $Id: fft.c,v 1.3 2003/12/22 14:32:56 sam Exp $ + * $Id$ * * Mainly taken from XMMS's code * @@ -20,12 +20,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#include #include "fft.h" -#include #include #ifndef PI #ifdef M_PI @@ -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); @@ -109,7 +102,7 @@ void fft_perform(const sound_sample *input, float *output, fft_state *state) { * Free the state. */ void fft_close(fft_state *state) { - if(state) free(state); + free( state ); } /***************************************************************************** @@ -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;