diff options
author | James Stembridge <jstembridge@users.sourceforge.net> | 2004-01-26 22:34:10 +0000 |
---|---|---|
committer | James Stembridge <jstembridge@users.sourceforge.net> | 2004-01-26 22:34:10 +0000 |
commit | 925b8c0c8c8d5641ec7865d102fc4a813a0940c4 (patch) | |
tree | 41b9798a788990135ae2876c426d5b88428999d8 /src/libfaad/specrec.c | |
parent | 229558581183265e40767066db5b6aa99c8818b1 (diff) | |
download | xine-lib-925b8c0c8c8d5641ec7865d102fc4a813a0940c4.tar.gz xine-lib-925b8c0c8c8d5641ec7865d102fc4a813a0940c4.tar.bz2 |
Sync with libfaad CVS
CVS patchset: 6071
CVS date: 2004/01/26 22:34:10
Diffstat (limited to 'src/libfaad/specrec.c')
-rw-r--r-- | src/libfaad/specrec.c | 148 |
1 files changed, 129 insertions, 19 deletions
diff --git a/src/libfaad/specrec.c b/src/libfaad/specrec.c index 588d79656..729a80193 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.5 2004/01/11 15:44:05 mroi Exp $ +** $Id: specrec.c,v 1.6 2004/01/26 22:34:11 jstembridge Exp $ **/ /* @@ -44,6 +44,7 @@ #include "is.h" #include "pns.h" #include "tns.h" +#include "drc.h" #include "lt_predict.h" #include "ic_predict.h" #ifdef SSR_DEC @@ -587,8 +588,17 @@ void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, { top = ics->sect_sfb_offset[g][sfb+1]; - exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; - frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; + /* this could be scalefactor for IS or PNS, those can be negative or bigger then 255 */ + /* just ignore them */ + if (ics->scale_factors[g][sfb] < 0 || ics->scale_factors[g][sfb] > 255) + { + exp = 0; + frac = 0; + } else { + /* ics->scale_factors[g][sfb] must be between 0 and 255 */ + exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; + frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; + } #ifdef FIXED_POINT exp -= 25; @@ -681,7 +691,7 @@ void apply_scalefactors_sse(faacDecHandle hDecoder, ic_stream *ics, uint8_t reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, element *sce, int16_t *spec_data) { - uint8_t retval; + uint8_t retval, mul; ALIGN real_t spec_coef[1024]; #ifdef PROFILE @@ -776,10 +786,27 @@ uint8_t reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, drc_decode(hDecoder->drc, spec_coef); } + if (hDecoder->time_out[sce->channel] == NULL) { - hDecoder->time_out[sce->channel] = (real_t*)faad_malloc(hDecoder->frameLength*2*sizeof(real_t)); - memset(hDecoder->time_out[sce->channel], 0, hDecoder->frameLength*2*sizeof(real_t)); + mul = 1; +#ifdef SBR_DEC + hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; + if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + { + /* SBR requires 2 times as much output data */ + mul = 2; + hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; + } +#endif + hDecoder->time_out[sce->channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->time_out[sce->channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); + } + + if (hDecoder->fb_intermed[sce->channel] == NULL) + { + hDecoder->fb_intermed[sce->channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->fb_intermed[sce->channel], 0, hDecoder->frameLength*sizeof(real_t)); } /* filter bank */ @@ -794,7 +821,8 @@ uint8_t reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, #else ifilter_bank(hDecoder->fb, ics->window_sequence, ics->window_shape, hDecoder->window_shape_prev[sce->channel], spec_coef, - hDecoder->time_out[sce->channel], hDecoder->object_type, hDecoder->frameLength); + hDecoder->time_out[sce->channel], hDecoder->fb_intermed[sce->channel], + hDecoder->object_type, hDecoder->frameLength); #endif #ifdef SSR_DEC } else { @@ -825,7 +853,36 @@ uint8_t reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, if (is_ltp_ot(hDecoder->object_type)) { lt_update_state(hDecoder->lt_pred_stat[sce->channel], hDecoder->time_out[sce->channel], - hDecoder->time_out[sce->channel]+hDecoder->frameLength, hDecoder->frameLength, hDecoder->object_type); + hDecoder->fb_intermed[sce->channel], hDecoder->frameLength, hDecoder->object_type); + } +#endif + +#ifdef SBR_DEC + if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) + { + uint8_t ele = hDecoder->fr_ch_ele; + uint8_t ch = sce->channel; + + /* following case can happen when forceUpSampling == 1 */ + if (hDecoder->sbr[ele] == NULL) + { + hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, + sce->ele_id, 2*get_sample_rate(hDecoder->sf_index) +#ifdef DRM + , 0 +#endif + ); + } + + retval = sbrDecodeSingleFrame(hDecoder->sbr[ele], hDecoder->time_out[ch], + hDecoder->postSeekResetFlag, hDecoder->forceUpSampling); + if (retval > 0) + return retval; + } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) + { + return 23; } #endif @@ -835,7 +892,7 @@ uint8_t reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, uint8_t reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, element *cpe, int16_t *spec_data1, int16_t *spec_data2) { - uint8_t retval; + uint8_t retval, mul; ALIGN real_t spec_coef1[1024]; ALIGN real_t spec_coef2[1024]; @@ -923,7 +980,7 @@ uint8_t reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_str if (is_ltp_ot(hDecoder->object_type)) { ltp_info *ltp1 = &(ics1->ltp); - ltp_info *ltp2 = (cpe->common_window) ? &(ics2->ltp2) : &(ics2->ltp) ; + ltp_info *ltp2 = (cpe->common_window) ? &(ics2->ltp2) : &(ics2->ltp); #ifdef LD_DEC if (hDecoder->object_type == LD) { @@ -981,13 +1038,34 @@ uint8_t reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_str if (hDecoder->time_out[cpe->channel] == NULL) { - hDecoder->time_out[cpe->channel] = (real_t*)faad_malloc(hDecoder->frameLength*2*sizeof(real_t)); - memset(hDecoder->time_out[cpe->channel], 0, hDecoder->frameLength*2*sizeof(real_t)); + mul = 1; +#ifdef SBR_DEC + hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; + if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + { + /* SBR requires 2 times as much output data */ + mul = 2; + hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; + } +#endif + hDecoder->time_out[cpe->channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->time_out[cpe->channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); } if (hDecoder->time_out[cpe->paired_channel] == NULL) { - hDecoder->time_out[cpe->paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*2*sizeof(real_t)); - memset(hDecoder->time_out[cpe->paired_channel], 0, hDecoder->frameLength*2*sizeof(real_t)); + hDecoder->time_out[cpe->paired_channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->time_out[cpe->paired_channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); + } + + if (hDecoder->fb_intermed[cpe->channel] == NULL) + { + hDecoder->fb_intermed[cpe->channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->fb_intermed[cpe->channel], 0, hDecoder->frameLength*sizeof(real_t)); + } + if (hDecoder->fb_intermed[cpe->paired_channel] == NULL) + { + hDecoder->fb_intermed[cpe->paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); + memset(hDecoder->fb_intermed[cpe->paired_channel], 0, hDecoder->frameLength*sizeof(real_t)); } /* filter bank */ @@ -1005,10 +1083,12 @@ uint8_t reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_str #else ifilter_bank(hDecoder->fb, ics1->window_sequence, ics1->window_shape, hDecoder->window_shape_prev[cpe->channel], spec_coef1, - hDecoder->time_out[cpe->channel], hDecoder->object_type, hDecoder->frameLength); + hDecoder->time_out[cpe->channel], hDecoder->fb_intermed[cpe->channel], + hDecoder->object_type, hDecoder->frameLength); ifilter_bank(hDecoder->fb, ics2->window_sequence, ics2->window_shape, hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, - hDecoder->time_out[cpe->paired_channel], hDecoder->object_type, hDecoder->frameLength); + hDecoder->time_out[cpe->paired_channel], hDecoder->fb_intermed[cpe->paired_channel], + hDecoder->object_type, hDecoder->frameLength); #endif #ifdef SSR_DEC } else { @@ -1056,10 +1136,40 @@ uint8_t reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_str if (is_ltp_ot(hDecoder->object_type)) { lt_update_state(hDecoder->lt_pred_stat[cpe->channel], hDecoder->time_out[cpe->channel], - hDecoder->time_out[cpe->channel]+hDecoder->frameLength, hDecoder->frameLength, hDecoder->object_type); + hDecoder->fb_intermed[cpe->channel], hDecoder->frameLength, hDecoder->object_type); lt_update_state(hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->time_out[cpe->paired_channel], - hDecoder->time_out[cpe->paired_channel]+hDecoder->frameLength, hDecoder->frameLength, - hDecoder->object_type); + hDecoder->fb_intermed[cpe->paired_channel], hDecoder->frameLength, hDecoder->object_type); + } +#endif + +#ifdef SBR_DEC + if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) + { + uint8_t ele = hDecoder->fr_ch_ele; + uint8_t ch0 = cpe->channel; + uint8_t ch1 = cpe->paired_channel; + + /* following case can happen when forceUpSampling == 1 */ + if (hDecoder->sbr[ele] == NULL) + { + hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, + cpe->ele_id, 2*get_sample_rate(hDecoder->sf_index) +#ifdef DRM + , 0 +#endif + ); + } + + retval = sbrDecodeCoupleFrame(hDecoder->sbr[ele], + hDecoder->time_out[ch0], hDecoder->time_out[ch1], + hDecoder->postSeekResetFlag, hDecoder->forceUpSampling); + if (retval > 0) + return retval; + } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) + && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) + { + return 23; } #endif |