diff options
-rw-r--r-- | src/libfaad/common.h | 17 | ||||
-rw-r--r-- | src/libfaad/output.c | 56 | ||||
-rw-r--r-- | src/libfaad/ps_dec.c | 10 | ||||
-rw-r--r-- | src/libfaad/sbr_dec.c | 6 | ||||
-rw-r--r-- | src/libfaad/specrec.c | 57 |
5 files changed, 86 insertions, 60 deletions
diff --git a/src/libfaad/common.h b/src/libfaad/common.h index 5da3661bb..47832e648 100644 --- a/src/libfaad/common.h +++ b/src/libfaad/common.h @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: common.h,v 1.16 2005/10/30 01:21:53 tmmm Exp $ +** $Id: common.h,v 1.17 2006/06/17 20:43:57 dgp85 Exp $ **/ #ifndef __COMMON_H__ @@ -32,10 +32,12 @@ extern "C" { #endif -#ifdef HAVE_CONFIG_H -# include "../config.h" +#ifdef __CYGWIN__ +#define __STRICT_ANSI__ #endif +#include "../config.h" + #define INLINE __inline #if 0 //defined(_WIN32) && !defined(_WIN32_WCE) #define ALIGN __declspec(align(16)) @@ -61,7 +63,7 @@ extern "C" { /* Use if target platform has address generators with autoincrement */ //#define PREFER_POINTERS -#ifdef _WIN32_WCE +#if defined(_WIN32_WCE) || defined(__arm__) #define FIXED_POINT #endif @@ -117,6 +119,9 @@ extern "C" { # ifdef MAIN_DEC # undef MAIN_DEC # endif +# ifdef SBR_DEC +# undef SBR_DEC +# endif #endif // FIXED_POINT #ifdef DRM @@ -326,6 +331,8 @@ char *strchr(), *strrchr(); #else +#include <math.h> + #ifdef HAVE_LRINTF # define HAS_LRINTF # define _ISOC9X_SOURCE 1 @@ -334,8 +341,6 @@ char *strchr(), *strrchr(); # define __USE_ISOC99 1 #endif - #include <math.h> - #ifdef HAVE_SINF # define sin sinf #error diff --git a/src/libfaad/output.c b/src/libfaad/output.c index 8a005c87e..cf02505c6 100644 --- a/src/libfaad/output.c +++ b/src/libfaad/output.c @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: output.c,v 1.7 2005/10/29 23:57:07 tmmm Exp $ +** $Id: output.c,v 1.8 2006/06/17 20:43:57 dgp85 Exp $ **/ #include "common.h" @@ -463,7 +463,7 @@ static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample } } -void* output_to_PCM(NeAACDecHandle hDecoder, +static void* output_to_PCM_orig(NeAACDecHandle hDecoder, real_t **input, void *sample_buffer, uint8_t channels, uint16_t frame_len, uint8_t format) { @@ -554,4 +554,56 @@ void* output_to_PCM(NeAACDecHandle hDecoder, return sample_buffer; } +void *output_to_PCM(NeAACDecHandle hDecoder, + real_t **input, void *sample_buffer, uint8_t channels, + uint16_t frame_len, uint8_t format) +{ + int ch, i; + int16_t *short_sample_buffer; + real_t *ch0, *ch1, *ch2, *ch3, *ch4; + + if (format != FAAD_FMT_16BIT) + return output_to_PCM_orig(hDecoder, input, sample_buffer, channels, frame_len, format); + + short_sample_buffer = (int16_t *)sample_buffer; + ch0 = input[hDecoder->internal_channel[0]]; + ch1 = input[hDecoder->internal_channel[1]]; + ch2 = input[hDecoder->internal_channel[2]]; + ch3 = input[hDecoder->internal_channel[3]]; + ch4 = input[hDecoder->internal_channel[4]]; + + if (hDecoder->downMatrix) + { + for (i = 0; i < frame_len; ++i) + { + int32_t tmp = (ch1[i] + ((ch0[i] + ch3[i]) >> 1) + ((ch0[i] + ch3[i]) >> 2) + (1 << (REAL_BITS))) >> (REAL_BITS + 1); + if ((tmp + 0x8000) & ~0xffff) + tmp = ~(tmp >> 31) - 0x8000; + short_sample_buffer[0] = tmp; + tmp = (ch2[i] + ((ch0[i] + ch4[i]) >> 1) + ((ch0[i] + ch4[i]) >> 2) + (1 << (REAL_BITS))) >> (REAL_BITS + 1); + if ((tmp + 0x8000) & ~0xffff) + tmp = ~(tmp >> 31) - 0x8000; + short_sample_buffer[1] = tmp; + short_sample_buffer += channels; + } + return sample_buffer; + } + + /* Copy output to a standard PCM buffer */ + for (i = 0; i < frame_len; ++i) + { + for (ch = 0; ch < channels; ++ch) + { + int32 tmp = input[hDecoder->internal_channel[ch]][i]; + tmp += (1 << (REAL_BITS - 1)); + tmp >>= REAL_BITS; + if ((tmp + 0x8000) & ~0xffff) + tmp = ~(tmp >> 31) - 0x8000; + *(short_sample_buffer++) = tmp; + } + } + + return sample_buffer; +} + #endif diff --git a/src/libfaad/ps_dec.c b/src/libfaad/ps_dec.c index 1ebfa6a85..3d65986b4 100644 --- a/src/libfaad/ps_dec.c +++ b/src/libfaad/ps_dec.c @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: ps_dec.c,v 1.1 2005/10/30 00:50:19 tmmm Exp $ +** $Id: ps_dec.c,v 1.2 2006/06/17 20:43:57 dgp85 Exp $ **/ #include "common.h" @@ -159,7 +159,7 @@ typedef struct /* static function declarations */ static void ps_data_decode(ps_info *ps); -static hyb_info *hybrid_init(); +static hyb_info *hybrid_init(void); static void channel_filter2(hyb_info *hyb, uint8_t frame_len, const real_t *filter, qmf_t *buffer, qmf_t **X_hybrid); static void INLINE DCT3_4_unscaled(real_t *y, real_t *x); @@ -189,7 +189,7 @@ static void ps_mix_phase(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64 /* */ -static hyb_info *hybrid_init() +static hyb_info *hybrid_init(void) { uint8_t i; @@ -1935,8 +1935,8 @@ ps_info *ps_init(uint8_t sr_index) /* main Parametric Stereo decoding function */ uint8_t ps_decode(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64]) { - qmf_t X_hybrid_left[32][32] = {{0}}; - qmf_t X_hybrid_right[32][32] = {{0}}; + qmf_t X_hybrid_left[32][32] = {{{0}}}; + qmf_t X_hybrid_right[32][32] = {{{0}}}; /* delta decoding of the bitstream data */ ps_data_decode(ps); diff --git a/src/libfaad/sbr_dec.c b/src/libfaad/sbr_dec.c index dba6a4fca..24c1f5031 100644 --- a/src/libfaad/sbr_dec.c +++ b/src/libfaad/sbr_dec.c @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: sbr_dec.c,v 1.8 2005/10/29 23:57:07 tmmm Exp $ +** $Id: sbr_dec.c,v 1.9 2006/06/17 20:43:57 dgp85 Exp $ **/ @@ -526,8 +526,8 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ uint8_t l, k; uint8_t dont_process = 0; uint8_t ret = 0; - ALIGN qmf_t X_left[38][64] = {{0}}; - ALIGN qmf_t X_right[38][64] = {{0}}; /* must set this to 0 */ + ALIGN qmf_t X_left[38][64] = {{{0}}}; + ALIGN qmf_t X_right[38][64] = {{{0}}}; /* must set this to 0 */ if (sbr == NULL) return 20; diff --git a/src/libfaad/specrec.c b/src/libfaad/specrec.c index 9ecdd7949..fd4b0653c 100644 --- a/src/libfaad/specrec.c +++ b/src/libfaad/specrec.c @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: specrec.c,v 1.9 2005/10/29 23:57:07 tmmm Exp $ +** $Id: specrec.c,v 1.10 2006/06/17 20:43:57 dgp85 Exp $ **/ /* @@ -673,29 +673,19 @@ static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel, /* MAIN object type prediction */ if (hDecoder->object_type == MAIN) { - /* allocate the state only when needed */ - if (hDecoder->pred_stat[channel] == NULL) - { - hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); + hDecoder->pred_stat[channel] = (pred_state*)realloc(hDecoder->pred_stat[channel], hDecoder->frameLength * sizeof(pred_state)); reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength); - } } #endif #ifdef LTP_DEC if (is_ltp_ot(hDecoder->object_type)) { - /* allocate the state only when needed */ - if (hDecoder->lt_pred_stat[channel] == NULL) - { - hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); + hDecoder->lt_pred_stat[channel] = (int16_t*)realloc(hDecoder->lt_pred_stat[channel], hDecoder->frameLength*4 * sizeof(int16_t)); memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); - } } #endif - if (hDecoder->time_out[channel] == NULL) - { mul = 1; #ifdef SBR_DEC hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; @@ -706,41 +696,28 @@ static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel, hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; } #endif - hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); + hDecoder->time_out[channel] = (real_t*)realloc(hDecoder->time_out[channel], mul*hDecoder->frameLength*sizeof(real_t)); memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); - } #if (defined(PS_DEC) || defined(DRM_PS)) if (output_channels == 2) { - if (hDecoder->time_out[channel+1] == NULL) - { - hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); + hDecoder->time_out[channel+1] = (real_t*)realloc(hDecoder->time_out[channel+1], mul*hDecoder->frameLength*sizeof(real_t)); memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t)); - } } #endif - if (hDecoder->fb_intermed[channel] == NULL) - { - hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); + hDecoder->fb_intermed[channel] = (real_t*)realloc(hDecoder->fb_intermed[channel], hDecoder->frameLength*sizeof(real_t)); memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t)); - } #ifdef SSR_DEC if (hDecoder->object_type == SSR) { - if (hDecoder->ssr_overlap[channel] == NULL) - { - hDecoder->ssr_overlap[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); - memset(hDecoder->ssr_overlap[channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); - } - if (hDecoder->prev_fmd[channel] == NULL) - { uint16_t k; - hDecoder->prev_fmd[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); + hDecoder->ssr_overlap[channel] = (real_t*)realloc(hDecoder->ssr_overlap[channel], 2*hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->ssr_overlap[channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); + hDecoder->prev_fmd[channel] = (real_t*)realloc(hDecoder->prev_fmd[channel], 2*hDecoder->frameLength*sizeof(real_t)); for (k = 0; k < 2*hDecoder->frameLength; k++) hDecoder->prev_fmd[channel][k] = REAL_CONST(-1); - } } #endif @@ -865,22 +842,14 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics, /* always allocate 2 channels, PS can always "suddenly" turn up */ #if (defined(PS_DEC) || defined(DRM_PS)) - output_channels = 2; + output_channels = hDecoder->ps_used[hDecoder->fr_ch_ele] ? 2 : 1; #else output_channels = 1; #endif - if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) + if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] < output_channels) { - /* element_output_channels not set yet */ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels; - } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) { - /* element inconsistency */ - return 21; - } - - if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) - { retval = allocate_single_channel(hDecoder, sce->channel, output_channels); if (retval > 0) return retval; @@ -1026,11 +995,10 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics, { return 23; } -#endif /* copy L to R when no PS is used */ #if (defined(PS_DEC) || defined(DRM_PS)) - if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0)) + if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0) && (output_channels == 2)) { uint8_t ele = hDecoder->fr_ch_ele; uint8_t ch = sce->channel; @@ -1040,6 +1008,7 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics, memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size); } #endif +#endif return 0; } |