shithub: aacenc

Download patch

ref: 010133517b5d362c27080b08459e14f9213727ca
parent: 2673a116d5373d9b6e4e6996d11257002486f12d
author: menno <menno>
date: Mon Mar 12 11:58:37 EST 2001

cleanup

--- a/frontend/faac.dsp
+++ b/frontend/faac.dsp
@@ -50,8 +50,8 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 libsndfile.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# SUBTRACT LINK32 /profile /nodefaultlib
+# ADD LINK32 libsndfile.lib libc.lib libm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386 /nodefaultlib
+# SUBTRACT LINK32 /debug
 
 !ELSEIF  "$(CFG)" == "faac - Win32 Debug"
 
--- a/frontend/faacgui.dsp
+++ b/frontend/faacgui.dsp
@@ -53,8 +53,8 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
-# ADD LINK32 libsndfile.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
-# SUBTRACT LINK32 /profile /nodefaultlib
+# ADD LINK32 libsndfile.lib libc.lib libm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib
+# SUBTRACT LINK32 /profile
 
 !ELSEIF  "$(CFG)" == "faacgui - Win32 Debug"
 
--- a/frontend/maingui.c
+++ b/frontend/maingui.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: maingui.c,v 1.10 2001/03/06 21:02:33 menno Exp $
+ * $Id: maingui.c,v 1.11 2001/03/12 16:58:36 menno Exp $
  */
 
 #include <windows.h>
@@ -193,8 +193,8 @@
 				char HeaderText[50];
 				char Percentage[5];
 
-				pcmbuf = (short*)malloc(PCMBUFSIZE*numChannels*sizeof(short));
-				bitbuf = (unsigned char*)malloc(BITBUFSIZE*sizeof(unsigned char));
+				pcmbuf = (short*)LocalAlloc(0, PCMBUFSIZE*numChannels*sizeof(short));
+				bitbuf = (unsigned char*)LocalAlloc(0, BITBUFSIZE*sizeof(unsigned char));
 
 				SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 1024));
 				SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
@@ -263,8 +263,8 @@
 					}
 
 				CloseHandle(hOutfile);
-				if (pcmbuf) free(pcmbuf);
-				if (bitbuf) free(bitbuf);
+				if (pcmbuf) LocalFree(pcmbuf);
+				if (bitbuf) LocalFree(bitbuf);
 			}
 
 			faacEncClose(hEncoder);
--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.c
@@ -16,12 +16,11 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: aacquant.c,v 1.6 2001/03/06 14:01:36 menno Exp $
+ * $Id: aacquant.c,v 1.7 2001/03/12 16:58:36 menno Exp $
  */
 
 #include <math.h>
 #include <stdlib.h>
-#include <memory.h>
 
 #include "aacquant.h"
 #include "coder.h"
@@ -44,9 +43,9 @@
 {
 	unsigned int channel, i;
 
-	pow43 = (double*)malloc(PRECALC_SIZE*sizeof(double));
-	adj43 = (double*)malloc(PRECALC_SIZE*sizeof(double));
-	adj43asm = (double*)malloc(PRECALC_SIZE*sizeof(double));
+	pow43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
+	adj43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
+	adj43asm = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
 
 	pow43[0] = 0.0;
 	for(i=1;i<PRECALC_SIZE;i++)
@@ -63,7 +62,7 @@
 		coderInfo[channel].old_value = 0;
 		coderInfo[channel].CurrentStep = 4;
 
-		coderInfo[channel].requantFreq = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
+		coderInfo[channel].requantFreq = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
 	}
 }
 
@@ -71,12 +70,12 @@
 {
 	unsigned int channel;
 
-	if (pow43) free(pow43);
-	if (adj43) free(adj43);
-	if (adj43asm) free(adj43asm);
+	if (pow43) FreeMemory(pow43);
+	if (adj43) FreeMemory(adj43);
+	if (adj43asm) FreeMemory(adj43asm);
 
 	for (channel = 0; channel < numChannels; channel++) {
-		if (coderInfo[channel].requantFreq) free(coderInfo[channel].requantFreq);
+		if (coderInfo[channel].requantFreq) FreeMemory(coderInfo[channel].requantFreq);
 	}
 }
 
@@ -97,9 +96,9 @@
 	int *scale_factor = coderInfo->scale_factor;
 
 
-	xr_pow = (double*)malloc(FRAME_LEN*sizeof(double));
-	xmin = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-	xi = (int*)malloc(FRAME_LEN*sizeof(int));
+	xr_pow = (double*)AllocMemory(FRAME_LEN*sizeof(double));
+	xmin = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+	xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
 
 
 	if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
@@ -139,7 +138,7 @@
 		}
 	} else {
 		coderInfo->global_gain = 0;
-		memset(xi, 0, FRAME_LEN*sizeof(int));
+		SetMemory(xi, 0, FRAME_LEN*sizeof(int));
 	}
 
 	CountBitsLong(coderInfo, xi);
