📄 specrec.c
字号:
#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);
}
}
#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));
}
}
#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));
if (!hDecoder->time_out[channel])
return 28;
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));
if (!hDecoder->time_out[channel+1])
return 28;
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));
if (!hDecoder->fb_intermed[channel])
return 28;
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)
{
uint8_t 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));
if (!hDecoder->time_out[channel])
return 28;
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));
if (!hDecoder->time_out[paired_channel])
return 28;
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));
if (!hDecoder->fb_intermed[channel])
return 28;
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));
if (!hDecoder->fb_intermed[paired_channel])
return 28;
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;
}
extern uint8_t safestack(uint8_t (*)(NeAACDecHandle hDecoder, ic_stream *ics),NeAACDecHandle hDecoder, ic_stream *ics,void**);
uint8_t sbrDecode(NeAACDecHandle hDecoder, ic_stream *ics)
{
uint8_t channel = hDecoder->channel;
uint8_t retval;
uint8_t ele = hDecoder->fr_ch_ele;
/* following case can happen when forceUpSampling == 1 */
if (hDecoder->sbr[ele] == NULL)
{
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index),
hDecoder->downSampledSBR
#ifdef DRM
, 0
#endif
);
}
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
hDecoder->sbr[ele]->maxAACLine = 8*ics->swb_offset[max(ics->max_sfb-1, 0)];
else
hDecoder->sbr[ele]->maxAACLine = ics->swb_offset[max(ics->max_sfb-1, 0)];
/* check if any of the PS tools is used */
#if (defined(PS_DEC) || defined(DRM_PS))
if (hDecoder->ps_used[ele] == 0)
{
#endif
retval = sbrDecodeSingleFrame(hDecoder->sbr[ele], hDecoder->time_out[channel],
hDecoder->postSeekResetFlag, hDecoder->downSampledSBR);
#if (defined(PS_DEC) || defined(DRM_PS))
} else {
retval = sbrDecodeSingleFramePS(hDecoder->sbr[ele], hDecoder->time_out[channel],
hDecoder->time_out[channel+1], hDecoder->postSeekResetFlag,
hDecoder->downSampledSBR);
}
#endif
return retval;
}
uint8_t sbrDecodeCouple(NeAACDecHandle hDecoder, ic_stream *ics1)
{
uint8_t paired_channel = hDecoder->paired_channel;
uint8_t channel = hDecoder->channel;
uint8_t retval;
uint8_t ele = hDecoder->fr_ch_ele;
/* following case can happen when forceUpSampling == 1 */
if (hDecoder->sbr[ele] == NULL)
{
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index),
hDecoder->downSampledSBR
#ifdef DRM
, 0
#endif
);
}
if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE)
hDecoder->sbr[ele]->maxAACLine = 8*ics1->swb_offset[max(ics1->max_sfb-1, 0)];
else
hDecoder->sbr[ele]->maxAACLine = ics1->swb_offset[max(ics1->max_sfb-1, 0)];
retval = sbrDecodeCoupleFrame(hDecoder->sbr[ele],
hDecoder->time_out[channel], hDecoder->time_out[paired_channel],
hDecoder->postSeekResetFlag, hDecoder->downSampledSBR);
return retval;
}
uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics)
{
uint8_t retval;
uint8_t channel = hDecoder->channel;
uint8_t output_channels;
#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;
#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, channel, output_channels);
if (retval > 0)
return retval;
hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1;
}
ics->buffer = hDecoder->time_out[channel];
/* dequantisation and scaling */
retval = quant_to_spec(hDecoder, ics, hDecoder->d.spec_data[0], hDecoder->frameLength);
if (retval > 0)
return retval;
#ifdef PROFILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -