summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libfaad/bits.c25
-rw-r--r--src/libfaad/bits.h40
-rw-r--r--src/libfaad/cfft.c17
-rw-r--r--src/libfaad/cfft.h15
-rw-r--r--src/libfaad/common.h7
-rw-r--r--src/libfaad/data.c9
-rw-r--r--src/libfaad/data.h3
-rw-r--r--src/libfaad/decoder.c99
-rw-r--r--src/libfaad/decoder.h30
-rw-r--r--src/libfaad/error.c7
-rw-r--r--src/libfaad/faad.h58
-rw-r--r--src/libfaad/filtbank.c21
-rw-r--r--src/libfaad/fixed.h34
-rw-r--r--src/libfaad/hcr.c6
-rw-r--r--src/libfaad/mdct.c19
-rw-r--r--src/libfaad/mp4.c73
-rw-r--r--src/libfaad/mp4.h11
-rw-r--r--src/libfaad/output.c16
-rw-r--r--src/libfaad/pns.c20
-rw-r--r--src/libfaad/pulse.c8
-rw-r--r--src/libfaad/pulse.h4
-rw-r--r--src/libfaad/rvlc.c14
-rw-r--r--src/libfaad/specrec.c48
-rw-r--r--src/libfaad/structs.h23
-rw-r--r--src/libfaad/syntax.c175
-rw-r--r--src/libfaad/syntax.h47
-rw-r--r--src/libfaad/tns.c104
-rw-r--r--src/libfaad/tns.h6
28 files changed, 533 insertions, 406 deletions
diff --git a/src/libfaad/bits.c b/src/libfaad/bits.c
index 66cade533..d08d69c77 100644
--- a/src/libfaad/bits.c
+++ b/src/libfaad/bits.c
@@ -1,22 +1,22 @@
/*
** FAAD - Freeware Advanced Audio Decoder
** Copyright (C) 2002 M. Bakker
-**
+**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
-**
+**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
-**
+**
** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
+** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: bits.c,v 1.3 2002/12/16 18:59:52 miguelfreitas Exp $
+** $Id: bits.c,v 1.4 2003/04/12 14:58:46 miguelfreitas Exp $
**/
#include "common.h"
@@ -53,11 +53,16 @@ void faad_initbits(bitfile *ld, void *_buffer, uint32_t buffer_size)
ld->tail = ((uint32_t*)ld->buffer + 2);
ld->bits_left = 32;
+
+ ld->bytes_used = 0;
+ ld->no_more_reading = 0;
+ ld->error = 0;
}
void faad_endbits(bitfile *ld)
{
- if (ld->buffer) free(ld->buffer);
+ if (ld)
+ if (ld->buffer) free(ld->buffer);
}
@@ -96,13 +101,15 @@ void faad_rewindbits(bitfile *ld)
ld->bufb = tmp;
ld->bits_left = 32;
ld->tail = &ld->start[2];
+ ld->bytes_used = 0;
+ ld->no_more_reading = 0;
}
uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
DEBUGDEC)
{
uint16_t i;
- uint8_t temp;
+ uint8_t temp;
uint16_t bytes = (uint16_t)bits / 8;
uint8_t remainder = (uint8_t)bits % 8;
@@ -153,4 +160,8 @@ void faad_initbits_rev(bitfile *ld, void *buffer,
ld->bits_left = bits_in_buffer % 32;
if (ld->bits_left == 0)
ld->bits_left = 32;
+
+ ld->bytes_used = 0;
+ ld->no_more_reading = 0;
+ ld->error = 0;
}
diff --git a/src/libfaad/bits.h b/src/libfaad/bits.h
index cdf83b539..dfb5ca659 100644
--- a/src/libfaad/bits.h
+++ b/src/libfaad/bits.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: bits.h,v 1.3 2002/12/16 18:59:53 miguelfreitas Exp $
+** $Id: bits.h,v 1.4 2003/04/12 14:58:46 miguelfreitas Exp $
**/
#ifndef __BITS_H__
@@ -41,6 +41,9 @@ typedef struct _bitfile
uint32_t bufb;
uint32_t bits_left;
uint32_t buffer_size; /* size of the buffer in bytes */
+ uint32_t bytes_used;
+ uint8_t no_more_reading;
+ uint8_t error;
uint32_t *tail;
uint32_t *start;
void *buffer;
@@ -103,6 +106,10 @@ static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits)
static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
{
+ /* do nothing if error */
+ if (ld->error != 0)
+ return;
+
if (bits < ld->bits_left)
{
ld->bits_left -= bits;
@@ -117,6 +124,11 @@ static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
#endif
ld->bufb = tmp;
ld->bits_left += (32 - bits);
+ ld->bytes_used += 4;
+ if (ld->bytes_used == ld->buffer_size)
+ ld->no_more_reading = 1;
+ if (ld->bytes_used > ld->buffer_size)
+ ld->error = 1;
}
}
@@ -125,6 +137,9 @@ static INLINE uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
{
uint32_t ret;
+ if (ld->no_more_reading)
+ return 0;
+
if (n == 0)
return 0;
@@ -141,7 +156,15 @@ static INLINE uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
static INLINE uint8_t faad_get1bit(bitfile *ld DEBUGDEC)
{
- return (uint8_t)faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
+ uint8_t r;
+
+ if (ld->bits_left == 0)
+ return (uint8_t)faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
+
+ ld->bits_left--;
+ r = (ld->bufa >> ld->bits_left) & 1;
+
+ return r;
}
/* reversed bitreading routines */
@@ -175,6 +198,10 @@ static INLINE uint32_t faad_showbits_rev(bitfile *ld, uint32_t bits)
static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
{
+ /* do nothing if error */
+ if (ld->error != 0)
+ return;
+
if (bits < ld->bits_left)
{
ld->bits_left -= bits;
@@ -189,6 +216,12 @@ static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
ld->bufb = tmp;
ld->start--;
ld->bits_left += (32 - bits);
+
+ ld->bytes_used += 4;
+ if (ld->bytes_used == ld->buffer_size)
+ ld->no_more_reading = 1;
+ if (ld->bytes_used > ld->buffer_size)
+ ld->error = 1;
}
}
@@ -197,6 +230,9 @@ static INLINE uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
{
uint32_t ret;
+ if (ld->no_more_reading)
+ return 0;
+
if (n == 0)
return 0;
diff --git a/src/libfaad/cfft.c b/src/libfaad/cfft.c
index a834c73da..a18527dbc 100644
--- a/src/libfaad/cfft.c
+++ b/src/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.5 2003/02/28 02:51:48 storri Exp $
+** $Id: cfft.c,v 1.6 2003/04/12 14:58:46 miguelfreitas Exp $
**/
/*
@@ -37,6 +37,21 @@
#include "cfft_tab.h"
+/* static declarations moved to avoid compiler warnings [MF] */
+static void passf2(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
+ complex_t *wa, int8_t isign);
+static void passf3(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
+ complex_t *wa1, complex_t *wa2, int8_t isign);
+static void passf4(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
+ complex_t *wa1, complex_t *wa2, complex_t *wa3, int8_t isign);
+static void passf5(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
+ complex_t *wa1, complex_t *wa2, complex_t *wa3, complex_t *wa4,
+ int8_t isign);
+INLINE void cfftf1(uint16_t n, complex_t *c, complex_t *ch,
+ uint16_t *ifac, complex_t *wa, int8_t isign);
+static void cffti1(uint16_t n, complex_t *wa, uint16_t *ifac);
+
+
/*----------------------------------------------------------------------
passf2, passf3, passf4, passf5. Complex FFT passes fwd and bwd.
----------------------------------------------------------------------*/
diff --git a/src/libfaad/cfft.h b/src/libfaad/cfft.h
index c3d860e71..4b2d9f544 100644
--- a/src/libfaad/cfft.h
+++ b/src/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.3 2002/12/16 18:59:55 miguelfreitas Exp $
+** $Id: cfft.h,v 1.4 2003/04/12 14:58:46 miguelfreitas Exp $
**/
#ifndef __CFFT_H__
@@ -33,18 +33,7 @@ cfft_info *cffti(uint16_t n);
void cfftu(cfft_info *cfft);
-static void passf2(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
- complex_t *wa, int8_t isign);
-static void passf3(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
- complex_t *wa1, complex_t *wa2, int8_t isign);
-static void passf4(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
- complex_t *wa1, complex_t *wa2, complex_t *wa3, int8_t isign);
-static void passf5(uint16_t ido, uint16_t l1, complex_t *cc, complex_t *ch,
- complex_t *wa1, complex_t *wa2, complex_t *wa3, complex_t *wa4,
- int8_t isign);
-INLINE void cfftf1(uint16_t n, complex_t *c, complex_t *ch,
- uint16_t *ifac, complex_t *wa, int8_t isign);
-static void cffti1(uint16_t n, complex_t *wa, uint16_t *ifac);
+/* static declarations moved to avoid compiler warnings [MF] */
#ifdef __cplusplus
diff --git a/src/libfaad/common.h b/src/libfaad/common.h
index 82b1d33d2..4683121e5 100644
--- a/src/libfaad/common.h
+++ b/src/libfaad/common.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: common.h,v 1.6 2003/01/31 01:20:27 storri Exp $
+** $Id: common.h,v 1.7 2003/04/12 14:58:46 miguelfreitas Exp $
**/
#ifndef __COMMON_H__
@@ -55,7 +55,7 @@ extern "C" {
/* Allow decoding of MAIN profile AAC */
#define MAIN_DEC
/* Allow decoding of SSR profile AAC */
-#define SSR_DEC
+//#define SSR_DEC
/* Allow decoding of LTP profile AAC */
#define LTP_DEC
/* Allow decoding of LD profile AAC */
@@ -259,6 +259,9 @@ typedef real_t complex_t[2];
/* common functions */
uint32_t int_log2(uint32_t val);
+uint8_t get_sr_index(uint32_t samplerate);
+int8_t can_decode_ot(uint8_t object_type);
+
#ifndef M_PI
#define M_PI 3.14159265358979323846f
#endif
diff --git a/src/libfaad/data.c b/src/libfaad/data.c
index cac03544b..07ae4957f 100644
--- a/src/libfaad/data.c
+++ b/src/libfaad/data.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: data.c,v 1.2 2002/12/16 18:59:57 miguelfreitas Exp $
+** $Id: data.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -33,6 +33,11 @@ extern uint8_t num_swb_480_window[] =
};
#endif
+extern uint8_t num_swb_960_window[] =
+{
+ 40, 40, 45, 49, 49, 49, 46, 46, 42, 42, 42, 40
+};
+
extern uint8_t num_swb_1024_window[] =
{
41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40
@@ -260,4 +265,4 @@ extern uint32_t sample_rates[] =
{
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
12000, 11025, 8000
-}; \ No newline at end of file
+};
diff --git a/src/libfaad/data.h b/src/libfaad/data.h
index 6873c1217..6b001f442 100644
--- a/src/libfaad/data.h
+++ b/src/libfaad/data.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: data.h,v 1.2 2002/12/16 18:59:58 miguelfreitas Exp $
+** $Id: data.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __DATA_H__
@@ -27,6 +27,7 @@ extern "C" {
#endif
extern uint8_t num_swb_1024_window[];
+extern uint8_t num_swb_960_window[];
#ifdef LD_DEC
extern uint8_t num_swb_512_window[];
extern uint8_t num_swb_480_window[];
diff --git a/src/libfaad/decoder.c b/src/libfaad/decoder.c
index 1d492ef11..64d8259f8 100644
--- a/src/libfaad/decoder.c
+++ b/src/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.3 2002/12/16 18:59:59 miguelfreitas Exp $
+** $Id: decoder.c,v 1.4 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -54,6 +54,32 @@ int8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode)
return err_msg[errcode];
}
+uint32_t FAADAPI faacDecGetCapabilities()
+{
+ uint32_t cap = 0;
+
+ /* can't do without it */
+ cap += LC_DEC_CAP;
+
+#ifdef MAIN_DEC
+ cap += MAIN_DEC_CAP;
+#endif
+#ifdef LTP_DEC
+ cap += LTP_DEC_CAP;
+#endif
+#ifdef LD_DEC
+ cap += LD_DEC_CAP;
+#endif
+#ifdef ERROR_RESILIENCE
+ cap += ERROR_RESILIENCE_CAP;
+#endif
+#ifdef FIXED_POINT
+ cap += FIXED_POINT_CAP;
+#endif
+
+ return cap;
+}
+
faacDecHandle FAADAPI faacDecOpen()
{
uint8_t i;
@@ -149,6 +175,7 @@ int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
hDecoder->adif_header_present = 1;
get_adif_header(&adif, &ld);
+ faad_byte_align(&ld);
hDecoder->sf_index = adif.pce.sf_index;
hDecoder->object_type = adif.pce.object_type;
@@ -172,6 +199,11 @@ int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
2 : adts.channel_configuration;
}
+ if (ld.error)
+ {
+ faad_endbits(&ld);
+ return -1;
+ }
faad_endbits(&ld);
}
hDecoder->channelConfiguration = *channels;
@@ -193,8 +225,8 @@ int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
return -1;
#ifndef FIXED_POINT
- if (hDecoder->config.outputFormat >= 5)
- Init_Dither(16, hDecoder->config.outputFormat - 5);
+ if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+ Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
#endif
return bits;
@@ -206,7 +238,7 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
uint32_t *samplerate, uint8_t *channels)
{
int8_t rc;
- uint8_t frameLengthFlag;
+ mp4AudioSpecificConfig mp4ASC;
hDecoder->adif_header_present = 0;
hDecoder->adts_header_present = 0;
@@ -220,17 +252,18 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
return -1;
}
- rc = AudioSpecificConfig(pBuffer, SizeOfDecoderSpecificInfo,
- samplerate, channels,
- &hDecoder->sf_index, &hDecoder->object_type,
-#ifdef ERROR_RESILIENCE
- &hDecoder->aacSectionDataResilienceFlag,
- &hDecoder->aacScalefactorDataResilienceFlag,
- &hDecoder->aacSpectralDataResilienceFlag,
-#else
- NULL, NULL, NULL,
-#endif
- &frameLengthFlag);
+ /* decode the audio specific config */
+ rc = AudioSpecificConfig(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC);
+
+ /* copy the relevant info to the decoder handle */
+ *samplerate = mp4ASC.samplingFrequency;
+ *channels = mp4ASC.channelsConfiguration;
+ hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
+ hDecoder->object_type = mp4ASC.objectTypeIndex;
+ hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag;
+ hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag;
+ hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag;
+
if (hDecoder->object_type < 5)
hDecoder->object_type--; /* For AAC differs from MPEG-4 */
if (rc != 0)
@@ -238,7 +271,7 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
return rc;
}
hDecoder->channelConfiguration = *channels;
- if (frameLengthFlag)
+ if (mp4ASC.frameLengthFlag)
hDecoder->frameLength = 960;
/* must be done before frameLength is divided by 2 for LD */
@@ -255,8 +288,8 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
#endif
#ifndef FIXED_POINT
- if (hDecoder->config.outputFormat >= 5)
- Init_Dither(16, hDecoder->config.outputFormat - 5);
+ if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+ Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
#endif
return 0;
@@ -281,8 +314,8 @@ int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate,
hDecoder->fb = filter_bank_init(hDecoder->frameLength);
#ifndef FIXED_POINT
- if (hDecoder->config.outputFormat >= 5)
- Init_Dither(16, hDecoder->config.outputFormat - 5);
+ if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+ Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
#endif
return 0;
@@ -292,6 +325,9 @@ void FAADAPI faacDecClose(faacDecHandle hDecoder)
{
uint8_t i;
+ if (hDecoder == NULL)
+ return;
+
for (i = 0; i < MAX_CHANNELS; i++)
{
if (hDecoder->time_out[i]) free(hDecoder->time_out[i]);
@@ -412,24 +448,30 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
elements = raw_data_block(hDecoder, hInfo, ld, syntax_elements,
spec_data, spec_coef, &pce, drc);
- if (hInfo->error > 0)
- goto error;
-
ch_ele = hDecoder->fr_ch_ele;
channels = hDecoder->fr_channels;
+ if (hInfo->error > 0)
+ goto error;
+
/* no more bit reading after this */
- faad_byte_align(ld);
hInfo->bytesconsumed = bit2byte(faad_get_processed_bits(ld));
+ if (ld->error)
+ {
+ hInfo->error = 14;
+ goto error;
+ }
faad_endbits(ld);
if (ld) free(ld);
ld = NULL;
/* number of samples in this frame */
hInfo->samples = frame_len*channels;
- /* number of samples in this frame */
+ /* number of channels in this frame */
hInfo->channels = channels;
+ /* samplerate */
+ hInfo->samplerate = sample_rates[hDecoder->sf_index];
/* check if frame has channel elements */
if (channels == 0)
@@ -439,7 +481,12 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
}
if (hDecoder->sample_buffer == NULL)
- hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(real_t));
+ {
+ if (hDecoder->config.outputFormat == FAAD_FMT_DOUBLE)
+ hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(double));
+ else
+ hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(real_t));
+ }
sample_buffer = hDecoder->sample_buffer;
diff --git a/src/libfaad/decoder.h b/src/libfaad/decoder.h
index a7ea19232..0b4a5e0c6 100644
--- a/src/libfaad/decoder.h
+++ b/src/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.2 2002/12/16 18:59:59 miguelfreitas Exp $
+** $Id: decoder.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __DECODER_H__
@@ -45,18 +45,30 @@ extern "C" {
#include "ic_predict.h"
-#define FAAD_FMT_16BIT 1
-#define FAAD_FMT_24BIT 2
-#define FAAD_FMT_32BIT 3
-#define FAAD_FMT_FLOAT 4
-#define FAAD_FMT_16BIT_DITHER 5
-#define FAAD_FMT_16BIT_L_SHAPE 6
-#define FAAD_FMT_16BIT_M_SHAPE 7
-#define FAAD_FMT_16BIT_H_SHAPE 8
+/* library output formats */
+#define FAAD_FMT_16BIT 1
+#define FAAD_FMT_24BIT 2
+#define FAAD_FMT_32BIT 3
+#define FAAD_FMT_FLOAT 4
+#define FAAD_FMT_DOUBLE 5
+#define FAAD_FMT_16BIT_DITHER 6
+#define FAAD_FMT_16BIT_L_SHAPE 7
+#define FAAD_FMT_16BIT_M_SHAPE 8
+#define FAAD_FMT_16BIT_H_SHAPE 9
+#define FAAD_FMT_DITHER_LOWEST FAAD_FMT_16BIT_DITHER
+
+#define LC_DEC_CAP (1<<0)
+#define MAIN_DEC_CAP (1<<1)
+#define LTP_DEC_CAP (1<<2)
+#define LD_DEC_CAP (1<<3)
+#define ERROR_RESILIENCE_CAP (1<<4)
+#define FIXED_POINT_CAP (1<<5)
int8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode);
+uint32_t FAADAPI faacDecGetCapabilities();
+
faacDecHandle FAADAPI faacDecOpen();
faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder);
diff --git a/src/libfaad/error.c b/src/libfaad/error.c
index 2e766f64e..b716d4837 100644
--- a/src/libfaad/error.c
+++ b/src/libfaad/error.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: error.c,v 1.2 2002/12/16 19:00:01 miguelfreitas Exp $
+** $Id: error.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -36,5 +36,6 @@ extern int8_t *err_msg[] = {
"Error decoding huffman codeword (bitstream error)",
"Non existent huffman codebook number found",
"Maximum number of channels exceeded",
- "Maximum number of bitstream elements exceeded"
-}; \ No newline at end of file
+ "Maximum number of bitstream elements exceeded",
+ "Input data buffer too small"
+};
diff --git a/src/libfaad/faad.h b/src/libfaad/faad.h
index a86128733..3c904ce09 100644
--- a/src/libfaad/faad.h
+++ b/src/libfaad/faad.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: faad.h,v 1.2 2002/12/16 19:00:02 miguelfreitas Exp $
+** $Id: faad.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __AACDEC_H__
@@ -55,14 +55,23 @@ extern "C" {
#define ADTS 2
/* library output formats */
-#define FAAD_FMT_16BIT 1
-#define FAAD_FMT_24BIT 2
-#define FAAD_FMT_32BIT 3
-#define FAAD_FMT_FLOAT 4
-#define FAAD_FMT_16BIT_DITHER 5
-#define FAAD_FMT_16BIT_L_SHAPE 6
-#define FAAD_FMT_16BIT_M_SHAPE 7
-#define FAAD_FMT_16BIT_H_SHAPE 8
+#define FAAD_FMT_16BIT 1
+#define FAAD_FMT_24BIT 2
+#define FAAD_FMT_32BIT 3
+#define FAAD_FMT_FLOAT 4
+#define FAAD_FMT_DOUBLE 5
+#define FAAD_FMT_16BIT_DITHER 6
+#define FAAD_FMT_16BIT_L_SHAPE 7
+#define FAAD_FMT_16BIT_M_SHAPE 8
+#define FAAD_FMT_16BIT_H_SHAPE 9
+
+/* Capabilities */
+#define LC_DEC_CAP (1<<0)
+#define MAIN_DEC_CAP (1<<1)
+#define LTP_DEC_CAP (1<<2)
+#define LD_DEC_CAP (1<<3)
+#define ERROR_RESILIENCE_CAP (1<<4)
+#define FIXED_POINT_CAP (1<<5)
/* A decode call can eat up to FAAD_MIN_STREAMSIZE octets per decoded channel,
so at least so much octets per channel should be available in this stream */
@@ -71,6 +80,25 @@ extern "C" {
typedef void *faacDecHandle;
+typedef struct mp4AudioSpecificConfig
+{
+ /* Audio Specific Info */
+ unsigned char objectTypeIndex;
+ unsigned char samplingFrequencyIndex;
+ unsigned long samplingFrequency;
+ unsigned char channelsConfiguration;
+
+ /* GA Specific Info */
+ unsigned char frameLengthFlag;
+ unsigned char dependsOnCoreCoder;
+ unsigned long coreCoderDelay;
+ unsigned char extensionFlag;
+ unsigned char aacSectionDataResilienceFlag;
+ unsigned char aacScalefactorDataResilienceFlag;
+ unsigned char aacSpectralDataResilienceFlag;
+ unsigned char epConfig;
+
+} mp4AudioSpecificConfig;
typedef struct faacDecConfiguration
{
@@ -85,10 +113,13 @@ typedef struct faacDecFrameInfo
unsigned long samples;
unsigned char channels;
unsigned char error;
+ unsigned long samplerate;
} faacDecFrameInfo;
char* FAADAPI faacDecGetErrorMessage(unsigned char errcode);
+unsigned long FAADAPI faacDecGetCapabilities();
+
faacDecHandle FAADAPI faacDecOpen();
faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder);
@@ -121,14 +152,7 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
char FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
unsigned long buffer_size,
- unsigned long *samplerate,
- unsigned char *channels,
- unsigned char *sf_index,
- unsigned char *object_type,
- unsigned char *aacSectionDataResilienceFlag,
- unsigned char *aacScalefactorDataResilienceFlag,
- unsigned char *aacSpectralDataResilienceFlag,
- unsigned char *frameLengthFlag);
+ mp4AudioSpecificConfig *mp4ASC);
#ifdef _WIN32
#pragma pack(pop)
diff --git a/src/libfaad/filtbank.c b/src/libfaad/filtbank.c
index d17c95473..27480a16d 100644
--- a/src/libfaad/filtbank.c
+++ b/src/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.4 2003/02/28 02:51:49 storri Exp $
+** $Id: filtbank.c,v 1.5 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -25,9 +25,9 @@
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32_WCE
-#define XINE_ASSERT(x)
+#define assert(x)
#else
-#include "xineutils.h"
+#include <assert.h>
#endif
#include "filtbank.h"
@@ -82,13 +82,16 @@ fb_info *filter_bank_init(uint16_t frame_len)
void filter_bank_end(fb_info *fb)
{
- faad_mdct_end(fb->mdct256);
- faad_mdct_end(fb->mdct2048);
+ if (fb != NULL)
+ {
+ faad_mdct_end(fb->mdct256);
+ faad_mdct_end(fb->mdct2048);
#ifdef LD_DEC
- faad_mdct_end(fb->mdct1024);
+ faad_mdct_end(fb->mdct1024);
#endif
- if (fb) free(fb);
+ free(fb);
+ }
}
static INLINE void imdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
@@ -265,9 +268,7 @@ void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint16_t nshort = frame_len/8;
uint16_t nflat_ls = (nlong-nshort)/2;
- XINE_ASSERT(window_sequence != EIGHT_SHORT_SEQUENCE,
- "%window_sequence (%d) == EIGHT_SHORT_SEQUENCE (%d)",
- window_sequence, EIGHT_SHORT_SEQUENCE);
+ assert(window_sequence != EIGHT_SHORT_SEQUENCE);
windowed_buf = (real_t*)malloc(nlong*2*sizeof(real_t));
diff --git a/src/libfaad/fixed.h b/src/libfaad/fixed.h
index ae5e5cc4a..5fae855ab 100644
--- a/src/libfaad/fixed.h
+++ b/src/libfaad/fixed.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: fixed.h,v 1.1 2002/12/16 19:00:06 miguelfreitas Exp $
+** $Id: fixed.h,v 1.2 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __FIXED_H__
@@ -71,6 +71,38 @@ static INLINE MUL_R_C(real_t A, real_t B)
}
}
+#elif defined(__GNUC__) && defined (__arm__)
+
+/* taken from MAD */
+#define arm_mul(x, y, SCALEBITS) \
+ ({ uint32_t __hi; \
+ uint32_t __lo; \
+ uint32_t __result; \
+ asm ("smull %0, %1, %3, %4\n\t" \
+ "movs %0, %0, lsr %5\n\t" \
+ "adc %2, %0, %1, lsl %6" \
+ : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
+ : "%r" (x), "r" (y), \
+ "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \
+ : "cc"); \
+ __result; \
+ })
+
+static INLINE real_t MUL(real_t A, real_t B)
+{
+ return arm_mul( A, B, REAL_BITS);
+}
+
+static INLINE real_t MUL_C_C(real_t A, real_t B)
+{
+ return arm_mul( A, B, COEF_BITS);
+}
+
+static INLINE real_t MUL_R_C(real_t A, real_t B)
+{
+ return arm_mul( A, B, COEF_BITS);
+}
+
#else
/* multiply real with real */
diff --git a/src/libfaad/hcr.c b/src/libfaad/hcr.c
index d5652aa18..aa282f32d 100644
--- a/src/libfaad/hcr.c
+++ b/src/libfaad/hcr.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: hcr.c,v 1.1 2002/12/16 19:00:10 miguelfreitas Exp $
+** $Id: hcr.c,v 1.2 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -548,6 +548,10 @@ uint8_t reordered_spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile
} /* of sfb */
} /* of presort */
+ /* Avoid divide by zero */
+ if (numberOfSegments == 0)
+ return 10; /* this is not good... */
+
numberOfSets = NrCodeWords / numberOfSegments;
/* second step: decode nonPCWs */
diff --git a/src/libfaad/mdct.c b/src/libfaad/mdct.c
index 0f2e3bda7..7deb017cf 100644
--- a/src/libfaad/mdct.c
+++ b/src/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.4 2003/02/28 02:51:49 storri Exp $
+** $Id: mdct.c,v 1.5 2003/04/12 14:58:47 miguelfreitas Exp $
**/
/*
@@ -40,9 +40,9 @@
#include <stdlib.h>
#ifdef _WIN32_WCE
-#define XINE_ASSERT(x)
+#define assert(x)
#else
-#include "xineutils.h"
+#include <assert.h>
#endif
#include "cfft.h"
@@ -115,7 +115,7 @@ mdct_info *faad_mdct_init(uint16_t N)
mdct_info *mdct = (mdct_info*)malloc(sizeof(mdct_info));
- XINE_ASSERT( (N % 8 == 0), "?");
+ assert(N % 8 == 0);
mdct->N = N;
mdct->sincos = (complex_t*)malloc(N/4*sizeof(complex_t));
@@ -147,12 +147,15 @@ mdct_info *faad_mdct_init(uint16_t N)
void faad_mdct_end(mdct_info *mdct)
{
- cfftu(mdct->cfft);
+ if (mdct != NULL)
+ {
+ cfftu(mdct->cfft);
- if (mdct->Z1) free(mdct->Z1);
- if (mdct->sincos) free(mdct->sincos);
+ if (mdct->Z1) free(mdct->Z1);
+ if (mdct->sincos) free(mdct->sincos);
- if (mdct) free(mdct);
+ free(mdct);
+ }
}
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
diff --git a/src/libfaad/mp4.c b/src/libfaad/mp4.c
index a55c13e2b..1dfeb82f6 100644
--- a/src/libfaad/mp4.c
+++ b/src/libfaad/mp4.c
@@ -16,12 +16,14 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: mp4.c,v 1.3 2002/12/16 19:00:42 miguelfreitas Exp $
+** $Id: mp4.c,v 1.4 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
#include "structs.h"
+#include <stdlib.h>
+
#include "bits.h"
#include "mp4.h"
#include "data.h"
@@ -102,91 +104,74 @@ static uint8_t ObjectTypesTable[32] = {
/* Table 1.6.1 */
int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer,
uint32_t buffer_size,
- uint32_t *samplerate,
- uint8_t *channels,
- uint8_t *sf_index,
- uint8_t *object_type,
- uint8_t *aacSectionDataResilienceFlag,
- uint8_t *aacScalefactorDataResilienceFlag,
- uint8_t *aacSpectralDataResilienceFlag,
- uint8_t *frameLengthFlag)
+ mp4AudioSpecificConfig *mp4ASC)
{
bitfile ld;
- uint8_t ep_config = 0;
int8_t result = 0;
- uint8_t ObjectTypeIndex, SamplingFrequencyIndex, ChannelsConfiguration;
+
+ if (pBuffer == NULL)
+ return -7;
+ if (mp4ASC == NULL)
+ return -8;
+
+ memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig));
faad_initbits(&ld, pBuffer, buffer_size);
faad_byte_align(&ld);
- ObjectTypeIndex = (uint8_t)faad_getbits(&ld, 5
+ mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
- SamplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
+ mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
- ChannelsConfiguration = (uint8_t)faad_getbits(&ld, 4
+ mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4
DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
- *samplerate = sample_rates[SamplingFrequencyIndex];
+ mp4ASC->samplingFrequency = sample_rates[mp4ASC->samplingFrequencyIndex];
- *channels = ChannelsConfiguration;
-
- *sf_index = SamplingFrequencyIndex;
- *object_type = ObjectTypeIndex;
-
- if (ObjectTypesTable[ObjectTypeIndex] != 1)
+ if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1)
{
faad_endbits(&ld);
return -1;
}
- if (*samplerate == 0)
+ if (mp4ASC->samplingFrequency == 0)
{
faad_endbits(&ld);
return -2;
}
- if (ChannelsConfiguration > 7)
+ if (mp4ASC->channelsConfiguration > 7)
{
faad_endbits(&ld);
return -3;
}
/* get GASpecificConfig */
- if (ObjectTypeIndex == 1 || ObjectTypeIndex == 2 ||
- ObjectTypeIndex == 3 || ObjectTypeIndex == 4 ||
- ObjectTypeIndex == 6 || ObjectTypeIndex == 7)
+ if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 ||
+ mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 ||
+ mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7)
{
- result = GASpecificConfig(&ld, channels, ObjectTypeIndex,
-#ifdef ERROR_RESILIENCE
- aacSectionDataResilienceFlag,
- aacScalefactorDataResilienceFlag,
- aacSpectralDataResilienceFlag,
-#endif
- frameLengthFlag);
-#ifdef ERROR_RESILIENCE
- } else if (ObjectTypeIndex >= ER_OBJECT_START) { /* ER */
- result = GASpecificConfig(&ld, channels, ObjectTypeIndex,
+ result = GASpecificConfig(&ld, mp4ASC);
+
#ifdef ERROR_RESILIENCE
- aacSectionDataResilienceFlag,
- aacScalefactorDataResilienceFlag,
- aacSpectralDataResilienceFlag,
-#endif
- frameLengthFlag);
- ep_config = (uint8_t)faad_getbits(&ld, 2
+ } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */
+ result = GASpecificConfig(&ld, mp4ASC);
+ mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2
DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig"));
- if (ep_config != 0)
+ if (mp4ASC->epConfig != 0)
result = -5;
#endif
+
} else {
result = -4;
}
#ifdef SSR_DEC
/* shorter frames not allowed for SSR */
- if ((ObjectTypeIndex == 4) && *frameLengthFlag)
+ if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag)
return -6;
#endif
diff --git a/src/libfaad/mp4.h b/src/libfaad/mp4.h
index 71eae905b..e3885dd1b 100644
--- a/src/libfaad/mp4.h
+++ b/src/libfaad/mp4.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: mp4.h,v 1.2 2002/12/16 19:00:45 miguelfreitas Exp $
+** $Id: mp4.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __MP4_H__
@@ -30,14 +30,7 @@ extern "C" {
int8_t FAADAPI AudioSpecificConfig(uint8_t *pBuffer,
uint32_t buffer_size,
- uint32_t *samplerate,
- uint8_t *channels,
- uint8_t *sf_index,
- uint8_t *object_type,
- uint8_t *aacSectionDataResilienceFlag,
- uint8_t *aacScalefactorDataResilienceFlag,
- uint8_t *aacSpectralDataResilienceFlag,
- uint8_t *frameLengthFlag);
+ mp4AudioSpecificConfig *mp4ASC);
#ifdef __cplusplus
}
diff --git a/src/libfaad/output.c b/src/libfaad/output.c
index 21507e9ce..ee68e1960 100644
--- a/src/libfaad/output.c
+++ b/src/libfaad/output.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: output.c,v 1.2 2002/12/16 19:00:49 miguelfreitas Exp $
+** $Id: output.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -53,6 +53,7 @@ void* output_to_PCM(real_t **input, void *sample_buffer, uint8_t channels,
int16_t *short_sample_buffer = (int16_t*)sample_buffer;
int32_t *int_sample_buffer = (int32_t*)sample_buffer;
float32_t *float_sample_buffer = (float32_t*)sample_buffer;
+ double *double_sample_buffer = (double*)sample_buffer;
/* Copy output to a standard PCM buffer */
switch (format)
@@ -147,6 +148,19 @@ void* output_to_PCM(real_t **input, void *sample_buffer, uint8_t channels,
}
}
break;
+ case FAAD_FMT_DOUBLE:
+ for (ch = 0; ch < channels; ch++)
+ {
+ for(i = 0; i < frame_len; i++)
+ {
+ if (input[ch][i] > (1<<15)-1)
+ input[ch][i] = (1<<15)-1;
+ else if (input[ch][i] < -(1<<15))
+ input[ch][i] = -(1<<15);
+ double_sample_buffer[(i*channels)+ch] = (double)input[ch][i]*FLOAT_SCALE;
+ }
+ }
+ break;
}
return sample_buffer;
diff --git a/src/libfaad/pns.c b/src/libfaad/pns.c
index b14aba5d7..e7a0168e4 100644
--- a/src/libfaad/pns.c
+++ b/src/libfaad/pns.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: pns.c,v 1.2 2002/12/16 19:00:53 miguelfreitas Exp $
+** $Id: pns.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -193,22 +193,10 @@ void pns_decode(ic_stream *ics_left, ic_stream *ics_right,
{
if (is_noise(ics_right, g, sfb))
{
- if (ics_left->ms_mask_present == 1)
+ if (((ics_left->ms_mask_present == 1) &&
+ (ics_left->ms_used[g][sfb])) ||
+ (ics_left->ms_mask_present == 2))
{
- if (ics_left->ms_used[g][sfb])
- {
- uint16_t c;
-
- offs = ics_right->swb_offset[sfb];
- size = ics_right->swb_offset[sfb+1] - offs;
-
- for (c = 0; c < size; c++)
- {
- spec_right[(group*nshort) + offs + c] =
- spec_left[(group*nshort) + offs + c];
- }
- }
- } else if (ics_left->ms_mask_present == 2) {
uint16_t c;
offs = ics_right->swb_offset[sfb];
diff --git a/src/libfaad/pulse.c b/src/libfaad/pulse.c
index 024c473d9..d2a7c6ec2 100644
--- a/src/libfaad/pulse.c
+++ b/src/libfaad/pulse.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: pulse.c,v 1.2 2002/12/16 19:00:59 miguelfreitas Exp $
+** $Id: pulse.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -25,7 +25,7 @@
#include "syntax.h"
#include "pulse.h"
-void pulse_decode(ic_stream *ics, int16_t *spec_data)
+void pulse_decode(ic_stream *ics, int16_t *spec_data, uint16_t framelen)
{
uint8_t i;
uint16_t k;
@@ -35,6 +35,10 @@ void pulse_decode(ic_stream *ics, int16_t *spec_data)
for(i = 0; i <= pul->number_pulse; i++) {
k += pul->pulse_offset[i];
+
+ if (k >= framelen)
+ return; /* should not be possible */
+
if (spec_data[k] > 0)
spec_data[k] += pul->pulse_amp[i];
else
diff --git a/src/libfaad/pulse.h b/src/libfaad/pulse.h
index d0084ccc3..4ccd429b1 100644
--- a/src/libfaad/pulse.h
+++ b/src/libfaad/pulse.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: pulse.h,v 1.2 2002/12/16 19:01:00 miguelfreitas Exp $
+** $Id: pulse.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __PULSE_H__
@@ -26,7 +26,7 @@
extern "C" {
#endif
-void pulse_decode(ic_stream *ics, int16_t *spec_coef);
+void pulse_decode(ic_stream *ics, int16_t *spec_coef, uint16_t framelen);
#ifdef __cplusplus
}
diff --git a/src/libfaad/rvlc.c b/src/libfaad/rvlc.c
index 2194906d6..70dcf7c29 100644
--- a/src/libfaad/rvlc.c
+++ b/src/libfaad/rvlc.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: rvlc.c,v 1.1 2002/12/16 19:01:03 miguelfreitas Exp $
+** $Id: rvlc.c,v 1.2 2003/04/12 14:58:47 miguelfreitas Exp $
**/
/* RVLC scalefactor decoding
@@ -133,8 +133,10 @@ uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld)
if (rvlc_esc_buffer) free(rvlc_esc_buffer);
if (rvlc_sf_buffer) free(rvlc_sf_buffer);
- faad_endbits(&ld_rvlc_sf);
- faad_endbits(&ld_rvlc_esc);
+ if (ics->length_of_rvlc_sf > 0)
+ faad_endbits(&ld_rvlc_sf);
+ if (ics->sf_escapes_present)
+ faad_endbits(&ld_rvlc_esc);
return result;
}
@@ -487,9 +489,9 @@ static int8_t rvlc_huffman_esc(bitfile *ld,
i = h->len;
if (direction > 0)
- cw = faad_getbits(ld, i);
+ cw = faad_getbits(ld, i DEBUGVAR(1,0,""));
else
- cw = faad_getbits_rev(ld, i);
+ cw = faad_getbits_rev(ld, i DEBUGVAR(1,0,""));
while ((cw != h->cw)
&& (i < 21))
@@ -507,4 +509,4 @@ static int8_t rvlc_huffman_esc(bitfile *ld,
return h->index;
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/libfaad/specrec.c b/src/libfaad/specrec.c
index dbb4416d2..81904b3a5 100644
--- a/src/libfaad/specrec.c
+++ b/src/libfaad/specrec.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: specrec.c,v 1.2 2002/12/16 19:01:14 miguelfreitas Exp $
+** $Id: specrec.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
/*
@@ -73,7 +73,10 @@ uint8_t window_grouping_info(faacDecHandle hDecoder, ic_stream *ics)
ics->num_swb = num_swb_480_window[sf_index];
} else {
#endif
- ics->num_swb = num_swb_1024_window[sf_index];
+ if (hDecoder->frameLength == 1024)
+ ics->num_swb = num_swb_1024_window[sf_index];
+ else /* if (hDecoder->frameLength == 960) */
+ ics->num_swb = num_swb_960_window[sf_index];
#ifdef LD_DEC
}
#endif
@@ -253,39 +256,36 @@ void build_tables(real_t *pow2_table)
static INLINE real_t iquant(int16_t q)
{
- if (q > 0)
+ int16_t sgn = 1;
+
+ if (q == 0) return 0;
+
+ if (q < 0)
{
- if (q < IQ_TABLE_SIZE)
- return iq_table[q];
- else
- return iq_table[q>>3] * 16;
- } else if (q < 0) {
q = -q;
- if (q < IQ_TABLE_SIZE)
- return -iq_table[q];
- else
- return -iq_table[q>>3] * 16;
- } else {
- return 0;
+ sgn = -1;
}
+
+ if (q >= IQ_TABLE_SIZE)
+ return sgn * iq_table[q>>3] * 16;
+
+ return sgn * iq_table[q];
}
void inverse_quantization(real_t *x_invquant, int16_t *x_quant, uint16_t frame_len)
{
- int8_t i;
+ int16_t i;
int16_t *in_ptr = x_quant;
real_t *out_ptr = x_invquant;
- for(i = frame_len/8-1; i >= 0; --i)
+ for(i = frame_len/4-1; i >= 0; --i)
{
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
- *out_ptr++ = iquant(*in_ptr++);
+ out_ptr[0] = iquant(in_ptr[0]);
+ out_ptr[1] = iquant(in_ptr[1]);
+ out_ptr[2] = iquant(in_ptr[2]);
+ out_ptr[3] = iquant(in_ptr[3]);
+ out_ptr += 4;
+ in_ptr += 4;
}
}
diff --git a/src/libfaad/structs.h b/src/libfaad/structs.h
index 5a6e58d0a..8a857dae3 100644
--- a/src/libfaad/structs.h
+++ b/src/libfaad/structs.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: structs.h,v 1.1 2002/12/16 19:02:00 miguelfreitas Exp $
+** $Id: structs.h,v 1.2 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __STRUCTS_H__
@@ -280,6 +280,26 @@ typedef struct
ic_stream ics2;
} element; /* syntax element (SCE, CPE, LFE) */
+typedef struct mp4AudioSpecificConfig
+{
+ /* Audio Specific Info */
+ uint8_t objectTypeIndex;
+ uint8_t samplingFrequencyIndex;
+ uint32_t samplingFrequency;
+ uint8_t channelsConfiguration;
+
+ /* GA Specific Info */
+ uint8_t frameLengthFlag;
+ uint8_t dependsOnCoreCoder;
+ uint16_t coreCoderDelay;
+ uint8_t extensionFlag;
+ uint8_t aacSectionDataResilienceFlag;
+ uint8_t aacScalefactorDataResilienceFlag;
+ uint8_t aacSpectralDataResilienceFlag;
+ uint8_t epConfig;
+
+} mp4AudioSpecificConfig;
+
typedef struct faacDecConfiguration
{
uint8_t defObjectType;
@@ -293,6 +313,7 @@ typedef struct faacDecFrameInfo
uint32_t samples;
uint8_t channels;
uint8_t error;
+ uint32_t samplerate;
} faacDecFrameInfo;
typedef struct
diff --git a/src/libfaad/syntax.c b/src/libfaad/syntax.c
index 27c68029b..08b3e6747 100644
--- a/src/libfaad/syntax.c
+++ b/src/libfaad/syntax.c
@@ -16,15 +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: syntax.c,v 1.3 2002/12/16 19:02:04 miguelfreitas Exp $
+** $Id: syntax.c,v 1.4 2003/04/12 14:58:47 miguelfreitas Exp $
**/
/*
Reads the AAC bitstream as defined in 14496-3 (MPEG-4 Audio)
-
- (Note that there are some differences with 13818-7 (MPEG2), these
- are also read correctly when the MPEG ID is known (can be found in
- an ADTS header)).
*/
#include "common.h"
@@ -46,54 +42,76 @@
#include "rvlc.h"
#endif
+/* static declarations moved to avoid compiler warnings [MF] */
+/* static functions */
+static uint8_t single_lfe_channel_element(faacDecHandle hDecoder,
+ element *sce, bitfile *ld,
+ int16_t *spec_data);
+static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
+ bitfile *ld, int16_t *spec_data1,
+ int16_t *spec_data2);
+static uint16_t data_stream_element(bitfile *ld);
+static uint8_t program_config_element(program_config *pce, bitfile *ld);
+static uint8_t fill_element(bitfile *ld, drc_info *drc);
+static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
+ bitfile *ld, ic_stream *ics, uint8_t scal_flag,
+ int16_t *spec_data);
+static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
+ uint8_t common_window);
+static void section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
+static uint8_t scale_factor_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
+static void gain_control_data(bitfile *ld, ic_stream *ics);
+static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
+ int16_t *spectral_data);
+static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count);
+static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
+static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
+static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
+static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);
+static void adts_variable_header(adts_header *adts, bitfile *ld);
+static void adts_error_check(adts_header *adts, bitfile *ld);
+static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
+static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
+
/* Table 4.4.1 */
-int8_t GASpecificConfig(bitfile *ld, uint8_t *channelConfiguration,
- uint8_t object_type,
-#ifdef ERROR_RESILIENCE
- uint8_t *aacSectionDataResilienceFlag,
- uint8_t *aacScalefactorDataResilienceFlag,
- uint8_t *aacSpectralDataResilienceFlag,
-#endif
- uint8_t *frameLengthFlag)
+int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC)
{
- uint8_t dependsOnCoreCoder, extensionFlag;
- uint16_t coreCoderDelay;
program_config pce;
/* 1024 or 960 */
- *frameLengthFlag = faad_get1bit(ld
+ mp4ASC->frameLengthFlag = faad_get1bit(ld
DEBUGVAR(1,138,"GASpecificConfig(): FrameLengthFlag"));
- dependsOnCoreCoder = faad_get1bit(ld
+ mp4ASC->dependsOnCoreCoder = faad_get1bit(ld
DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder"));
- if (dependsOnCoreCoder == 1)
+ if (mp4ASC->dependsOnCoreCoder == 1)
{
- coreCoderDelay = (uint16_t)faad_getbits(ld, 14
+ mp4ASC->coreCoderDelay = (uint16_t)faad_getbits(ld, 14
DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay"));
}
- extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag"));
- if (*channelConfiguration == 0)
+ mp4ASC->extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag"));
+ if (mp4ASC->channelsConfiguration == 0)
{
program_config_element(&pce, ld);
- *channelConfiguration = pce.channels;
+ mp4ASC->channelsConfiguration = pce.channels;
if (pce.num_valid_cc_elements)
return -3;
}
#ifdef ERROR_RESILIENCE
- if (extensionFlag == 1)
+ if (mp4ASC->extensionFlag == 1)
{
/* Error resilience not supported yet */
- if (object_type >= ER_OBJECT_START)
+ if (mp4ASC->objectTypeIndex >= ER_OBJECT_START)
{
- *aacSectionDataResilienceFlag = faad_get1bit(ld
+ mp4ASC->aacSectionDataResilienceFlag = faad_get1bit(ld
DEBUGVAR(1,144,"GASpecificConfig(): aacSectionDataResilienceFlag"));
- *aacScalefactorDataResilienceFlag = faad_get1bit(ld
+ mp4ASC->aacScalefactorDataResilienceFlag = faad_get1bit(ld
DEBUGVAR(1,145,"GASpecificConfig(): aacScalefactorDataResilienceFlag"));
- *aacSpectralDataResilienceFlag = faad_get1bit(ld
+ mp4ASC->aacSpectralDataResilienceFlag = faad_get1bit(ld
DEBUGVAR(1,146,"GASpecificConfig(): aacSpectralDataResilienceFlag"));
/* 1 bit: extensionFlag3 */
@@ -449,6 +467,9 @@ element **raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
}
#endif
+ /* new in corrigendum 14496-3:2002 */
+ faad_byte_align(ld);
+
return elements;
}
@@ -515,7 +536,7 @@ static uint8_t single_lfe_channel_element(faacDecHandle hDecoder,
if (ics->pulse_data_present)
{
if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
- pulse_decode(ics, spec_data);
+ pulse_decode(ics, spec_data, hDecoder->frameLength);
else
return 2; /* pulse coding not allowed for short blocks */
}
@@ -614,7 +635,6 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
if ((result = faad_check_CRC( ld )) > 0)
{
- printf("CRC wrong!\n");
return result;
}
/* error resilient spectral data decoding */
@@ -626,14 +646,14 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
if (ics1->pulse_data_present)
{
if (ics1->window_sequence != EIGHT_SHORT_SEQUENCE)
- pulse_decode(ics1, spec_data1);
+ pulse_decode(ics1, spec_data1, hDecoder->frameLength);
else
return 2; /* pulse coding not allowed for short blocks */
}
if (ics2->pulse_data_present)
{
if (ics2->window_sequence != EIGHT_SHORT_SEQUENCE)
- pulse_decode(ics2, spec_data2);
+ pulse_decode(ics2, spec_data2, hDecoder->frameLength);
else
return 2; /* pulse coding not allowed for short blocks */
}
@@ -648,6 +668,8 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
uint8_t common_window)
{
+ uint8_t retval = 0;
+
/* ics->ics_reserved_bit = */ faad_get1bit(ld
DEBUGVAR(1,43,"ics_info(): ics_reserved_bit"));
ics->window_sequence = (uint8_t)faad_getbits(ld, 2
@@ -664,7 +686,18 @@ static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
} else {
ics->max_sfb = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,48,"ics_info(): max_sfb (long)"));
+ }
+
+ /* get the grouping information */
+ retval = window_grouping_info(hDecoder, ics);
+ /* should be an error */
+ /* check the range of max_sfb */
+ if (ics->max_sfb > ics->num_swb)
+ ics->max_sfb = ics->num_swb;
+
+ if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
+ {
if ((ics->predictor_data_present = faad_get1bit(ld
DEBUGVAR(1,49,"ics_info(): predictor_data_present"))) & 1)
{
@@ -720,12 +753,11 @@ static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
}
}
- /* get the grouping information */
- return window_grouping_info(hDecoder, ics);
+ return retval;
}
/* Table 4.4.7 */
-static void pulse_data(pulse_info *pul, bitfile *ld)
+static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
{
uint8_t i;
@@ -734,6 +766,10 @@ static void pulse_data(pulse_info *pul, bitfile *ld)
pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb"));
+ /* check the range of pulse_start_sfb */
+ if (pul->pulse_start_sfb > ics->num_swb)
+ pul->pulse_start_sfb = ics->num_swb;
+
for (i = 0; i < pul->number_pulse+1; i++)
{
pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5
@@ -919,7 +955,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
if ((ics->pulse_data_present = faad_get1bit(ld
DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
{
- pulse_data(&(ics->pul), ld);
+ pulse_data(ics, &(ics->pul), ld);
}
/* get tns data */
@@ -950,7 +986,9 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
#ifdef ERROR_RESILIENCE
if (hDecoder->aacSpectralDataResilienceFlag)
{
-#if 0
+ ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
+ DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data"));
+
if (hDecoder->channelConfiguration == 2)
{
if (ics->length_of_reordered_spectral_data > 6144)
@@ -959,10 +997,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
if (ics->length_of_reordered_spectral_data > 12288)
ics->length_of_reordered_spectral_data = 12288;
}
-#endif
- ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
- DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data"));
- /* TODO: test for >6144/12288, see page 143 */
+
ics->length_of_longest_codeword = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,148,"individual_channel_stream(): length_of_longest_codeword"));
if (ics->length_of_longest_codeword >= 49)
@@ -1009,7 +1044,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
if (ics->pulse_data_present)
{
if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
- pulse_decode(ics, spec_data);
+ pulse_decode(ics, spec_data, hDecoder->frameLength);
else
return 2; /* pulse coding not allowed for short blocks */
}
@@ -1269,10 +1304,6 @@ static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld)
#ifdef LTP_DEC
/* Table 4.4.28 */
-/*
- The limit MAX_LTP_SFB is not defined in 14496-3, this is a bug in the document
- and will be corrected in one of the corrigenda.
-*/
static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld)
{
uint8_t sfb, w;
@@ -1389,7 +1420,10 @@ static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld
/* Table 4.4.30 */
static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count)
{
- uint16_t i, n;
+ uint16_t i, n, dataElementLength;
+ uint8_t dataElementLengthPart;
+ uint8_t align = 4, data_element_version, loopCounter;
+
uint8_t extension_type = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,87,"extension_payload(): extension_type"));
@@ -1408,13 +1442,38 @@ static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count)
DEBUGVAR(1,88,"extension_payload(): fill_byte")); /* must be ‘10100101’ */
}
return count;
+ case EXT_DATA_ELEMENT:
+ data_element_version = faad_getbits(ld, 4
+ DEBUGVAR(1,400,"extension_payload(): data_element_version"));
+ switch (data_element_version)
+ {
+ case ANC_DATA:
+ loopCounter = 0;
+ dataElementLength = 0;
+ do {
+ dataElementLengthPart = faad_getbits(ld, 8
+ DEBUGVAR(1,401,"extension_payload(): dataElementLengthPart"));
+ dataElementLength += dataElementLengthPart;
+ loopCounter++;
+ } while (dataElementLengthPart == 255);
+
+ for (i = 0; i < dataElementLength; i++)
+ {
+ /* data_element_byte[i] = */ faad_getbits(ld, 8
+ DEBUGVAR(1,402,"extension_payload(): data_element_byte"));
+ return (dataElementLength+loopCounter+1);
+ }
+ default:
+ align = 0;
+ }
+ case EXT_FIL:
default:
- faad_getbits(ld, 4
- DEBUGVAR(1,137,"extension_payload(): fill_nibble"));
+ faad_getbits(ld, align
+ DEBUGVAR(1,88,"extension_payload(): fill_nibble"));
for (i = 0; i < count-1; i++)
{
/* other_bits[i] = */ faad_getbits(ld, 8
- DEBUGVAR(1,89,"extension_payload(): fill_byte"));
+ DEBUGVAR(1,89,"extension_payload(): fill_bit"));
}
return count;
}
@@ -1550,16 +1609,16 @@ void get_adif_header(adif_header *adif, bitfile *ld)
adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,116,"get_adif_header(): num_program_config_elements"));
- for (i = 0; i < adif->num_program_config_elements + 1; i++)
+ if(adif->bitstream_type == 0)
{
- if(adif->bitstream_type == 0)
- {
- adif->adif_buffer_fullness = faad_getbits(ld, 20
- DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness"));
- } else {
- adif->adif_buffer_fullness = 0;
- }
+ adif->adif_buffer_fullness = faad_getbits(ld, 20
+ DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness"));
+ } else {
+ adif->adif_buffer_fullness = 0;
+ }
+ for (i = 0; i < adif->num_program_config_elements + 1; i++)
+ {
program_config_element(&adif->pce, ld);
}
}
@@ -1618,11 +1677,13 @@ static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld)
DEBUGVAR(1,126,"adts_fixed_header(): original"));
adts->home = faad_get1bit(ld
DEBUGVAR(1,127,"adts_fixed_header(): home"));
+/* Removed in corrigendum 14496-3:2002
if (adts->id == 0)
{
adts->emphasis = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,128,"adts_fixed_header(): emphasis"));
}
+*/
return 0;
}
diff --git a/src/libfaad/syntax.h b/src/libfaad/syntax.h
index cb62b0ed1..b8c5b9a09 100644
--- a/src/libfaad/syntax.h
+++ b/src/libfaad/syntax.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: syntax.h,v 1.4 2002/12/16 19:02:08 miguelfreitas Exp $
+** $Id: syntax.h,v 1.5 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __SYNTAX_H__
@@ -49,8 +49,11 @@ extern "C" {
#define LEN_TAG 4
#define LEN_BYTE 8
-#define EXT_FILL_DATA 1
+#define EXT_FIL 0
+#define EXT_FILL_DATA 1
+#define EXT_DATA_ELEMENT 2
#define EXT_DYNAMIC_RANGE 11
+#define ANC_DATA 0
/* Syntax elements */
#define ID_SCE 0x0
@@ -78,52 +81,18 @@ extern "C" {
#define INTENSITY_HCB 15
-int8_t GASpecificConfig(bitfile *ld, uint8_t *channelConfiguration,
- uint8_t object_type,
-#ifdef ERROR_RESILIENCE
- uint8_t *aacSectionDataResilienceFlag,
- uint8_t *aacScalefactorDataResilienceFlag,
- uint8_t *aacSpectralDataResilienceFlag,
-#endif
- uint8_t *frameLengthFlag);
+int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC);
uint8_t adts_frame(adts_header *adts, bitfile *ld);
void get_adif_header(adif_header *adif, bitfile *ld);
-/* static functions */
-static uint8_t single_lfe_channel_element(faacDecHandle hDecoder,
- element *sce, bitfile *ld,
- int16_t *spec_data);
-static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
- bitfile *ld, int16_t *spec_data1,
- int16_t *spec_data2);
-static uint16_t data_stream_element(bitfile *ld);
-static uint8_t program_config_element(program_config *pce, bitfile *ld);
-static uint8_t fill_element(bitfile *ld, drc_info *drc);
-static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele,
- bitfile *ld, ic_stream *ics, uint8_t scal_flag,
- int16_t *spec_data);
-static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
- uint8_t common_window);
-static void section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
-static uint8_t scale_factor_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
-static void gain_control_data(bitfile *ld, ic_stream *ics);
-static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
- int16_t *spectral_data);
-static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count);
+/* static declarations moved to avoid compiler warnings [MF] */
+
#ifdef ERROR_RESILIENCE
uint8_t reordered_spectral_data(faacDecHandle hDecoder, ic_stream *ics,
bitfile *ld, int16_t *spectral_data);
#endif
-static void pulse_data(pulse_info *pul, bitfile *ld);
-static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
-static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
-static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);
-static void adts_variable_header(adts_header *adts, bitfile *ld);
-static void adts_error_check(adts_header *adts, bitfile *ld);
-static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
-static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
#ifdef __cplusplus
diff --git a/src/libfaad/tns.c b/src/libfaad/tns.c
index d06fb5774..6609071ae 100644
--- a/src/libfaad/tns.c
+++ b/src/libfaad/tns.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: tns.c,v 1.2 2002/12/16 19:02:10 miguelfreitas Exp $
+** $Id: tns.c,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#include "common.h"
@@ -111,20 +111,15 @@ void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
{
top = bottom;
bottom = max(top - tns->length[w][f], 0);
- tns_order = min(tns->order[w][f], tns_max_order(ics, sr_index,
- object_type));
+ tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
if (!tns_order)
continue;
tns_decode_coef(tns_order, tns->coef_res[w]+3,
tns->coef_compress[w][f], tns->coef[w][f], lpc);
- start = ics->swb_offset[min(bottom,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
- end = ics->swb_offset[min(top,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
+ start = ics->swb_offset[min(bottom, ics->max_sfb)];
+ end = ics->swb_offset[min(top, ics->max_sfb)];
if ((size = end - start) <= 0)
continue;
@@ -163,20 +158,15 @@ void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
{
top = bottom;
bottom = max(top - tns->length[w][f], 0);
- tns_order = min(tns->order[w][f], tns_max_order(ics, sr_index,
- object_type));
+ tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
if (!tns_order)
continue;
tns_decode_coef(tns_order, tns->coef_res[w]+3,
tns->coef_compress[w][f], tns->coef[w][f], lpc);
- start = ics->swb_offset[min(bottom,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
- end = ics->swb_offset[min(top,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
+ start = ics->swb_offset[min(bottom, ics->max_sfb)];
+ end = ics->swb_offset[min(top, ics->max_sfb)];
if ((size = end - start) <= 0)
continue;
@@ -305,83 +295,3 @@ static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *l
spectrum += inc;
}
}
-
-static uint8_t tns_max_bands_table[12][6] =
-{
- /* entry for each sampling rate
- * 1 Main/LC long window
- * 2 Main/LC short window
- * 3 SSR long window
- * 4 SSR short window
- * 5 LD 512 window
- * 6 LD 480 window
- */
- { 31, 9, 28, 7, 0, 0 }, /* 96000 */
- { 31, 9, 28, 7, 0, 0 }, /* 88200 */
- { 34, 10, 27, 7, 0, 0 }, /* 64000 */
- { 40, 14, 26, 6, 31, 31 }, /* 48000 */
- { 42, 14, 26, 6, 32, 32 }, /* 44100 */
- { 51, 14, 26, 6, 37, 37 }, /* 32000 */
- { 46, 14, 29, 7, 31, 30 }, /* 24000 */
- { 46, 14, 29, 7, 31, 30 }, /* 22050 */
- { 42, 14, 23, 8, 0, 0 }, /* 16000 */
- { 42, 14, 23, 8, 0, 0 }, /* 12000 */
- { 42, 14, 23, 8, 0, 0 }, /* 11025 */
- { 39, 14, 19, 7, 0, 0 }, /* 8000 */
-};
-
-static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type, uint16_t frame_len)
-{
- uint8_t i;
-
- i = (ics->window_sequence == EIGHT_SHORT_SEQUENCE) ? 1 : 0;
-#ifdef LD_DEC
- if (object_type == LD)
- {
- if (frame_len == 512)
- i = 4;
- else
- i = 5;
- }
-#endif
-
- return tns_max_bands_table[sr_index][i];
-}
-
-static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type)
-{
- /* Correction in 14496-3 Cor. 1
- Works like MPEG2-AAC (13818-7) now
-
- For other object types (scalable) the following goes for tns max order
- for long windows:
- if (sr_index <= 5)
- return 12;
- else
- return 20;
- */
- if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
- {
- switch (object_type)
- {
- case MAIN:
- case LTP:
- case ER_LTP:
-#ifdef LD_DEC
- case LD:
-#endif
- return 20;
- case LC:
- case ER_LC:
- case DRM_ER_LC:
- case SSR:
- return 12;
- }
- } else {
- return 7;
- }
-
- return 0;
-}
diff --git a/src/libfaad/tns.h b/src/libfaad/tns.h
index d9a904511..37f9c9a9d 100644
--- a/src/libfaad/tns.h
+++ b/src/libfaad/tns.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: tns.h,v 1.2 2002/12/16 19:02:12 miguelfreitas Exp $
+** $Id: tns.h,v 1.3 2003/04/12 14:58:47 miguelfreitas Exp $
**/
#ifndef __TNS_H__
@@ -41,10 +41,6 @@ static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *l
uint8_t order);
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
uint8_t order);
-static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index, uint8_t object_type,
- uint16_t frame_len);
-static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type);
#ifdef __cplusplus