@@ -165,9 +164,9 @@
 	}
 
 
-	if (xmin) free(xmin);
-	if (xr_pow) free(xr_pow);
-	if (xi) free(xi);
+	if (xmin) FreeMemory(xmin);
+	if (xr_pow) FreeMemory(xr_pow);
+	if (xi) FreeMemory(xi);
 
 	return bits;
 }
@@ -417,10 +416,10 @@
 	int *save_xi;
 	double *distort;
 
-	distort = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-	best_scale_factor = (int*)malloc(MAX_SCFAC_BANDS*sizeof(int));
+	distort = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+	best_scale_factor = (int*)AllocMemory(MAX_SCFAC_BANDS*sizeof(int));
 
-	save_xi = (int*)malloc(FRAME_LEN*sizeof(int));
+	save_xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
 
 	notdone = 1;
 	outer_loop_count = 0;
@@ -473,9 +472,9 @@
 	}
 	memcpy(xi, save_xi, sizeof(int)*BLOCK_LEN_LONG);
 
-	if (best_scale_factor) free(best_scale_factor);
-	if (save_xi) free(save_xi);
-	if (distort) free(distort);
+	if (best_scale_factor) FreeMemory(best_scale_factor);
+	if (save_xi) FreeMemory(save_xi);
+	if (distort) FreeMemory(distort);
 
 	return 0;
 }
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -16,11 +16,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: bitstream.c,v 1.5 2001/03/05 11:33:37 menno Exp $
+ * $Id: bitstream.c,v 1.6 2001/03/12 16:58:36 menno Exp $
  */
 
 #include <stdlib.h>
-#include <memory.h>
 
 #include "coder.h"
 #include "channels.h"
@@ -27,6 +26,7 @@
 #include "huffman.h"
 #include "bitstream.h"
 #include "ltp.h"
+#include "util.h"
 
 int WriteBitstream(faacEncHandle hEncoder,
 				   CoderInfo *coderInfo,
@@ -653,12 +653,12 @@
 {
 	BitStream *bitStream;
 
-	bitStream = malloc(sizeof(BitStream));
+	bitStream = AllocMemory(sizeof(BitStream));
 	bitStream->size = size;
 	bitStream->numBit = 0;
 	bitStream->currentBit = 0;
 	bitStream->data = buffer;
-	memset(bitStream->data, 0, size);
+	SetMemory(bitStream->data, 0, size);
 
 	return bitStream;
 }
@@ -667,7 +667,7 @@
 {
 	int bytes = bit2byte(bitStream->numBit);
 
-	free(bitStream);
+	FreeMemory(bitStream);
 
 	return bytes;
 }
--- a/libfaac/fft.c
+++ b/libfaac/fft.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: fft.c,v 1.2 2001/02/04 17:50:47 oxygene2000 Exp $
+ * $Id: fft.c,v 1.3 2001/03/12 16:58:36 menno Exp $
  */
 
 #include <math.h>
@@ -23,8 +23,8 @@
 #include <stdlib.h>
 
 #include "fft.h"
+#include "util.h"
 
-
 #define  MAXLOGM     11    /* max FFT length = 2^MAXLOGM */
 #define  TWOPI       6.28318530717958647692
 #define  SQHALF      0.707106781186547524401
@@ -42,9 +42,9 @@
  
    /* Allocate memory for tables */
    nel = m4 - 2;
-   tabr[logm-4] = (double *) calloc(3 * nel, sizeof(double));
+   tabr[logm-4] = (double *)AllocMemory(3 * nel * sizeof(double));
 /*
-   if ((tab[logm-4] = (double *) calloc(3 * nel, sizeof(double))) == NULL) {
+   if ((tab[logm-4] = (double *) AllocMemory(3 * nel * sizeof(double))) == NULL) {
       printf("Error : RSFFT : not enough memory for cosine tables.\n");
       error_exit();
    }
@@ -287,9 +287,9 @@
  
       /* Allocate memory for tables */
       nel = m4 - 2;
-	  tab[logm-4] = (double *) calloc(6 * nel, sizeof(double));
+	  tab[logm-4] = (double *)AllocMemory(6 * nel * sizeof(double));
 /*
-      if ((tab[logm-4] = (double *) calloc(6 * nel, sizeof(double))) == NULL) {
+      if ((tab[logm-4] = (double *)AllocMemory(6 * nel * sizeof(double))) == NULL) {
          error_exit();
       }
 */
--- a/libfaac/filtbank.c
+++ b/libfaac/filtbank.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: filtbank.c,v 1.5 2001/03/05 11:33:37 menno Exp $
+ * $Id: filtbank.c,v 1.6 2001/03/12 16:58:37 menno Exp $
  */
 
 /*
@@ -28,7 +28,6 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <memory.h>
 
 #include "coder.h"
 #include "filtbank.h"
@@ -44,15 +43,15 @@
 	unsigned int i, channel;
 
 	for (channel = 0; channel < hEncoder->numChannels; channel++) {
-		hEncoder->freqBuff[channel] = (double*)malloc(2*FRAME_LEN*sizeof(double));
-		hEncoder->overlapBuff[channel] = (double*)malloc(FRAME_LEN*sizeof(double));
-		memset(hEncoder->overlapBuff[channel], 0, FRAME_LEN*sizeof(double));
+		hEncoder->freqBuff[channel] = (double*)AllocMemory(2*FRAME_LEN*sizeof(double));
+		hEncoder->overlapBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
+		SetMemory(hEncoder->overlapBuff[channel], 0, FRAME_LEN*sizeof(double));
 	}
 
-	hEncoder->sin_window_long = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
-	hEncoder->sin_window_short = (double*)malloc(BLOCK_LEN_SHORT*sizeof(double));
-	hEncoder->kbd_window_long = (double*)malloc(BLOCK_LEN_LONG*sizeof(double));
-	hEncoder->kbd_window_short = (double*)malloc(BLOCK_LEN_SHORT*sizeof(double));
+	hEncoder->sin_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+	hEncoder->sin_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
+	hEncoder->kbd_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+	hEncoder->kbd_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
 
 	for( i=0; i<BLOCK_LEN_LONG; i++ )
 		hEncoder->sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
@@ -68,14 +67,14 @@
 	unsigned int channel;
 
 	for (channel = 0; channel < hEncoder->numChannels; channel++) {
-		if (hEncoder->freqBuff[channel]) free(hEncoder->freqBuff[channel]);
-		if (hEncoder->overlapBuff[channel]) free(hEncoder->overlapBuff[channel]);
+		if (hEncoder->freqBuff[channel]) FreeMemory(hEncoder->freqBuff[channel]);
+		if (hEncoder->overlapBuff[channel]) FreeMemory(hEncoder->overlapBuff[channel]);
 	}
 
-	if (hEncoder->sin_window_long) free(hEncoder->sin_window_long);
-	if (hEncoder->sin_window_short) free(hEncoder->sin_window_short);
-	if (hEncoder->kbd_window_long) free(hEncoder->kbd_window_long);
-	if (hEncoder->kbd_window_short) free(hEncoder->kbd_window_short);
+	if (hEncoder->sin_window_long) FreeMemory(hEncoder->sin_window_long);
+	if (hEncoder->sin_window_short) FreeMemory(hEncoder->sin_window_short);
+	if (hEncoder->kbd_window_long) FreeMemory(hEncoder->kbd_window_long);
+	if (hEncoder->kbd_window_short) FreeMemory(hEncoder->kbd_window_short);
 }
 
 void FilterBank(faacEncHandle hEncoder,
@@ -90,7 +89,7 @@
 	int k, i;
 	int block_type = coderInfo->block_type;
 
-	transf_buf = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
+	transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
 
 	/* create / shift old values */
 	/* We use p_overlap here as buffer holding the last frame time signal*/
@@ -158,12 +157,12 @@
 		memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
 		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];
-		memset(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+		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 );
 		break;
 
     case SHORT_LONG_WINDOW :
-		memset(p_out_mdct,0,NFLAT_LS*sizeof(double));
+		SetMemory(p_out_mdct,0,NFLAT_LS*sizeof(double));
 		for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
 			p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
 		memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizeof(double));
@@ -187,7 +186,7 @@
 		break;
 	}
 
-	if (transf_buf) free(transf_buf);
+	if (transf_buf) FreeMemory(transf_buf);
 }
 
 void IFilterBank(faacEncHandle hEncoder,
@@ -204,8 +203,8 @@
 	int k, i;
 	int block_type = coderInfo->block_type;
 
-	transf_buf = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
-	overlap_buf = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
+	transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+	overlap_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
 
 	/*  Window shape processing */
 	if (overlap_select != MNON_OVERLAPPED) {
@@ -277,11 +276,11 @@
 			memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
 			for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
 				o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
-			memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+			SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
         } else { /* overlap_select == NON_OVERLAPPED */
 			for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
 				transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
-			memset(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+			SetMemory(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
 		}
 		break;
 
@@ -297,7 +296,7 @@
 			for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
 				o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
 		} else { /* overlap_select == NON_OVERLAPPED */
-			memset(transf_buf,0,NFLAT_LS*sizeof(double));
+			SetMemory(transf_buf,0,NFLAT_LS*sizeof(double));
 			for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
 				transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
 		}
@@ -329,7 +328,7 @@
 			}
 			first_window = second_window;
 		}
-		memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+		SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
 		break;
 	}
 
@@ -341,8 +340,8 @@
 	/* save unused output data */
 	memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizeof(double));
 
