📄 aac_enc_api_int.c
字号:
state_com->real_max_sfb_lfe[0] = state_com->real_max_sfb_lfe[1] =
state_com->real_max_sfb_lfe[3] = state_com->real_max_sfb[0];
state_com->real_max_sfb_lfe[2] = state_com->real_max_sfb[2];
state_com->real_max_line_lfe[0] = state_com->real_max_line_lfe[1] =
state_com->real_max_line_lfe[3] = state_com->real_max_line[0];
state_com->real_max_line_lfe[2] = state_com->real_max_line[2];
}
if (state_com->ath_max_sfb[0] > state_com->real_max_sfb_lfe[0]) {
state_com->ath_max_sfb_lfe[0] = state_com->real_max_sfb_lfe[1] =
state_com->ath_max_sfb_lfe[3] = state_com->real_max_sfb_lfe[0];
} else {
state_com->ath_max_sfb_lfe[0] = state_com->real_max_sfb_lfe[1] =
state_com->ath_max_sfb_lfe[3] = state_com->ath_max_sfb[0];
}
if (state_com->ath_max_sfb[2] > state_com->real_max_sfb_lfe[2]) {
state_com->ath_max_sfb_lfe[2] = state_com->real_max_sfb_lfe[2];
} else {
state_com->ath_max_sfb_lfe[2] = state_com->ath_max_sfb[2];
}
aacStatus = InitFilterbank_enc(&(state->filterbank_enc), ptr, &tmpSize);
if (aacStatus != AAC_OK) return aacStatus;
size += tmpSize;
ptr += tmpSize;
aacStatus = aaciencInitPsychoacousticCom(&state->psychoacoustic_block_com,
ptr, sf_index, ns_mode, &tmpSize);
if (aacStatus != AAC_OK) return aacStatus;
size += tmpSize;
ptr += tmpSize;
state->psychoacoustic_block_com.prev_prev_f_r_index = state_com->m_buff_prev_index;
state->psychoacoustic_block_com.prev_f_r_index = state_com->m_buff_curr_index;
state->psychoacoustic_block_com.current_f_r_index = state_com->m_buff_next_index;
for (ch = 0; ch < chNum; ch++) {
aaciencInitPsychoacoustic(&state->psychoacoustic_block[ch]);
}
if (lfe_channel_present != 0) {
bits_for_lfe = bits_per_frame/(5 * chNum - 4 * lfe_channel_present);
if (bits_for_lfe < 300) bits_for_lfe = 300;
else if (bits_for_lfe > 768 * 8) bits_for_lfe = 768 * 8;
bits_per_frame -= bits_for_lfe * lfe_channel_present;
}
sce_tag = 0;
cpe_tag = 0;
lfe_tag = 0;
num_channel = (state_com->m_channel_number - lfe_channel_present);
for (ch = 0; ch < chNum;) {
state_com->chInfo[ch].prev_window_shape = 1;
state_com->chInfo[ch].common_scalefactor_update = 2;
state_com->chInfo[ch].last_frame_common_scalefactor = 0;
if (state_com->chInfo[ch].element_id == ID_CPE) {
state_com->chInfo[ch+1].common_scalefactor_update = 2;
state_com->chInfo[ch+1].last_frame_common_scalefactor = 0;
state_com->chInfo[ch].element_instance_tag = cpe_tag;
state_com->chInfo[ch].bits_in_buf = 0;
state_com->chInfo[ch].mean_bits = (2 * bits_per_frame)/num_channel;
state_com->chInfo[ch].max_bits_in_buf = 768 * 8 * 2;
bits_per_frame -= (state_com->chInfo[ch].mean_bits);
cpe_tag++;
ch += 2;
num_channel -= 2;
} else if (state_com->chInfo[ch].element_id == ID_SCE) {
state_com->chInfo[ch].element_instance_tag = sce_tag;
state_com->chInfo[ch].bits_in_buf = 0;
state_com->chInfo[ch].mean_bits = bits_per_frame/num_channel;
state_com->chInfo[ch].max_bits_in_buf = 768 * 8;
bits_per_frame -= (state_com->chInfo[ch].mean_bits);
sce_tag++;
ch += 1;
num_channel -= 1;
} else {
state_com->chInfo[ch].element_instance_tag = lfe_tag;
state_com->chInfo[ch].bits_in_buf = 0;
state_com->chInfo[ch].mean_bits = bits_for_lfe;
state_com->chInfo[ch].max_bits_in_buf = 768 * 8;
lfe_tag++;
ch += 1;
}
}
state_com->stereo_mode_param = stereo_mode;
state_com->audioObjectType = audioObjectType;
} else {
aacStatus = BuildHuffmanTables(NULL, &tmpSize);
if (aacStatus != AAC_OK) return aacStatus;
size += tmpSize;
aacStatus = InitFilterbank_enc(NULL, ptr, &tmpSize);
if (aacStatus != AAC_OK) return aacStatus;
size += tmpSize;
aacStatus = aaciencInitPsychoacousticCom(NULL, ptr, sf_index,
ns_mode, &tmpSize);
if (aacStatus != AAC_OK) return aacStatus;
size += tmpSize;
}
if (audioObjectType == AOT_AAC_LTP) {
Ipp32s sizeSpec, sizeInit, sizeWork;
Ipp8u *pBufInit;
ippStatus = ippsFFTGetSize_R_32s(12, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone,
&sizeSpec, &sizeInit, &sizeWork);
if (ippStatus != ippStsOk) return AAC_ALLOC;
size += (sizeSpec + sizeWork + sizeInit);
if (state) {
state->corrBuff = ptr + sizeSpec;
pBufInit = state->corrBuff + sizeWork;
ippStatus = ippsFFTInit_R_32s(&state->corrFft, 12, IPP_FFT_DIV_INV_BY_N,
ippAlgHintNone, ptr, pBufInit);
if (ippStatus != ippStsOk) return AAC_ALLOC;
ptr += (sizeSpec + sizeWork + sizeInit);
}
}
*size_all = size;
return AAC_OK;
}
/********************************************************************/
AACStatus aaciencGetFrame(Ipp16s *inPointer,
Ipp32s *encodedBytes,
Ipp8u *outPointer,
AACEnc *state)
{
__ALIGN Ipp16s mdct_line[2][1024];
__ALIGN Ipp16s mdct_line_i[1024];
__ALIGN Ipp16s mdct_line_pred[2][1024];
__ALIGN Ipp32s predictedSpectrum[2][2048];
__ALIGN Ipp16s predictedSpectrum16s[2][1024];
__ALIGN Ipp32s inSignal[4 * 1024];
__ALIGN Ipp32s smr_short_i[__ALIGNED(MAX_SFB_SHORT * 8)];
Ipp16s *p_mdct_line;
Ipp16s *p_mdct_line_pred[2];
Ipp32s *ptrSmrIn, *ptrSmrOut, *p_smr;
AACEnc_com *state_com;
Ipp32s sfb_offset[MAX_SECTION_NUMBER];
sEnc_individual_channel_stream ics[2];
sQuantizationBlock quantization_block;
sEnc_single_channel_element sce;
sEnc_channel_pair_element cpe;
sBitsreamBuffer BS;
sBitsreamBuffer *pBS = &BS;
sCrcSaveTable* pCrcSaveTable;
Ipp32s win_seq;
Ipp32s win_shape = 1;
Ipp32s i, j, numCh, ch, procCh, sfb;
Ipp32s available_bits, bits_in_buf;
Ipp32s bits_from_buffer, com_additional_bits, used_bits, save_bits;
Ipp32s additional_bits[2], max_bits_in_buf, lim_bits, norm_bits;
Ipp32s mdct_scaleFactor[2];
Ipp32s max_sfb_pred = 0, ms_add_bits = 0;
if (!inPointer || !outPointer)
return AAC_NULL_PTR;
INIT_BITSTREAM(pBS, outPointer)
state_com = &(state->com);
ippsZero_32s(inSignal + 2048, 2048);
for (i = 0; i < 7; i++) {
ics[0].scale_factor_grouping[i] = 0;
ics[1].scale_factor_grouping[i] = 0;
}
ics[0].pHuffTables = (void**)&state_com->huffman_tables;
ics[1].pHuffTables = (void**)&state_com->huffman_tables;
ics[0].audioObjectType = state_com->audioObjectType;
ics[1].audioObjectType = state_com->audioObjectType;
ics[0].predictor_data_present = 0;
ics[1].predictor_data_present = 0;
sce.p_individual_channel_stream = &ics[0];
cpe.p_individual_channel_stream_0 = &ics[0];
cpe.p_individual_channel_stream_1 = &ics[1];
numCh = state_com->m_channel_number;
pCrcSaveTable = state_com->crcSaveTable;
for (ch = 0; ch < numCh; ch++) {
state_com->buff[ch] =
state->m_buff_pointers[3*ch+state_com->m_buff_next_index];
}
ippsDeinterleave_16s(inPointer, numCh, 1024, state_com->buff);
for (ch = 0; ch < numCh; ch += procCh) {
procCh = 1;
state->psychoacoustic_block[ch].stereo_mode[
state->psychoacoustic_block_com.nb_curr_index] = AAC_MONO;
cpe.ms_mask_present = 0;
if (state_com->chInfo[ch].element_id == ID_CPE) {
procCh = 2;
state->psychoacoustic_block[ch].stereo_mode[
state->psychoacoustic_block_com.nb_curr_index] =
state_com->stereo_mode_param;
cpe.ms_mask_present = 0;
}
if (state_com->chInfo[ch].element_id != ID_LFE) {
sPsychoacousticBlock* pBlock[2];
for (i = 0; i < procCh; i++) {
state->psychoacoustic_block_com.input_data[i][0] =
state->m_buff_pointers[3*(ch+i)+state_com->m_buff_curr_index];
state->psychoacoustic_block_com.input_data[i][1] =
state->m_buff_pointers[3*(ch+i)+state_com->m_buff_next_index];
pBlock[i] = &state->psychoacoustic_block[ch+i];
}
aaciencPsychoacoustic(pBlock, &state->psychoacoustic_block_com, state->ms_thr, procCh);
} else {
state->psychoacoustic_block[ch].block_type = ONLY_LONG_SEQUENCE;
}
for (i = 0; i < procCh; i++) {
win_seq = ics[i].windows_sequence =
state->psychoacoustic_block[ch+i].block_type;
win_shape = ics[i].window_shape = 1;
if (state_com->chInfo[ch+i].element_id != ID_LFE) {
ics[i].max_sfb = state_com->real_max_sfb[win_seq];
ics[i].max_line = state_com->real_max_line[win_seq];
ics[i].ath_max_sfb = state_com->ath_max_sfb[win_seq];
} else {
ics[i].max_sfb = state_com->real_max_sfb_lfe[win_seq];
ics[i].max_line = state_com->real_max_line_lfe[win_seq];
ics[i].ath_max_sfb = state_com->ath_max_sfb_lfe[win_seq];
}
ics[i].sfb_offset = state_com->sfb_offset[win_seq];
Filterbank_enc(&(state->filterbank_enc),
state->m_buff_pointers[3*(ch+i)+state_com->m_buff_prev_index],
state->m_buff_pointers[3*(ch+i)+state_com->m_buff_curr_index],
win_seq, win_shape,
state_com->chInfo[ch+i].prev_window_shape,
mdct_line[i], mdct_scaleFactor+i);
p_mdct_line_pred[i] = NULL;
if (state_com->audioObjectType == AOT_AAC_LTP) {
ics[i].ltp_data_present = 0;
/* There is no prediction in the mid-side mode */
if (state->psychoacoustic_block[ch].stereo_mode[
state->psychoacoustic_block_com.nb_prev_index] != AAC_MS_STEREO) {
if (win_seq != EIGHT_SHORT_SEQUENCE) {
Ipp16s *tmp_ptr;
max_sfb_pred = ics[i].max_sfb;
if (max_sfb_pred > MAX_LTP_SFB_LONG) max_sfb_pred = MAX_LTP_SFB_LONG;
tmp_ptr = state->m_buff_pointers[3*(ch+i)+state_com->m_buff_prev_index];
for (j = 0; j < 1024; j++) {
inSignal[j] = tmp_ptr[j] << 16;
}
tmp_ptr = state->m_buff_pointers[3*(ch+i)+state_com->m_buff_curr_index];
for (j = 0; j < 1024; j++) {
inSignal[j + 1024] = tmp_ptr[j] << 16;
}
aaciencLtpEncode(inSignal, state->ltp_buff[ch+i], predictedSpectrum[i],
&(ics[i].ltp_lag), &(ics[i].ltp_coef),
state->corrFft, state->corrBuff);
if (ics[i].ltp_lag >= 0) {
ippsMDCTFwd_AAC_32s_I(predictedSpectrum[i],
win_seq, win_shape,
state_com->chInfo[ch+i].prev_window_shape,
2048);
ippsZero_32s(predictedSpectrum[i] + state_com->sfb_offset[win_seq][max_sfb_pred],
1024 - state_com->sfb_offset[win_seq][max_sfb_pred]);
ippsConvert_32s16s_Sfs(predictedSpectrum[i], predictedSpectrum16s[i],
1024, mdct_scaleFactor[i] + 2);
p_mdct_line_pred[i] = mdct_line_pred[i];
ippsSub_16s(predictedSpectrum16s[i], mdct_line[i], p_mdct_line_pred[i], 1024);
}
}
}
}
}
if (state->psychoacoustic_block[ch].stereo_mode[
state->psychoacoustic_block_com.nb_prev_index] == AAC_MS_STEREO) {
Ipp16s *ptrL = mdct_line[0];
Ipp16s *ptrR = mdct_line[1];
Ipp32s li, ri;
Ipp32s k;
cpe.ms_mask_present = 2;
if (mdct_scaleFactor[0] > mdct_scaleFactor[1]) {
Ipp32s shift = mdct_scaleFactor[0] - mdct_scaleFactor[1];
if (shift > 16) shift = 16;
for (k = 0; k < 1024; k++) {
Ipp32s tmp = ((Ipp32s)ptrL[k] << shift);
li = ((tmp + (Ipp32s)ptrR[k]) >> (1 + shift));
ri = ((tmp - (Ipp32s)ptrR[k]) >> (1 + shift));
ptrL[k] = (Ipp16s)li;
ptrR[k] = (Ipp16s)ri;
}
/* There is no prediction in the mid-side mode */
mdct_scaleFactor[1] = mdct_scaleFactor[0];
} else {
Ipp32s shift = mdct_scaleFactor[1] - mdct_scaleFactor[0];
if (shift > 16) shift = 16;
for (k = 0; k < 1024; k++) {
Ipp32s tmp = ((Ipp32s)ptrR[k] << shift);
li = (((Ipp32s)ptrL[k] + tmp) >> (1 + shift));
ri = (((Ipp32s)ptrL[k] - tmp) >> (1 + shift));
ptrL[k] = (Ipp16s)li;
ptrR[k] = (Ipp16s)ri;
}
/* There is no prediction in the mid-side mode */
mdct_scaleFactor[0] = mdct_scaleFactor[1];
}
}
/* available_bits counting */
available_bits = state_com->chInfo[ch].mean_bits;
bits_in_buf = state_com->chInfo[ch].bits_in_buf;
max_bits_in_buf = state_com->chInfo[ch].max_bits_in_buf;
used_bits = 3; /* Syntactic element ID */
cpe.common_window = 1; /* stupid MS warning */
if (procCh == 1) {
used_bits += enc_single_channel_element(&sce,
state_com->chInfo[ch].element_instance_tag, pBS, 0, 0);
save_bits = used_bits;
} else {
if (ics[0].windows_sequence == ics[1].windows_sequence) {
cpe.common_window = 1;
} else {
cpe.common_window = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -