shithub: aacenc

Download patch

ref: 4b5782688647af37ad987073572b0769c1fee8f8
parent: 69cae32d20807f0cb1a994a53d42ecad17df8b04
author: stux <stux>
date: Sun Nov 16 00:02:52 EST 2003

moved global tables from fft.c into hEncoder FFT_Tables. Add fft_init and fft_terminate, flowed through all necessary changes. This should remove at least one instance of a memory leak, and fix some thread-safety problems. Version update to 1.23.3

--- a/libfaac/fft.c
+++ b/libfaac/fft.c
@@ -1,6 +1,6 @@
 /*
  * FAAC - Freeware Advanced Audio Coder
- * $Id: fft.c,v 1.9 2003/09/07 16:48:01 knik Exp $
+ * $Id: fft.c,v 1.10 2003/11/16 05:02:51 stux Exp $
  * Copyright (C) 2002 Krzysztof Nikiel
  *
  * This library is free software; you can redistribute it and/or
@@ -29,178 +29,218 @@
 #define MAXLOGM 9
 #define MAXLOGR 8
 
-typedef float fftfloat;
+void fft_init( FFT_Tables *fft_tables )
+{
+	int i;
+	fft_tables->costbl		= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->costbl[0] ) );
+	fft_tables->negsintbl	= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->negsintbl[0] ) );
+	fft_tables->reordertbl	= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->reordertbl[0] ) );
+	
+	for( i = 0; i< MAXLOGM+1; i++ )
+	{
+		fft_tables->costbl[i]		= NULL;
+		fft_tables->negsintbl[i]	= NULL;
+		fft_tables->reordertbl[i]	= NULL;
+	}
+}
 
-static fftfloat *costbl[MAXLOGM + 1] = {NULL};	// size/2
-static fftfloat *negsintbl[MAXLOGM + 1] = {NULL};	// size/2
-static unsigned short *reordertbl[MAXLOGM + 1] = {NULL};	//size
+void fft_terminate( FFT_Tables *fft_tables )
+{
+	int i;
 
-static void reorder(double *x, int logm)
+	for( i = 0; i< MAXLOGM+1; i++ )
+	{
+		if( fft_tables->costbl[i] != NULL )
+			FreeMemory( fft_tables->costbl[i] );
+		
+		if( fft_tables->negsintbl[i] != NULL )
+			FreeMemory( fft_tables->negsintbl[i] );
+			
+		if( fft_tables->reordertbl[i] != NULL )
+			FreeMemory( fft_tables->reordertbl[i] );
+	}
+
+	FreeMemory( fft_tables->costbl );
+	FreeMemory( fft_tables->negsintbl );
+	FreeMemory( fft_tables->reordertbl );
+
+	fft_tables->costbl		= NULL;
+	fft_tables->negsintbl	= NULL;
+	fft_tables->reordertbl	= NULL;
+}
+
+static void reorder( FFT_Tables *fft_tables, double *x, int logm)
 {
-  int i;
-  int size = 1 << logm;
-  unsigned short *r;	//size
+	int i;
+	int size = 1 << logm;
+	unsigned short *r;	//size
 
 
-  if (!reordertbl[logm])
-    // create bit reversing table
-  {
-    reordertbl[logm] = AllocMemory(size * sizeof(*(reordertbl[0])));
+	if ( fft_tables->reordertbl[logm] == NULL ) // create bit reversing table
+	{
+		fft_tables->reordertbl[logm] = AllocMemory(size * sizeof(*(fft_tables->reordertbl[0])));
 
-    for (i = 0; i < size; i++)
-    {
-      int reversed = 0;
-      int b0;
-      int tmp = i;
+		for (i = 0; i < size; i++)
+		{
+			int reversed = 0;
+			int b0;
+			int tmp = i;
 
-      for (b0 = 0; b0 < logm; b0++)
-      {
-	reversed = (reversed << 1) | (tmp & 1);
-	tmp >>= 1;
-      }
-      reordertbl[logm][i] = reversed;
-    }
-  }
+			for (b0 = 0; b0 < logm; b0++)
+			{
+				reversed = (reversed << 1) | (tmp & 1);
+				tmp >>= 1;
+			}
+			fft_tables->reordertbl[logm][i] = reversed;
+		}
+	}
 
-  r = reordertbl[logm];
+	r = fft_tables->reordertbl[logm];
 
-  for (i = 0; i < size; i++)
-  {
-    int j = r[i];
-    double tmp;
+	for (i = 0; i < size; i++)
+	{
+		int j = r[i];
+		double tmp;
 
-    if (j <= i)
-      continue;
+		if (j <= i)
+			continue;
 
-    tmp = x[i];
-    x[i] = x[j];
-    x[j] = tmp;
-  }
+		tmp = x[i];
+		x[i] = x[j];
+		x[j] = tmp;
+	}
 }
 
-static void fft_proc(double *xr, double *xi,
-		     fftfloat *refac, fftfloat *imfac, int size)
+static void fft_proc(
+		double *xr, 
+		double *xi,
+		fftfloat *refac, 
+		fftfloat *imfac, 
+		int size)	
 {
-  int step, shift, pos;
-  int exp, estep;
+	int step, shift, pos;
+	int exp, estep;
 
-  estep = size;
-  for (step = 1; step < size; step *= 2)
-  {
-    int x1;
-    int x2 = 0;
-    estep >>= 1;
-    for (pos = 0; pos < size; pos += (2 * step))
-    {
-      x1 = x2;
-      x2 += step;
-      exp = 0;
-      for (shift = 0; shift < step; shift++)
-      {
-	double v2r, v2i;
+	estep = size;
+	for (step = 1; step < size; step *= 2)
+	{
+		int x1;
+		int x2 = 0;
+		estep >>= 1;
+		for (pos = 0; pos < size; pos += (2 * step))
+		{
+			x1 = x2;
+			x2 += step;
+			exp = 0;
+			for (shift = 0; shift < step; shift++)
+			{
+				double v2r, v2i;
 
-	v2r = xr[x2] * refac[exp] - xi[x2] * imfac[exp];
-	v2i = xr[x2] * imfac[exp] + xi[x2] * refac[exp];
+				v2r = xr[x2] * refac[exp] - xi[x2] * imfac[exp];
+				v2i = xr[x2] * imfac[exp] + xi[x2] * refac[exp];
 
-	xr[x2] = xr[x1] - v2r;
-	xr[x1] += v2r;
+				xr[x2] = xr[x1] - v2r;
+				xr[x1] += v2r;
 
-	xi[x2] = xi[x1] - v2i;
+				xi[x2] = xi[x1] - v2i;
 
-	xi[x1] += v2i;
+				xi[x1] += v2i;
 
-	exp += estep;
+				exp += estep;
 
-	x1++;
-	x2++;
-      }
-    }
-  }
+				x1++;
+				x2++;
+			}
+		}
+	}
 }
 
-static void check_tables(int logm)
+static void check_tables( FFT_Tables *fft_tables, int logm)
 {
+	if( fft_tables->costbl[logm] == NULL )
+	{
+		int i;
+		int size = 1 << logm;
 
-  if (!(costbl[logm]))
-  {
-    int i;
-    int size = 1 << logm;
+		if( fft_tables->negsintbl[logm] != NULL )
+			FreeMemory( fft_tables->negsintbl[logm] );
 
-    if (negsintbl[logm])
-      FreeMemory(negsintbl[logm]);
+		fft_tables->costbl[logm]	= AllocMemory((size / 2) * sizeof(*(fft_tables->costbl[0])));
+		fft_tables->negsintbl[logm]	= AllocMemory((size / 2) * sizeof(*(fft_tables->negsintbl[0])));
 
-    costbl[logm] = AllocMemory((size / 2) * sizeof(*(costbl[0])));
-    negsintbl[logm] = AllocMemory((size / 2) * sizeof(*(negsintbl[0])));
-
-    for (i = 0; i < (size >> 1); i++)
-    {
-      double theta = 2.0 * M_PI * ((double) i) / (double) size;
-      costbl[logm][i] = cos(theta);
-      negsintbl[logm][i] = -sin(theta);
-    }
-  }
+		for (i = 0; i < (size >> 1); i++)
+		{
+			double theta = 2.0 * M_PI * ((double) i) / (double) size;
+			fft_tables->costbl[logm][i]		= cos(theta);
+			fft_tables->negsintbl[logm][i]	= -sin(theta);
+		}
+	}
 }
 
-void fft(double *xr, double *xi, int logm)
+void fft( FFT_Tables *fft_tables, double *xr, double *xi, int logm)
 {
-  if (logm > MAXLOGM)
-  {
-    fprintf(stderr, "fft size too big\n");
-    exit(1);
-  }
+	if (logm > MAXLOGM)
+	{
+		fprintf(stderr, "fft size too big\n");
+		exit(1);
+	}
 
-  if (logm < 1)
-  {
-    //printf("logm < 1\n");
-    return;
-  }
+	if (logm < 1)
+	{
+		//printf("logm < 1\n");
+		return;
+	}
 
-  check_tables(logm);
+	check_tables( fft_tables, logm);
 
-  reorder(xr, logm);
-  reorder(xi, logm);
+	reorder( fft_tables, xr, logm);
+	reorder( fft_tables, xi, logm);
 
-  fft_proc(xr, xi, costbl[logm], negsintbl[logm], 1 << logm);
+	fft_proc( xr, xi, fft_tables->costbl[logm], fft_tables->negsintbl[logm], 1 << logm );
 }
 
-void rfft(double *x, int logm)
+void rfft( FFT_Tables *fft_tables, double *x, int logm)
 {
-   double xi[1 << MAXLOGR];
+	double xi[1 << MAXLOGR];
 
-   if (logm > MAXLOGR)
-   {
-     fprintf(stderr, "rfft size too big\n");
-     exit(1);
-   }
+	if (logm > MAXLOGR)
+	{
+		fprintf(stderr, "rfft size too big\n");
+		exit(1);
+	}
 
-   memset(xi, 0, (1 << logm) * sizeof(xi[0]));
+	memset(xi, 0, (1 << logm) * sizeof(xi[0]));
 
-   fft(x, xi, logm);
+	fft( fft_tables, x, xi, logm);
 
-   memcpy(x + (1 << (logm - 1)), xi, (1 << (logm - 1)) * sizeof(*x));
+	memcpy(x + (1 << (logm - 1)), xi, (1 << (logm - 1)) * sizeof(*x));
 }
 
-void ffti(double *xr, double *xi, int logm)
+void ffti( FFT_Tables *fft_tables, double *xr, double *xi, int logm)
 {
-  int i, size;
-  double fac;
-  double *xrp, *xip;
+	int i, size;
+	double fac;
+	double *xrp, *xip;
 
-  fft(xi, xr, logm);
+	fft( fft_tables, xi, xr, logm);
 
-  size = 1 << logm;
-  fac = 1.0 / size;
-  xrp = xr;
-  xip = xi;
-  for (i = 0; i < size; i++)
-  {
-    *xrp++ *= fac;
-    *xip++ *= fac;
-  }
+	size = 1 << logm;
+	fac = 1.0 / size;
+	xrp = xr;
+	xip = xi;
+
+	for (i = 0; i < size; i++)
+	{
+		*xrp++ *= fac;
+		*xip++ *= fac;
+	}
 }
 
 /*
 $Log: fft.c,v $
+Revision 1.10  2003/11/16 05:02:51  stux
+moved global tables from fft.c into hEncoder FFT_Tables. Add fft_init and fft_terminate, flowed through all necessary changes. This should remove at least one instance of a memory leak, and fix some thread-safety problems. Version update to 1.23.3
+
 Revision 1.9  2003/09/07 16:48:01  knik
 reduced arrays size
 
--- a/libfaac/fft.h
+++ b/libfaac/fft.h
@@ -1,6 +1,6 @@
 /*
  * FAAC - Freeware Advanced Audio Coder
- * $Id: fft.h,v 1.3 2002/08/21 16:52:52 knik Exp $
+ * $Id: fft.h,v 1.4 2003/11/16 05:02:52 stux Exp $
  * Copyright (C) 2002 Krzysztof Nikiel
  *
  * This library is free software; you can redistribute it and/or
@@ -22,8 +22,20 @@
 #ifndef _FFT_H_
 #define _FFT_H_
 
-void rfft(double *x, int logm);
-void fft(double *xr, double *xi, int logm);
-void ffti(double *xr, double *xi, int logm);
+typedef float fftfloat;
+
+typedef struct
+{
+    fftfloat **costbl;
+    fftfloat **negsintbl;
+    unsigned short **reordertbl;
+} FFT_Tables;
+
+void fft_init		( FFT_Tables *fft_tables );
+void fft_terminate	( FFT_Tables *fft_tables );
+
+void rfft			( FFT_Tables *fft_tables, double *x, int logm );
+void fft			( FFT_Tables *fft_tables, double *xr, double *xi, int logm );
+void ffti			( FFT_Tables *fft_tables, double *xr, double *xi, int logm );
 
 #endif
--- a/libfaac/filtbank.c
+++ b/libfaac/filtbank.c
@@ -22,7 +22,7 @@
  *                                                                           *
  ****************************************************************************/
 /*
- * $Id: filtbank.c,v 1.10 2002/08/21 16:53:42 knik Exp $
+ * $Id: filtbank.c,v 1.11 2003/11/16 05:02:52 stux Exp $
  */
 
 /*
@@ -154,7 +154,7 @@
             p_out_mdct[i] = p_o_buf[i] * first_window[i];
             p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
         }
-        MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+        MDCT( &hEncoder->fft_tables, p_out_mdct, 2*BLOCK_LEN_LONG );
         break;
 
     case LONG_SHORT_WINDOW :
@@ -164,7 +164,7 @@
         for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
             p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
         SetMemory(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
-        MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+        MDCT( &hEncoder->fft_tables, p_out_mdct, 2*BLOCK_LEN_LONG );
         break;
 
     case SHORT_LONG_WINDOW :
@@ -174,7 +174,7 @@
         memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizeof(double));
         for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
             p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
-        MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+        MDCT( &hEncoder->fft_tables, p_out_mdct, 2*BLOCK_LEN_LONG );
         break;
 
     case ONLY_SHORT_WINDOW :
@@ -184,7 +184,7 @@
                 p_out_mdct[i] = p_o_buf[i] * first_window[i];
                 p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
             }
-            MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
+            MDCT( &hEncoder->fft_tables, p_out_mdct, 2*BLOCK_LEN_SHORT );
             p_out_mdct += BLOCK_LEN_SHORT;
             p_o_buf += BLOCK_LEN_SHORT;
             first_window = second_window;
@@ -257,7 +257,7 @@
     switch( block_type ) {
     case ONLY_LONG_WINDOW :
         memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
-        IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+        IMDCT( &hEncoder->fft_tables, transf_buf, 2*BLOCK_LEN_LONG );
         for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
             transf_buf[i] *= first_window[i];
         if (overlap_select != MNON_OVERLAPPED) {
@@ -273,7 +273,7 @@
 
     case LONG_SHORT_WINDOW :
         memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
-        IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+        IMDCT( &hEncoder->fft_tables, transf_buf, 2*BLOCK_LEN_LONG );
         for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
             transf_buf[i] *= first_window[i];
         if (overlap_select != MNON_OVERLAPPED) {
@@ -292,7 +292,7 @@
 
     case SHORT_LONG_WINDOW :
         memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
-        IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+        IMDCT( &hEncoder->fft_tables, transf_buf, 2*BLOCK_LEN_LONG );
         for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
             transf_buf[i+NFLAT_LS] *= first_window[i];
         if (overlap_select != MNON_OVERLAPPED) {
@@ -316,7 +316,7 @@
         }
         for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
             memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizeof(double));
-            IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
+            IMDCT( &hEncoder->fft_tables, transf_buf, 2*BLOCK_LEN_SHORT );
             p_in_data += BLOCK_LEN_SHORT;
             if (overlap_select != MNON_OVERLAPPED) {
                 for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
@@ -411,7 +411,7 @@
     }
 }
 
-static void MDCT(double *data, int N)
+static void MDCT( FFT_Tables *fft_tables, double *data, int N )
 {
     double *xi, *xr;
     double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
@@ -458,10 +458,10 @@
     /* Perform in-place complex FFT of length N/4 */
     switch (N) {
     case 256:
-        fft(xr, xi, 6);
+        fft( fft_tables, xr, xi, 6);
         break;
     case 2048:
-        fft(xr, xi, 9);
+        fft( fft_tables, xr, xi, 9);
     }
 
     /* prepare for recurrence relations in post-twiddle */