-	if (overlap_buf) free(overlap_buf);
-	if (transf_buf) free(transf_buf);
+	if (overlap_buf) FreeMemory(overlap_buf);
+	if (transf_buf) FreeMemory(transf_buf);
 }
 
 void specFilter(double *freqBuff,
@@ -357,7 +356,7 @@
 	lowpass = (lowpassFreq * specLen) / (sampleRate>>1) + 1;
 	xlowpass = (lowpass < specLen) ? lowpass : specLen ;
 
-	memset(freqBuff+xlowpass,0,(specLen-xlowpass)*sizeof(double));
+	SetMemory(freqBuff+xlowpass,0,(specLen-xlowpass)*sizeof(double));
 }
 
 static double Izero(double x)
@@ -414,8 +413,8 @@
 	double cosfreq8, sinfreq8;
 	int i, n;
 
-	xi = (double*)malloc((N >> 2)*sizeof(double));
-	xr = (double*)malloc((N >> 2)*sizeof(double));
+	xi = (double*)AllocMemory((N >> 2)*sizeof(double));
+	xr = (double*)AllocMemory((N >> 2)*sizeof(double));
 
 	/* prepare for recurrence relation in pre-twiddle */
 	cfreq = cos (freq);
@@ -481,8 +480,8 @@
 		s = s * cfreq + cold * sfreq;
 	}
 
-	if (xr) free(xr);
-	if (xi) free(xi);
+	if (xr) FreeMemory(xr);
+	if (xi) FreeMemory(xi);
 }
 
 static void IMDCT(double *data, int N)
@@ -493,8 +492,8 @@
 	double fac, cosfreq8, sinfreq8;
 	int i;
 
-	xi = (double*)malloc((N >> 2)*sizeof(double));
-	xr = (double*)malloc((N >> 2)*sizeof(double));
+	xi = (double*)AllocMemory((N >> 2)*sizeof(double));
+	xr = (double*)AllocMemory((N >> 2)*sizeof(double));
 
 	/* Choosing to allocate 2/N factor to Inverse Xform! */
 	fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
@@ -561,6 +560,6 @@
 		s = s * cfreq + cold * sfreq;
 	}
 
-	if (xr) free(xr);
-	if (xi) free(xi);
+	if (xr) FreeMemory(xr);
+	if (xi) FreeMemory(xi);
 }
--- a/libfaac/frame.c
+++ b/libfaac/frame.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: frame.c,v 1.13 2001/03/06 14:01:36 menno Exp $
+ * $Id: frame.c,v 1.14 2001/03/12 16:58:37 menno Exp $
  */
 
 /*
@@ -29,7 +29,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <memory.h>
 
 #include "frame.h"
 #include "coder.h"
@@ -87,8 +86,8 @@
 	unsigned int channel;
 	faacEncHandle hEncoder;
 
-	hEncoder = (faacEncStruct*)malloc(sizeof(faacEncStruct));
-	memset(hEncoder, 0, sizeof(faacEncStruct));
+	hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
+	SetMemory(hEncoder, 0, sizeof(faacEncStruct));
 
 	hEncoder->numChannels = numChannels;
 	hEncoder->sampleRate = sampleRate;
@@ -120,8 +119,8 @@
 		hEncoder->sampleBuff[channel] = NULL;
 		hEncoder->nextSampleBuff[channel] = NULL;
 		hEncoder->next2SampleBuff[channel] = NULL;
-		hEncoder->ltpTimeBuff[channel] = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
-		memset(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
+		hEncoder->ltpTimeBuff[channel] = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+		SetMemory(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
 	}
 
 	/* Initialize coder functions */
@@ -159,13 +158,13 @@
 
 	/* Free remaining buffer memory */
 	for (channel = 0; channel < hEncoder->numChannels; channel++) {
-		if (hEncoder->ltpTimeBuff[channel]) free(hEncoder->ltpTimeBuff[channel]);
-		if (hEncoder->sampleBuff[channel]) free(hEncoder->sampleBuff[channel]);
-		if (hEncoder->nextSampleBuff[channel]) free(hEncoder->nextSampleBuff[channel]);
+		if (hEncoder->ltpTimeBuff[channel]) FreeMemory(hEncoder->ltpTimeBuff[channel]);
+		if (hEncoder->sampleBuff[channel]) FreeMemory(hEncoder->sampleBuff[channel]);
+		if (hEncoder->nextSampleBuff[channel]) FreeMemory(hEncoder->nextSampleBuff[channel]);
 	}
 
 	/* Free handle */
-	if (hEncoder) free(hEncoder);
+	if (hEncoder) FreeMemory(hEncoder);
 
 	return 0;
 }
@@ -226,9 +225,9 @@
 		}
 
 		if (hEncoder->sampleBuff[channel])
-			free(hEncoder->sampleBuff[channel]);
+			FreeMemory(hEncoder->sampleBuff[channel]);
 		hEncoder->sampleBuff[channel] = hEncoder->nextSampleBuff[channel];
