📄 specrec.c
字号:
//printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+2]);
//printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+3]);
#endif
#endif
gincrease += 4;
k += 4;
}
wa += win_inc;
}
j += width;
}
gindex += gincrease;
}
return error;
}
static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel,
uint8_t output_channels)
{
int mul = 1;
#ifdef MAIN_DEC
/* MAIN object type prediction */
if (hDecoder->object_type == MAIN)
{
/* allocate the state only when needed */
if (hDecoder->pred_stat[channel] != NULL)
{
faad_free(hDecoder->pred_stat[channel]);
hDecoder->pred_stat[channel] = NULL;
}
hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(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)
{
faad_free(hDecoder->lt_pred_stat[channel]);
hDecoder->lt_pred_stat[channel] = NULL;
}
hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(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)
{
faad_free(hDecoder->time_out[channel]);
hDecoder->time_out[channel] = NULL;
}
{
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[channel] = (real_t*)faad_malloc(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)
{
faad_free(hDecoder->time_out[channel+1]);
hDecoder->time_out[channel+1] = NULL;
}
hDecoder->time_out[channel+1] = (real_t*)faad_malloc(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)
{
faad_free(hDecoder->fb_intermed[channel]);
hDecoder->fb_intermed[channel] = NULL;
}
hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(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));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[channel][k] = REAL_CONST(-1);
}
}
#endif
return 0;
}
static uint8_t allocate_channel_pair(NeAACDecHandle hDecoder,
uint8_t channel, uint8_t paired_channel)
{
int mul = 1;
#ifdef MAIN_DEC
/* 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));
reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength);
}
if (hDecoder->pred_stat[paired_channel] == NULL)
{
hDecoder->pred_stat[paired_channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
reset_all_predictors(hDecoder->pred_stat[paired_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));
memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
}
if (hDecoder->lt_pred_stat[paired_channel] == NULL)
{
hDecoder->lt_pred_stat[paired_channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
memset(hDecoder->lt_pred_stat[paired_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;
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[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->time_out[paired_channel] == NULL)
{
hDecoder->time_out[paired_channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[paired_channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->fb_intermed[channel] == NULL)
{
hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->fb_intermed[paired_channel] == NULL)
{
hDecoder->fb_intermed[paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->fb_intermed[paired_channel], 0, hDecoder->frameLength*sizeof(real_t));
}
#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
{
if (hDecoder->ssr_overlap[cpe->channel] == NULL)
{
hDecoder->ssr_overlap[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->ssr_overlap[cpe->channel], 0, 2*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->ssr_overlap[cpe->paired_channel] == NULL)
{
hDecoder->ssr_overlap[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->ssr_overlap[cpe->paired_channel], 0, 2*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->prev_fmd[cpe->channel] == NULL)
{
uint16_t k;
hDecoder->prev_fmd[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[cpe->channel][k] = REAL_CONST(-1);
}
if (hDecoder->prev_fmd[cpe->paired_channel] == NULL)
{
uint16_t k;
hDecoder->prev_fmd[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[cpe->paired_channel][k] = REAL_CONST(-1);
}
}
#endif
return 0;
}
uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
element *sce, int16_t *spec_data)
{
uint8_t retval;
int output_channels;
ALIGN real_t spec_coef[1024];
#ifdef PROFILE
int64_t count = faad_get_ts();
#endif
/* always allocate 2 channels, PS can always "suddenly" turn up */
#if ( (defined(DRM) && defined(DRM_PS)) )
output_channels = 2;
#elif defined(PS_DEC)
if (hDecoder->ps_used[hDecoder->fr_ch_ele])
output_channels = 2;
else
output_channels = 1;
#else
output_channels = 1;
#endif
if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0)
{
/* 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 */
/* this only happens if PS is actually found but not in the first frame
* this means that there is only 1 bitstream element!
*/
/* reset the allocation */
hDecoder->element_alloced[hDecoder->fr_ch_ele] = 0;
hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
//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;
hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1;
}
/* dequantisation and scaling */
retval = quant_to_spec(hDecoder, ics, spec_data, spec_coef, hDecoder->frameLength);
if (retval > 0)
return retval;
#ifdef PROFILE
count = faad_get_ts() - count;
hDecoder->requant_cycles += count;
#endif
/* pns decoding */
pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type,
&(hDecoder->__r1), &(hDecoder->__r2));
#ifdef MAIN_DEC
/* MAIN object type prediction */
if (hDecoder->object_type == MAIN)
{
/* intra channel prediction */
ic_prediction(ics, spec_coef, hDecoder->pred_stat[sce->channel], hDecoder->frameLength,
hDecoder->sf_index);
/* In addition, for scalefactor bands coded by perceptual
noise substitution the predictors belonging to the
corresponding spectral coefficients are reset.
*/
pns_reset_pred_state(ics, hDecoder->pred_stat[sce->channel]);
}
#endif
#ifdef LTP_DEC
if (is_ltp_ot(hDecoder->object_type))
{
#ifdef LD_DEC
if (hDecoder->object_type == LD)
{
if (ics->ltp.data_present)
{
if (ics->ltp.lag_update)
hDecoder->ltp_lag[sce->channel] = ics->ltp.lag;
}
ics->ltp.lag = hDecoder->ltp_lag[sce->channel];
}
#endif
/* long term prediction */
lt_prediction(ics, &(ics->ltp), spec_coef, hDecoder->lt_pred_stat[sce->channel], hDecoder->fb,
ics->window_shape, hDecoder->window_shape_prev[sce->channel],
hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength);
}
#endif
/* tns decoding */
tns_decode_frame(ics, &(ics->tns), hDecoder->sf_index, hDecoder->object_type,
spec_coef, hDecoder->frameLength);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -