ref: 28139279d1c1df736e0db341f30b70ab080e1326
parent: fccac308645a539807dd5916d9e66ac1e02f70c2
author: menno <menno>
date: Sat Aug 17 06:03:16 EDT 2002
Memory allocation clean up
--- a/libfaad/cfft.c
+++ b/libfaad/cfft.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: cfft.c,v 1.1 2002/07/14 19:11:11 menno Exp $
+** $Id: cfft.c,v 1.2 2002/08/17 10:03:10 menno Exp $
**/
/*
@@ -554,14 +554,14 @@
c[i] = ch[i];
}
-void cfftf(cfft_info cfft, real_t *c)
+void cfftf(cfft_info *cfft, real_t *c)
{
- cfftf1(cfft.n, c, cfft.work, cfft.tab, cfft.ifac, -1);
+ cfftf1(cfft->n, c, cfft->work, cfft->tab, cfft->ifac, -1);
}
-void cfftb(cfft_info cfft, real_t *c)
+void cfftb(cfft_info *cfft, real_t *c)
{
- cfftf1(cfft.n, c, cfft.work, cfft.tab, cfft.ifac, +1);
+ cfftf1(cfft->n, c, cfft->work, cfft->tab, cfft->ifac, +1);
}
static void cffti1(uint16_t n, real_t *wa, uint16_t *ifac)
@@ -651,21 +651,23 @@
}
}
-cfft_info cffti(uint16_t n)
+cfft_info *cffti(uint16_t n)
{
- cfft_info cfft;
+ cfft_info *cfft = malloc(sizeof(cfft_info));
- cfft.n = n;
- cfft.work = malloc(2*n*sizeof(real_t));
- cfft.tab = malloc(2*n*sizeof(real_t));
+ cfft->n = n;
+ cfft->work = malloc(2*n*sizeof(real_t));
+ cfft->tab = malloc(2*n*sizeof(real_t));
- cffti1(n, cfft.tab, cfft.ifac);
+ cffti1(n, cfft->tab, cfft->ifac);
return cfft;
}
-void cfftu(cfft_info cfft)
+void cfftu(cfft_info *cfft)
{
- if (cfft.work) free(cfft.work);
- if (cfft.tab) free(cfft.tab);
+ if (cfft->work) free(cfft->work);
+ if (cfft->tab) free(cfft->tab);
+
+ if (cfft) free(cfft);
}
\ No newline at end of file
--- a/libfaad/cfft.h
+++ b/libfaad/cfft.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: cfft.h,v 1.1 2002/07/14 19:11:11 menno Exp $
+** $Id: cfft.h,v 1.2 2002/08/17 10:03:11 menno Exp $
**/
#ifndef __CFFT_H__
@@ -34,10 +34,10 @@
uint16_t n;
} cfft_info;
-void cfftf(cfft_info cfft, real_t *c); // complex transform
-void cfftb(cfft_info cfft, real_t *c); // its inverse
-cfft_info cffti(uint16_t n); // initializer of the above routine pair
-void cfftu(cfft_info cfft);
+void cfftf(cfft_info *cfft, real_t *c); // complex transform
+void cfftb(cfft_info *cfft, real_t *c); // its inverse
+cfft_info *cffti(uint16_t n); // initializer of the above routine pair
+void cfftu(cfft_info *cfft);
static void passf2(uint16_t ido, uint16_t l1, real_t *cc, real_t *ch,
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.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: decoder.c,v 1.18 2002/08/05 20:33:38 menno Exp $
+** $Id: decoder.c,v 1.19 2002/08/17 10:03:12 menno Exp $
**/
#include <stdlib.h>
@@ -55,7 +55,6 @@
return NULL;
memset(hDecoder, 0, sizeof(faacDecStruct));
- memset(&hDecoder->fb, 0, sizeof(fb_info));
hDecoder->config.outputFormat = FAAD_FMT_16BIT;
hDecoder->config.defObjectType = MAIN;
@@ -84,7 +83,7 @@
#endif
}
- init_drc(&hDecoder->drc, 1.0f, 1.0f);
+ hDecoder->drc = drc_init(1.0f, 1.0f);
#if IQ_TABLE_SIZE && POW_TABLE_SIZE
build_tables(hDecoder->iq_table, hDecoder->pow2_table);
#elif !POW_TABLE_SIZE
@@ -239,7 +238,7 @@
hDecoder->channelConfiguration = *channels;
/* must be done before frameLength is divided by 2 for LD */
- filter_bank_init(&hDecoder->fb, hDecoder->frameLength);
+ hDecoder->fb = filter_bank_init(hDecoder->frameLength);
#ifdef LD_DEC
if (hDecoder->object_type == LD)
@@ -289,7 +288,7 @@
hDecoder->frameLength = 960;
/* must be done before frameLength is divided by 2 for LD */
- filter_bank_init(&hDecoder->fb, hDecoder->frameLength);
+ hDecoder->fb = filter_bank_init(hDecoder->frameLength);
#ifdef LD_DEC
if (hDecoder->object_type == LD)
@@ -315,8 +314,10 @@
#endif
}
- filter_bank_end(&hDecoder->fb);
+ filter_bank_end(hDecoder->fb);
+ drc_end(hDecoder->drc);
+
if (hDecoder->sample_buffer) free(hDecoder->sample_buffer);
if (hDecoder) free(hDecoder);
@@ -449,8 +450,8 @@
uint8_t *window_shape_prev = hDecoder->window_shape_prev;
real_t **time_state = hDecoder->time_state;
real_t **time_out = hDecoder->time_out;
- fb_info *fb = &hDecoder->fb;
- drc_info *drc = &hDecoder->drc;
+ fb_info *fb = hDecoder->fb;
+ drc_info *drc = hDecoder->drc;
uint8_t outputFormat = hDecoder->config.outputFormat;
#ifdef LTP_DEC
uint16_t *ltp_lag = hDecoder->ltp_lag;
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.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: decoder.h,v 1.8 2002/08/13 19:16:07 menno Exp $
+** $Id: decoder.h,v 1.9 2002/08/17 10:03:12 menno Exp $
**/
#ifndef __DECODER_H__
@@ -85,8 +85,8 @@
#ifdef LTP_DEC
uint16_t ltp_lag[MAX_CHANNELS];
#endif
- fb_info fb;
- drc_info drc;
+ fb_info *fb;
+ drc_info *drc;
real_t *time_state[MAX_CHANNELS];
real_t *time_out[MAX_CHANNELS];
--- a/libfaad/drc.c
+++ b/libfaad/drc.c
@@ -16,17 +16,18 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: drc.c,v 1.5 2002/05/24 17:26:12 menno Exp $
+** $Id: drc.c,v 1.6 2002/08/17 10:03:12 menno Exp $
**/
#include "common.h"
-#include <memory.h>
+#include <stdlib.h>
#include "syntax.h"
#include "drc.h"
-void init_drc(drc_info *drc, real_t cut, real_t boost)
+drc_info *drc_init(real_t cut, real_t boost)
{
+ drc_info *drc = malloc(sizeof(drc_info));
memset(drc, 0, sizeof(drc_info));
drc->ctrl1 = cut;
@@ -36,6 +37,13 @@
drc->band_top[0] = 1024/4 - 1;
drc->dyn_rng_sgn[0] = 1;
drc->dyn_rng_ctl[0] = 0;
+
+ return drc;
+}
+
+void drc_end(drc_info *drc)
+{
+ if (drc) free(drc);
}
void drc_decode(drc_info *drc, real_t *spec)
--- a/libfaad/drc.h
+++ b/libfaad/drc.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: drc.h,v 1.2 2002/02/18 10:01:05 menno Exp $
+** $Id: drc.h,v 1.3 2002/08/17 10:03:13 menno Exp $
**/
#ifndef __DRC_H__
@@ -28,7 +28,8 @@
#define DRC_REF_LEVEL 20*4 /* -20 dB */
-void init_drc(drc_info *drc, real_t cut, real_t boost);
+drc_info *drc_init(real_t cut, real_t boost);
+void drc_end(drc_info *drc);
void drc_decode(drc_info *drc, real_t *spec);
--- a/libfaad/filtbank.c
+++ b/libfaad/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.11 2002/08/05 20:33:38 menno Exp $
+** $Id: filtbank.c,v 1.12 2002/08/17 10:03:13 menno Exp $
**/
#include "common.h"
@@ -29,7 +29,7 @@
#include "mdct.h"
-void filter_bank_init(fb_info *fb, uint16_t frame_len)
+fb_info *filter_bank_init(uint16_t frame_len)
{
uint16_t i;
uint16_t nshort = frame_len/8;
@@ -36,10 +36,12 @@
#ifdef LD_DEC
uint16_t frame_len_ld = frame_len/2;
#endif
+ fb_info *fb = malloc(sizeof(fb_info));
+ memset(fb, 0, sizeof(fb_info));
/* normal */
- faad_mdct_init(&(fb->mdct256), 2*nshort);
- faad_mdct_init(&(fb->mdct2048), 2*frame_len);
+ fb->mdct256 = faad_mdct_init(2*nshort);
+ fb->mdct2048 = faad_mdct_init(2*frame_len);
fb->long_window[0] = malloc(frame_len*sizeof(real_t));
fb->short_window[0] = malloc(nshort*sizeof(real_t));
@@ -54,7 +56,7 @@
#ifdef LD_DEC
/* LD */
- faad_mdct_init(&(fb->mdct1024), frame_len_ld);
+ fb->mdct1024 = faad_mdct_init(frame_len_ld);
fb->ld_window[0] = malloc(frame_len_ld*sizeof(real_t));
fb->ld_window[1] = malloc(frame_len_ld*sizeof(real_t));
@@ -71,22 +73,26 @@
for (; i < frame_len_ld; i++)
fb->ld_window[1][i] = 1.0;
#endif
+
+ return fb;
}
void filter_bank_end(fb_info *fb)
{
- faad_mdct_end(&(fb->mdct256));
- faad_mdct_end(&(fb->mdct2048));
+ faad_mdct_end(fb->mdct256);
+ faad_mdct_end(fb->mdct2048);
if (fb->long_window[0]) free(fb->long_window[0]);
if (fb->short_window[0]) free(fb->short_window[0]);
#ifdef LD_DEC
- faad_mdct_end(&(fb->mdct1024));
+ faad_mdct_end(fb->mdct1024);
if (fb->ld_window[0]) free(fb->ld_window[0]);
if (fb->ld_window[1]) free(fb->ld_window[1]);
#endif
+
+ if (fb) free(fb);
}
static INLINE void vcopy(real_t *src, real_t *dest, uint16_t vlen)
@@ -149,14 +155,6 @@
{
*dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
*dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
-/*
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
-*/
}
}
@@ -168,16 +166,16 @@
{
case 2048:
case 1920:
- mdct = &(fb->mdct2048);
+ mdct = fb->mdct2048;
break;
case 256:
case 240:
- mdct = &(fb->mdct256);
+ mdct = fb->mdct256;
break;
#ifdef LD_DEC
case 1024:
case 960:
- mdct = &(fb->mdct1024);
+ mdct = fb->mdct1024;
break;
#endif
}
@@ -194,16 +192,16 @@
{
case 2048:
case 1920:
- mdct = &(fb->mdct2048);
+ mdct = fb->mdct2048;
break;
case 256:
case 120:
- mdct = &(fb->mdct256);
+ mdct = fb->mdct256;
break;
#ifdef LD_DEC
case 1024:
case 960:
- mdct = &(fb->mdct1024);
+ mdct = fb->mdct1024;
break;
#endif
}
--- a/libfaad/filtbank.h
+++ b/libfaad/filtbank.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: filtbank.h,v 1.7 2002/06/13 11:03:27 menno Exp $
+** $Id: filtbank.h,v 1.8 2002/08/17 10:03:14 menno Exp $
**/
#ifndef __FILTBANK_H__
@@ -37,14 +37,14 @@
real_t *ld_window[2];
#endif
- mdct_info mdct256;
+ mdct_info *mdct256;
#ifdef LD_DEC
- mdct_info mdct1024;
+ mdct_info *mdct1024;
#endif
- mdct_info mdct2048;
+ mdct_info *mdct2048;
} fb_info;
-void filter_bank_init(fb_info *fb, uint16_t frame_len);
+fb_info *filter_bank_init(uint16_t frame_len);
void filter_bank_end(fb_info *fb);
#ifdef LTP_DEC
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -64,7 +64,7 @@
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "fftw" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /YX /FD /GZ /c
+# ADD CPP /nologo /Zp8 /MTd /W3 /Gm /GX /ZI /Od /I "fftw" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /YX /FD /GZ /c
# ADD BASE RSC /l 0x413 /d "_DEBUG"
# ADD RSC /l 0x413 /d "_DEBUG"
BSC32=bscmake.exe
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.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: mdct.c,v 1.12 2002/08/10 19:01:18 menno Exp $
+** $Id: mdct.c,v 1.13 2002/08/17 10:03:15 menno Exp $
**/
/*
@@ -52,10 +52,12 @@
#include "mdct.h"
-void faad_mdct_init(mdct_info *mdct, uint16_t N)
+mdct_info *faad_mdct_init(uint16_t N)
{
uint16_t k;
+ mdct_info *mdct = malloc(sizeof(mdct_info));
+
assert(N % 8 == 0);
mdct->N = N;
@@ -84,6 +86,8 @@
/* own implementation */
mdct->cfft = cffti(N/4);
#endif
+
+ return mdct;
}
void faad_mdct_end(mdct_info *mdct)
@@ -100,6 +104,8 @@
if (mdct->Z2) free(mdct->Z2);
if (mdct->Z1) free(mdct->Z1);
if (mdct->sincos) free(mdct->sincos);
+
+ if (mdct) free(mdct);
}
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
--- a/libfaad/mdct.h
+++ b/libfaad/mdct.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: mdct.h,v 1.9 2002/07/14 19:11:12 menno Exp $
+** $Id: mdct.h,v 1.10 2002/08/17 10:03:16 menno Exp $
**/
#ifndef __MDCT_H__
@@ -56,12 +56,12 @@
#else
real_t *Z1;
faad_complex *Z2;
- cfft_info cfft;
+ cfft_info *cfft;
#endif
uint16_t N;
} mdct_info;
-void faad_mdct_init(mdct_info *mdct, uint16_t N);
+mdct_info *faad_mdct_init(uint16_t N);
void faad_mdct_end(mdct_info *mdct);
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out);
void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out);