-		hEncoder->nextSampleBuff[channel] = (double*)malloc(FRAME_LEN*sizeof(double));
+		hEncoder->nextSampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
 
 		if (samplesInput == 0) { /* start flushing*/
 			for (i = 0; i < FRAME_LEN; i++)
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.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: huffman.c,v 1.3 2001/02/04 17:50:47 oxygene2000 Exp $
+ * $Id: huffman.c,v 1.4 2001/03/12 16:58:37 menno Exp $
  */
 
 #include <math.h>
@@ -25,6 +25,7 @@
 #include "huffman.h"
 #include "coder.h"
 #include "bitstream.h"
+#include "util.h"
 
 #include "hufftab.h"
 
@@ -33,8 +34,8 @@
 	unsigned int channel;
 
 	for (channel = 0; channel < numChannels; channel++) {
-		coderInfo[channel].data = (int*)malloc(5*FRAME_LEN*sizeof(int));
-		coderInfo[channel].len = (int*)malloc(5*FRAME_LEN*sizeof(int));
+		coderInfo[channel].data = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
+		coderInfo[channel].len = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
 	}
 }
 
@@ -43,8 +44,8 @@
 	unsigned int channel;
 
 	for (channel = 0; channel < numChannels; channel++) {
-		if (coderInfo[channel].data) free(coderInfo[channel].data);
-		if (coderInfo[channel].len) free(coderInfo[channel].len);
+		if (coderInfo[channel].data) FreeMemory(coderInfo[channel].data);
+		if (coderInfo[channel].len) FreeMemory(coderInfo[channel].len);
 	}
 }
 
@@ -97,12 +98,12 @@
 /* #define SLOW */
 
 #ifdef SLOW
-	for(i=0;i<5;i++){
-		hop = 1 << i;
+	for(i = 0; i < 5; i++) {
 #else
-		hop = 1;
 		i = 0;
 #endif
+		hop = 1 << i;
+
 		NoiselessBitCount(coderInfo, quant, hop, min_book_choice);
 
 		/* load up the (not-full) binary search tree with the min_book_choice values */
--- a/libfaac/libfaac.dsp
+++ b/libfaac/libfaac.dsp
@@ -177,10 +177,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=.\kbd_win.h
-# End Source File
-# Begin Source File
-
 SOURCE=.\ltp.h
 # End Source File
 # Begin Source File
--- a/libfaac/ltp.c
+++ b/libfaac/ltp.c
@@ -16,10 +16,9 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: ltp.c,v 1.2 2001/03/05 15:55:40 menno Exp $
+ * $Id: ltp.c,v 1.3 2001/03/12 16:58:37 menno Exp $
  */
 
-#include <malloc.h>
 #include <stdio.h>
 #include <math.h>
 
@@ -28,6 +27,7 @@
 #include "ltp.h"
 #include "tns.h"
 #include "filtbank.h"
+#include "util.h"
 
 /* short double_to_int(double sig_in); */
 #define double_to_int(sig_in) \
@@ -287,10 +287,10 @@
 	for (channel = 0; channel < hEncoder->numChannels; channel++) {
 		LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
 
-		ltpInfo->buffer = malloc(NOK_LT_BLEN * sizeof(short));
-		ltpInfo->mdct_predicted = malloc(2*BLOCK_LEN_LONG*sizeof(double));
-		ltpInfo->time_buffer = malloc(BLOCK_LEN_LONG*sizeof(double));
-		ltpInfo->ltp_overlap_buffer = malloc(BLOCK_LEN_LONG*sizeof(double));
+		ltpInfo->buffer = AllocMemory(NOK_LT_BLEN * sizeof(short));
+		ltpInfo->mdct_predicted = AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+		ltpInfo->time_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+		ltpInfo->ltp_overlap_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
 
 		for (i = 0; i < NOK_LT_BLEN; i++)
 			ltpInfo->buffer[i] = 0;
@@ -316,8 +316,8 @@
 	for (channel = 0; channel < hEncoder->numChannels; channel++) {
 		LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
 
-		if (ltpInfo->buffer) free(ltpInfo->buffer);
-		if (ltpInfo->mdct_predicted) free(ltpInfo->mdct_predicted);
+		if (ltpInfo->buffer) FreeMemory(ltpInfo->buffer);
+		if (ltpInfo->mdct_predicted) FreeMemory(ltpInfo->mdct_predicted);
 	}
 }
 
@@ -335,7 +335,7 @@
 	ltpInfo->global_pred_flag = 0;
 	ltpInfo->side_info = 0;
 
-	predicted_samples = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
+	predicted_samples = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
 
 	switch(coderInfo->block_type)
 	{
@@ -370,7 +370,7 @@
 		break;
 	}
 
-	if (predicted_samples) free(predicted_samples);
+	if (predicted_samples) FreeMemory(predicted_samples);
 
 	return (ltpInfo->global_pred_flag);
 }
--- a/libfaac/psych.c
+++ b/libfaac/psych.c
@@ -16,11 +16,9 @@
  * 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.c,v 1.9 2001/03/06 21:02:33 menno Exp $
+ * $Id: psych.c,v 1.10 2001/03/12 16:58:37 menno Exp $
  */
 
-#include <malloc.h>
-#include <memory.h>
 #include <math.h>
 #ifdef _DEBUG
 #include <stdio.h>
@@ -42,12 +40,12 @@
 	double tmpx,tmpy,tmp,x;
 	double bval[MAX_NPART], SNR;
 
-	gpsyInfo->ath = (double*)malloc(NPART_LONG*sizeof(double));
-	gpsyInfo->athS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-	gpsyInfo->mld = (double*)malloc(NPART_LONG*sizeof(double));
-	gpsyInfo->mldS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-	gpsyInfo->window = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
-	gpsyInfo->windowS = (double*)malloc(2*BLOCK_LEN_SHORT*sizeof(double));
+	gpsyInfo->ath = (double*)AllocMemory(NPART_LONG*sizeof(double));
+	gpsyInfo->athS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->mld = (double*)AllocMemory(NPART_LONG*sizeof(double));
+	gpsyInfo->mldS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+	gpsyInfo->window = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+	gpsyInfo->windowS = (double*)AllocMemory(2*BLOCK_LEN_SHORT*sizeof(double));
 
 	for(i = 0; i < BLOCK_LEN_LONG*2; i++)
 		gpsyInfo->window[i] = 0.42-0.5*cos(2*M_PI*(i+.5)/(BLOCK_LEN_LONG*2))+
@@ -63,29 +61,29 @@
 		psyInfo[channel].lastPe = 0.0;
 		psyInfo[channel].lastEnr = 0.0;
 		psyInfo[channel].threeInARow = 0;
-		psyInfo[channel].tonality = (double*)malloc(NPART_LONG*sizeof(double));
-		psyInfo[channel].nb = (double*)malloc(NPART_LONG*sizeof(double));
-		psyInfo[channel].maskThr = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskEn = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskThrNext = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskEnNext = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskThrMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskEnMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskThrNextMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].maskEnNextMS = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-		psyInfo[channel].prevSamples = (double*)malloc(size*sizeof(double));
-		memset(psyInfo[channel].prevSamples, 0, size*sizeof(double));
+		psyInfo[channel].tonality = (double*)AllocMemory(NPART_LONG*sizeof(double));
+		psyInfo[channel].nb = (double*)AllocMemory(NPART_LONG*sizeof(double));
+		psyInfo[channel].maskThr = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEn = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskThrNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].maskEnNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+		psyInfo[channel].prevSamples = (double*)AllocMemory(size*sizeof(double));
+		SetMemory(psyInfo[channel].prevSamples, 0, size*sizeof(double));
 