@@ -490,7 +490,7 @@
     if (xi) FreeMemory(xi);
 }
 
-static void IMDCT(double *data, int N)
+static void IMDCT( FFT_Tables *fft_tables, double *data, int N)
 {
     double *xi, *xr;
     double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
@@ -530,10 +530,10 @@
     /* Perform in-place complex IFFT of length N/4 */
     switch (N) {
     case 256:
-        ffti(xr, xi, 6);
+        ffti( fft_tables, xr, xi, 6);
         break;
     case 2048:
-        ffti(xr, xi, 9);
+        ffti( fft_tables, xr, xi, 9);
     }
 
     /* prepare for recurrence relations in post-twiddle */
--- a/libfaac/filtbank.h
+++ b/libfaac/filtbank.h
@@ -16,7 +16,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: filtbank.h,v 1.8 2001/06/08 18:01:09 menno Exp $
+ * $Id: filtbank.h,v 1.9 2003/11/16 05:02:52 stux Exp $
  */
 
 #ifndef FILTBANK_H
@@ -38,34 +38,33 @@
 #define SINE_WINDOW 0
 #define KBD_WINDOW  1
 
-void FilterBankInit(faacEncHandle hEncoder);
+void			FilterBankInit		( faacEncHandle hEncoder );
 
-void FilterBankEnd(faacEncHandle hEncoder);
+void			FilterBankEnd		( faacEncHandle hEncoder );
 
-void FilterBank(faacEncHandle hEncoder,
-                CoderInfo *coderInfo,
-                double *p_in_data,
-                double *p_out_mdct,
-                double *p_overlap,
-                int overlap_select);
+void			FilterBank( faacEncHandle hEncoder,
+						CoderInfo *coderInfo,
+						double *p_in_data,
+						double *p_out_mdct,
+						double *p_overlap,
+						int overlap_select );
 
-void IFilterBank(faacEncHandle hEncoder,
-                 CoderInfo *coderInfo,
-                 double *p_in_data,
-                 double *p_out_mdct,
-                 double *p_overlap,
-                 int overlap_select);
+void			IFilterBank( faacEncHandle hEncoder,
+						CoderInfo *coderInfo,
+						double *p_in_data,
+						double *p_out_mdct,
+						double *p_overlap,
+						int overlap_select );
 
-void specFilter(double *freqBuff,
-                int sampleRate,
-                int lowpassFreq,
-                int specLen
-                );
+void			specFilter(	double *freqBuff,
+						int sampleRate,
+						int lowpassFreq,
+						int specLen );
 
-static void CalculateKBDWindow(double* win, double alpha, int length);
-static double Izero(double x);
-static void MDCT(double *data, int N);
-static void IMDCT(double *data, int N);
+static void		CalculateKBDWindow	( double* win, double alpha, int length );
+static double	Izero				( double x);
+static void		MDCT				( FFT_Tables *fft_tables, double *data, int N );
+static void		IMDCT				( FFT_Tables *fft_tables, double *data, int N );
 
 
 #ifdef __cplusplus
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -16,7 +16,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: frame.c,v 1.52 2003/11/15 08:13:42 stux Exp $
+ * $Id: frame.c,v 1.53 2003/11/16 05:02:52 stux Exp $
  */
 
 /*
@@ -366,7 +366,9 @@
     }
 
     /* Initialize coder functions */
-    hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
+	fft_init( &hEncoder->fft_tables );
+    
+	hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
         hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
         hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
         hEncoder->srInfo->num_cb_short);