-		psyInfo[channel].lastNb = (double*)malloc(NPART_LONG*sizeof(double));
-		psyInfo[channel].lastNbMS = (double*)malloc(NPART_LONG*sizeof(double));
+		psyInfo[channel].lastNb = (double*)AllocMemory(NPART_LONG*sizeof(double));
+		psyInfo[channel].lastNbMS = (double*)AllocMemory(NPART_LONG*sizeof(double));
 		for (j = 0; j < NPART_LONG; j++) {
 			psyInfo[channel].lastNb[j] = 2.;
 			psyInfo[channel].lastNbMS[j] = 2.;
 		}
 
-		psyInfo[channel].energy = (double*)malloc(size*sizeof(double));
-		psyInfo[channel].energyMS = (double*)malloc(size*sizeof(double));
-		psyInfo[channel].transBuff = (double*)malloc(2*size*sizeof(double));
+		psyInfo[channel].energy = (double*)AllocMemory(size*sizeof(double));
+		psyInfo[channel].energyMS = (double*)AllocMemory(size*sizeof(double));
+		psyInfo[channel].transBuff = (double*)AllocMemory(2*size*sizeof(double));
 	}
 
 	gpsyInfo->psyPart = &psyPartTableLong[sampleRateIdx];
@@ -95,23 +93,23 @@
 	for (channel = 0; channel < numChannels; channel++) {
 		psyInfo[channel].sizeS = size;
 
-		psyInfo[channel].prevSamplesS = (double*)malloc(size*sizeof(double));
-		memset(psyInfo[channel].prevSamplesS, 0, size*sizeof(double));
+		psyInfo[channel].prevSamplesS = (double*)AllocMemory(size*sizeof(double));
+		SetMemory(psyInfo[channel].prevSamplesS, 0, size*sizeof(double));
 
 		for (j = 0; j < 8; j++) {
-			psyInfo[channel].nbS[j] = (double*)malloc(NPART_SHORT*sizeof(double));
-			psyInfo[channel].maskThrS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskEnS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskThrNextS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskEnNextS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskThrSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskEnSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskThrNextSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
-			psyInfo[channel].maskEnNextSMS[j] = (double*)malloc(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].nbS[j] = (double*)AllocMemory(NPART_SHORT*sizeof(double));
+			psyInfo[channel].maskThrS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskThrNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+			psyInfo[channel].maskEnNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
 
-			psyInfo[channel].energyS[j] = (double*)malloc(size*sizeof(double));
-			psyInfo[channel].energySMS[j] = (double*)malloc(size*sizeof(double));
-			psyInfo[channel].transBuffS[j] = (double*)malloc(2*size*sizeof(double));
+			psyInfo[channel].energyS[j] = (double*)AllocMemory(size*sizeof(double));
+			psyInfo[channel].energySMS[j] = (double*)AllocMemory(size*sizeof(double));
+			psyInfo[channel].transBuffS[j] = (double*)AllocMemory(2*size*sizeof(double));
 		}
 	}
 
@@ -277,50 +275,50 @@
 	unsigned int channel;
 	int j;
 
-	if (gpsyInfo->ath) free(gpsyInfo->ath);
-	if (gpsyInfo->athS) free(gpsyInfo->athS);
-	if (gpsyInfo->mld) free(gpsyInfo->mld);
-	if (gpsyInfo->mldS) free(gpsyInfo->mldS);
-	if (gpsyInfo->window) free(gpsyInfo->window);
-	if (gpsyInfo->windowS) free(gpsyInfo->windowS);
+	if (gpsyInfo->ath) FreeMemory(gpsyInfo->ath);
+	if (gpsyInfo->athS) FreeMemory(gpsyInfo->athS);
+	if (gpsyInfo->mld) FreeMemory(gpsyInfo->mld);
+	if (gpsyInfo->mldS) FreeMemory(gpsyInfo->mldS);
+	if (gpsyInfo->window) FreeMemory(gpsyInfo->window);
+	if (gpsyInfo->windowS) FreeMemory(gpsyInfo->windowS);
 
 	for (channel = 0; channel < numChannels; channel++) {
-		if (psyInfo[channel].nb) free(psyInfo[channel].nb);
-		if (psyInfo[channel].tonality) free(psyInfo[channel].tonality);
-		if (psyInfo[channel].prevSamples) free(psyInfo[channel].prevSamples);
-		if (psyInfo[channel].maskThr) free(psyInfo[channel].maskThr);
-		if (psyInfo[channel].maskEn) free(psyInfo[channel].maskEn);
-		if (psyInfo[channel].maskThrNext) free(psyInfo[channel].maskThrNext);
-		if (psyInfo[channel].maskEnNext) free(psyInfo[channel].maskEnNext);
-		if (psyInfo[channel].maskThrMS) free(psyInfo[channel].maskThrMS);
-		if (psyInfo[channel].maskEnMS) free(psyInfo[channel].maskEnMS);
-		if (psyInfo[channel].maskThrNextMS) free(psyInfo[channel].maskThrNextMS);
-		if (psyInfo[channel].maskEnNextMS) free(psyInfo[channel].maskEnNextMS);
+		if (psyInfo[channel].nb) FreeMemory(psyInfo[channel].nb);
+		if (psyInfo[channel].tonality) FreeMemory(psyInfo[channel].tonality);
+		if (psyInfo[channel].prevSamples) FreeMemory(psyInfo[channel].prevSamples);
+		if (psyInfo[channel].maskThr) FreeMemory(psyInfo[channel].maskThr);
+		if (psyInfo[channel].maskEn) FreeMemory(psyInfo[channel].maskEn);
+		if (psyInfo[channel].maskThrNext) FreeMemory(psyInfo[channel].maskThrNext);
+		if (psyInfo[channel].maskEnNext) FreeMemory(psyInfo[channel].maskEnNext);
+		if (psyInfo[channel].maskThrMS) FreeMemory(psyInfo[channel].maskThrMS);
+		if (psyInfo[channel].maskEnMS) FreeMemory(psyInfo[channel].maskEnMS);
+		if (psyInfo[channel].maskThrNextMS) FreeMemory(psyInfo[channel].maskThrNextMS);
+		if (psyInfo[channel].maskEnNextMS) FreeMemory(psyInfo[channel].maskEnNextMS);
 		
-		if (psyInfo[channel].lastNb) free(psyInfo[channel].lastNb);
-		if (psyInfo[channel].lastNbMS) free(psyInfo[channel].lastNbMS);
+		if (psyInfo[channel].lastNb) FreeMemory(psyInfo[channel].lastNb);
+		if (psyInfo[channel].lastNbMS) FreeMemory(psyInfo[channel].lastNbMS);
 
-		if (psyInfo[channel].energy) free(psyInfo[channel].energy);
-		if (psyInfo[channel].energyMS) free(psyInfo[channel].energyMS);
-		if (psyInfo[channel].transBuff) free(psyInfo[channel].transBuff);
+		if (psyInfo[channel].energy) FreeMemory(psyInfo[channel].energy);
+		if (psyInfo[channel].energyMS) FreeMemory(psyInfo[channel].energyMS);
+		if (psyInfo[channel].transBuff) FreeMemory(psyInfo[channel].transBuff);
 	}
 
 	for (channel = 0; channel < numChannels; channel++) {
-		if(psyInfo[channel].prevSamplesS) free(psyInfo[channel].prevSamplesS);
+		if(psyInfo[channel].prevSamplesS) FreeMemory(psyInfo[channel].prevSamplesS);
 		for (j = 0; j < 8; j++) {
-			if (psyInfo[channel].nbS[j]) free(psyInfo[channel].nbS[j]);
-			if (psyInfo[channel].maskThrS[j]) free(psyInfo[channel].maskThrS[j]);
-			if (psyInfo[channel].maskEnS[j]) free(psyInfo[channel].maskEnS[j]);
-			if (psyInfo[channel].maskThrNextS[j]) free(psyInfo[channel].maskThrNextS[j]);
-			if (psyInfo[channel].maskEnNextS[j]) free(psyInfo[channel].maskEnNextS[j]);
-			if (psyInfo[channel].maskThrSMS[j]) free(psyInfo[channel].maskThrSMS[j]);
-			if (psyInfo[channel].maskEnSMS[j]) free(psyInfo[channel].maskEnSMS[j]);
-			if (psyInfo[channel].maskThrNextSMS[j]) free(psyInfo[channel].maskThrNextSMS[j]);
-			if (psyInfo[channel].maskEnNextSMS[j]) free(psyInfo[channel].maskEnNextSMS[j]);
+			if (psyInfo[channel].nbS[j]) FreeMemory(psyInfo[channel].nbS[j]);
+			if (psyInfo[channel].maskThrS[j]) FreeMemory(psyInfo[channel].maskThrS[j]);
+			if (psyInfo[channel].maskEnS[j]) FreeMemory(psyInfo[channel].maskEnS[j]);
+			if (psyInfo[channel].maskThrNextS[j]) FreeMemory(psyInfo[channel].maskThrNextS[j]);
+			if (psyInfo[channel].maskEnNextS[j]) FreeMemory(psyInfo[channel].maskEnNextS[j]);
+			if (psyInfo[channel].maskThrSMS[j]) FreeMemory(psyInfo[channel].maskThrSMS[j]);
+			if (psyInfo[channel].maskEnSMS[j]) FreeMemory(psyInfo[channel].maskEnSMS[j]);
+			if (psyInfo[channel].maskThrNextSMS[j]) FreeMemory(psyInfo[channel].maskThrNextSMS[j]);
+			if (psyInfo[channel].maskEnNextSMS[j]) FreeMemory(psyInfo[channel].maskEnNextSMS[j]);
 
-			if (psyInfo[channel].energyS[j]) free(psyInfo[channel].energyS[j]);
-			if (psyInfo[channel].energySMS[j]) free(psyInfo[channel].energySMS[j]);
-			if (psyInfo[channel].transBuffS[j]) free(psyInfo[channel].transBuffS[j]);
+			if (psyInfo[channel].energyS[j]) FreeMemory(psyInfo[channel].energyS[j]);
+			if (psyInfo[channel].energySMS[j]) FreeMemory(psyInfo[channel].energySMS[j]);
+			if (psyInfo[channel].transBuffS[j]) FreeMemory(psyInfo[channel].transBuffS[j]);
 		}
 	}
 }