@@ -382,6 +384,8 @@
     AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels,
 		    &(hEncoder->aacquantCfg));
 
+	
+
     HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);
 
     /* Return handle */
@@ -404,6 +408,8 @@
 
     HuffmanEnd(hEncoder->coderInfo, hEncoder->numChannels);
 
+	fft_terminate( &hEncoder->fft_tables );
+
     /* Free remaining buffer memory */
     for (channel = 0; channel < hEncoder->numChannels; channel++) 
 	{
@@ -557,8 +563,12 @@
 		/* LFE psychoacoustic can run without it */
 		if (!channelInfo[channel].lfe || channelInfo[channel].cpe)
 		{
-			hEncoder->psymodel->PsyBufferUpdate(&hEncoder->gpsyInfo, &hEncoder->psyInfo[channel],
-					hEncoder->next3SampleBuff[channel], bandWidth,
+			hEncoder->psymodel->PsyBufferUpdate( 
+					&hEncoder->fft_tables, 
+					&hEncoder->gpsyInfo, 
+					&hEncoder->psyInfo[channel],
+					hEncoder->next3SampleBuff[channel], 
+					bandWidth,
 					hEncoder->srInfo->cb_width_short,
 					hEncoder->srInfo->num_cb_short);
 		}
@@ -943,6 +953,9 @@
 
 /*
 $Log: frame.c,v $
+Revision 1.53  2003/11/16 05:02:52  stux
+moved global tables from fft.c into hEncoder FFT_Tables. Add fft_init and fft_terminate, flowed through all necessary changes. This should remove at least one instance of a memory leak, and fix some thread-safety problems. Version update to 1.23.3
+
 Revision 1.52  2003/11/15 08:13:42  stux
 added FaacEncGetVersion(), version 1.23.2, added myself to faacCopyright :-P, does vanity know no bound ;)
 
--- a/libfaac/frame.h
+++ b/libfaac/frame.h
@@ -16,7 +16,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: frame.h,v 1.25 2003/11/15 08:13:42 stux Exp $
+ * $Id: frame.h,v 1.26 2003/11/16 05:02:52 stux Exp $
  */
 
 #ifndef FRAME_H
@@ -48,6 +48,7 @@
 #include "channels.h"
 #include "psych.h"
 #include "aacquant.h"
+#include "fft.h"
 
 #ifdef WIN32
   #ifndef FAACAPI
@@ -117,6 +118,9 @@
 
     /* quantizer specific config */
     AACQuantCfg aacquantCfg;
+
+	/* FFT Tables */
+	FFT_Tables	fft_tables;
 
     /* output bits difference in average bitrate mode */
     int bitDiff;
--- a/libfaac/psych.h
+++ b/libfaac/psych.h
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: psych.h,v 1.12 2003/09/07 16:45:48 knik Exp $
+ * $Id: psych.h,v 1.13 2003/11/16 05:02:52 stux Exp $
  */
 
 #ifndef PSYCH_H
@@ -32,6 +32,7 @@
 
 #include "coder.h"
 #include "channels.h"
+#include "fft.h"
 
 typedef struct {
 	int size;
@@ -56,22 +57,23 @@
         void *data;
 } GlobalPsyInfo;
 
-typedef struct {
-  void (*PsyInit) (GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
-		   unsigned int numChannels, unsigned int sampleRate,
-		   int *cb_width_long, int num_cb_long,
-			 int *cb_width_short, int num_cb_short);
-  void (*PsyEnd) (GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
-		  unsigned int numChannels);
-  void (*PsyCalculate) (ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo,
-			PsyInfo *psyInfo, int *cb_width_long, int num_cb_long,
-			int *cb_width_short, int num_cb_short,
-			unsigned int numChannels);
-  void (*PsyBufferUpdate) (GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo,
-			    double *newSamples, unsigned int bandwidth,
-			    int *cb_width_short, int num_cb_short);
-  void (*BlockSwitch) (CoderInfo *coderInfo, PsyInfo *psyInfo,
-		       unsigned int numChannels);
+typedef struct 
+{
+void (*PsyInit) (GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
+		unsigned int numChannels, unsigned int sampleRate,
+		int *cb_width_long, int num_cb_long,
+		int *cb_width_short, int num_cb_short);
+void (*PsyEnd) (GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
+		unsigned int numChannels);
+void (*PsyCalculate) (ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo,
+		PsyInfo *psyInfo, int *cb_width_long, int num_cb_long,
+		int *cb_width_short, int num_cb_short,
+		unsigned int numChannels);
+void (*PsyBufferUpdate) ( FFT_Tables *fft_tables, GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo,
+		double *newSamples, unsigned int bandwidth,
+		int *cb_width_short, int num_cb_short);
+void (*BlockSwitch) (CoderInfo *coderInfo, PsyInfo *psyInfo,
+		unsigned int numChannels);
 } psymodel_t;
 
 extern psymodel_t psymodel2;
--- a/libfaac/psychkni.c
+++ b/libfaac/psychkni.c
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: psychkni.c,v 1.13 2003/09/07 16:45:48 knik Exp $
+ * $Id: psychkni.c,v 1.14 2003/11/16 05:02:52 stux Exp $
  */
 #include <stdio.h>
 #include <stdlib.h>
@@ -333,7 +333,7 @@
   }
 }
 
-static void PsyBufferUpdate(GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo,
+static void PsyBufferUpdate( FFT_Tables *fft_tables, GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo,
 			    double *newSamples, unsigned int bandwidth,
 			    int *cb_width_short, int num_cb_short)
 {
@@ -358,7 +358,7 @@
 	   2 * psyInfo->sizeS * sizeof(double));
 
     Hann(gpsyInfo, transBuffS, 2 * psyInfo->sizeS);
-    rfft(transBuffS, 8);
+    rfft( fft_tables, transBuffS, 8);
 
     // shift bufs
     tmp = psydata->fftEnrgPrevS[win];
--- a/libfaac/version.h
+++ b/libfaac/version.h
@@ -1,6 +1,6 @@
 #ifndef _VERSION_H_
 #define _VERSION_H_
 
-#define FAAC_VERSION "1.23.2"
+#define FAAC_VERSION "1.23.3"
 
 #endif