--- a/libfaac/tns.c
+++ b/libfaac/tns.c
@@ -16,11 +16,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: tns.c,v 1.2 2001/03/05 21:24:02 oxygene Exp $
+ * $Id: tns.c,v 1.3 2001/03/12 16:58:37 menno Exp $
  */
 
 #include <math.h>
-#include <malloc.h>
 #include "frame.h"
 #include "coder.h"
 #include "bitstream.h"
@@ -376,7 +375,7 @@
 	double* a=filter->aCoeffs;
 	double* temp;
 
-    temp = (double *) malloc (length * sizeof (double));
+    temp = (double *)AllocMemory(length * sizeof (double));
 
 	/* Determine loop parameters for given direction */
 	if (filter->direction) {
@@ -419,7 +418,7 @@
 			}
 		}
 	}
-	if (temp) free(temp);
+	if (temp) FreeMemory(temp);
 }
 
 
--- a/libfaac/util.h
+++ b/libfaac/util.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: util.h,v 1.4 2001/02/28 18:39:34 menno Exp $
+ * $Id: util.h,v 1.5 2001/03/12 16:58:37 menno Exp $
  */
 
 #ifndef UTIL_H
@@ -26,6 +26,8 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#include <malloc.h>
+#include <memory.h>
 
 #ifndef max
 #define max(a, b) (((a) > (b)) ? (a) : (b))
@@ -38,6 +40,10 @@
 #define M_PI        3.14159265358979323846
 #endif
 
+/* Memory functions */
+#define AllocMemory(size) malloc(size)
+#define FreeMemory(block) free(block)
+#define SetMemory(block, value, size) memset(block, value, size)
 
 int GetSRIndex(unsigned int sampleRate);
 unsigned int MaxBitrate(unsigned long sampleRate);
@@ -44,7 +50,6 @@
 unsigned int MinBitrate();
 unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate);
 unsigned int BitAllocation(double pe, int short_block);
-
 
 #ifdef __cplusplus
 }