📄 mp3enc_psychoacoustic_int.c
字号:
ippsFree(mem_init);
}
/*
if (ippsFFTInitAlloc_R_16s(&(state->ipa_pFFTSpecLong),
10, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast) != ippStsOk)
return 1;
if (ippsFFTInitAlloc_R_16s(&(state->ipa_pFFTSpecShort),
8, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast) != ippStsOk)
return 1;
if (ippsFFTGetBufSize_R_16s(state->ipa_pFFTSpecLong, &size) != ippStsOk)
return 1;
if (ippsFFTGetBufSize_R_16s(state->ipa_pFFTSpecShort, &size_short) != ippStsOk)
return 1;
if (size < size_short) size = size_short;
if (size != 0) {
state->ipa_pBuffer = ippsMalloc_8u(size);
if (state->ipa_pBuffer == NULL)
return 1;
}
*/
if(state) {
freq_ind = state->com.header.samplingFreq;
state->ms_dcoef[0] = state->ms_dcoef[1] = state->ms_dcoef_next = 0;
state->ms_ncoef[0] = state->ms_ncoef[1] = state->ms_ncoef_next = 0;
state->pa_iblen_long = 512;
state->pa_iblen_short = 128;
for (ch = 0; ch < 4; ch++)
state->ipa_current_f_r_index[ch] = 2;
for (ch = 0; ch < 4; ch++) {
state->ipa_desired_block_type[ch] = NORM_TYPE;
for (gr = 0; gr < 2; gr++)
state->ipa_next_desired_block_type[gr][ch] = NORM_TYPE;
}
state->pa_num_ptt_long = num_ptt = num_ptt_long_tbl[freq_ind];
bval = mp3ienc_bval_l[freq_ind];
sprdngf = (Ipp16s*)state->ipa_sprdngf_long;
for (jj = 0; jj < 1; jj++) {
for (b = 0; b < num_ptt; b++) {
Ipp16s *tmp_ptr = sprdngf + b * num_ptt;
Ipp32s tmp = 0;
Ipp32s scalef = -15;
Ipp16s src2 = bval[b];
for (bb = 0; bb < num_ptt; bb++) {
ippsSpread_16s_Sfs(bval[bb], src2, -10, tmp_ptr + bb);
tmp += tmp_ptr[bb];
}
while (tmp >= 32768) {
scalef += 1;
tmp >>= 1;
}
ippsDivC_16s_ISfs((Ipp16s)tmp, tmp_ptr, num_ptt, scalef);
}
}
state->pa_num_ptt_short = num_ptt = num_ptt_short_tbl[freq_ind];
sprdngf = (Ipp16s*)state->ipa_sprdngf_short;
for (jj = 0; jj < 1; jj++) {
for (b = 0; b < num_ptt; b++) {
Ipp16s *tmp_ptr = sprdngf + b * num_ptt;
Ipp32s tmp = 0;
Ipp32s scalef = -15;
Ipp16s src2 = mp3ienc_ptbl_s[freq_ind][b].bval;
for (bb = 0; bb < num_ptt; bb++) {
ippsSpread_16s_Sfs(mp3ienc_ptbl_s[freq_ind][bb].bval,
src2, -10, tmp_ptr + bb);
tmp += tmp_ptr[bb];
}
while (tmp >= 32768) {
scalef += 1;
tmp >>= 1;
}
ippsDivC_16s_ISfs((Ipp16s)tmp, tmp_ptr, num_ptt, scalef);
}
}
for (ch = 0; ch < 4; ch++) {
state->ipa_nb_curr_index[ch] = 1;
state->ipa_nb_prev_index[ch] = 0;
}
max_len = 0;
for (i = 0; i < state->pa_num_ptt_long; i++) {
Ipp32s len = mp3ienc_pa_numlines_l[freq_ind][i];
if (len > max_len) max_len = len;
}
state->ipa_longScale = 0;
while (max_len > (1 << state->ipa_longScale)) {
state->ipa_longScale++;
}
max_len = 0;
for (i = 0; i < state->pa_num_ptt_short; i++) {
Ipp32s len = mp3ienc_ptbl_s[freq_ind][i].numlines;
if (len > max_len) max_len = len;
}
state->ipa_shortScale = 0;
while (max_len > (1 << state->ipa_shortScale)) {
state->ipa_shortScale++;
}
for (ch = 0; ch < 4; ch++)
for (i = 0; i < MAX_PPT_LONG; i++) {
for (j = 0; j < 3; j++)
state->ipa_nb_long[ch][j][i] = 0x7FFFFFFF;
}
state->ipa_nb_longScaleFactor[0] = 0x7FFFFFF;
state->ipa_nb_longScaleFactor[1] = 0x7FFFFFF;
for (ch = 0; ch < 4; ch++)
for (i = 0; i < 512; i++) {
state->ipa_r[ch][0][i] = state->ipa_r[ch][1][i] = state->ipa_r[ch][2][i] = 1;
state->ipa_re[ch][0][i] = state->ipa_re[ch][1][i] = state->ipa_re[ch][2][i] = 1;
state->ipa_im[ch][0][i] = state->ipa_im[ch][1][i] = state->ipa_im[ch][2][i] = 0;
}
for (ch = 0; ch < 4; ch++)
for (j = 0; j < 3; j++) {
for (i = 0; i < 128; i++) {
state->ipa_r_short[ch][0][j][i] = state->ipa_r_short[ch][1][j][i] =
state->ipa_r_short[ch][2][j][i] = 1;
state->ipa_re_short[ch][0][j][i] = state->ipa_re_short[ch][1][j][i] =
state->ipa_re_short[ch][2][j][i] = 1;
state->ipa_im_short[ch][0][j][i] = state->ipa_im_short[ch][1][j][i] =
state->ipa_im_short[ch][2][j][i] = 0;
}
}
for (ch = 0; ch < 4; ch++)
state->ipa_next_frame_PE[ch] = 0;
}
if(size_all)
*size_all = size;
return 0;
}
/****************************************************************************/
void mp3ienc_psychoacousticFree(MP3Enc *state)
{
if (state->ipa_pFFTSpecShort)
ippsFFTFree_R_16s(state->ipa_pFFTSpecShort);
if (state->ipa_pFFTSpecLong)
ippsFFTFree_R_16s(state->ipa_pFFTSpecLong);
if (state->ipa_pBuffer)
ippsFree(state->ipa_pBuffer);
}
/****************************************************************************/
static void mp3ienc_psychoacoustic_stage1(MP3Enc *state, Ipp16s *pa_buffer, Ipp32s gr, Ipp32s ch)
{
VM_ALIGN16_DECL(Ipp32s) rsqr_long[1024];
Ipp32s s_en[3];
Ipp32s min, max;
Ipp32s rsqr_longScale;
Ipp32s i, j;
state->ipa_curr_frame_PE_st[gr][ch] =
state->ipa_curr_frame_PE[ch] = state->ipa_next_frame_PE[ch];
for (i = 0; i < SBBND_L; i++)
state->pa_ratio_l[gr][ch][i] = state->pa_ratio_l_next[ch][i];
for (j = 0; j < 3; j++)
for (i = 0; i < SBBND_S; i++)
state->pa_ratio_s[gr][ch][j][i] = state->pa_ratio_s_next[ch][j][i];
mp3ienc_psychoacousticLongWindow(state, pa_buffer, rsqr_long, &rsqr_longScale, ch);
mp3ienc_psychoacousticShortWindow(state, pa_buffer, s_en, ch);
ippsMinMax_32s(s_en, 3, &min, &max);
/* part 1 */
if (state->ipa_next_frame_PE[ch] > 2900) {
state->ipa_next_desired_block_type[gr][ch] = SHORT_TYPE;
} else if (max > 20 * min) {
state->ipa_next_desired_block_type[gr][ch] = SHORT_TYPE;
} else if ((max > 10 * min) && (state->ipa_next_frame_PE[ch] > 1500)) {
state->ipa_next_desired_block_type[gr][ch] = SHORT_TYPE;
} else {
state->ipa_next_desired_block_type[gr][ch] = NORM_TYPE;
}
state->ipa_current_f_r_index[ch]++;
if (state->ipa_current_f_r_index[ch] >= 3)
state->ipa_current_f_r_index[ch] = 0;
state->ipa_nb_curr_index[ch] ^= 1;
state->ipa_nb_prev_index[ch] ^= 1;
}
void mp3ienc_psychoacoustic(MP3Enc *state, Ipp16s **pa_buffer)
{
Ipp32s gr, ch, ms, stereo;
stereo = state->com.stereo;
for (gr = 0; gr < 2; gr++) {
for (ch = 0; ch < stereo; ch++)
mp3ienc_psychoacoustic_stage1(state, pa_buffer[ch] + gr * 576, gr, ch);
if (state->com.stereo_mode_param == MPA_MS_STEREO ||
state->com.stereo_mode_param == MPA_JOINT_STEREO) {
for (ch = 2; ch < 4; ch++)
mp3ienc_psychoacoustic_stage1(state, pa_buffer[ch] + gr * 576, gr, ch);
state->ms_ncoef[gr] = state->ms_ncoef_next;
state->ms_dcoef[gr] = state->ms_dcoef_next;
state->ms_ncoef_next = state->ms_pwr[0];
state->ms_dcoef_next = state->ms_pwr[0] + state->ms_pwr[1];
}
}
state->com.stereo_mode = state->com.stereo_mode_param;
if (state->com.stereo_mode_param == MPA_JOINT_STEREO) {
if (((state->ipa_curr_frame_PE_st[0][2] + state->ipa_curr_frame_PE_st[0][3] +
state->ipa_curr_frame_PE_st[1][2] + state->ipa_curr_frame_PE_st[1][3]) << 2) <
3 * (state->ipa_curr_frame_PE_st[0][0] + state->ipa_curr_frame_PE_st[0][1] +
state->ipa_curr_frame_PE_st[1][0] + state->ipa_curr_frame_PE_st[1][1]) ||
((state->ms_ncoef[0] << 2) > 3 * state->ms_dcoef[0] && (state->ms_ncoef[1] << 2) > 3 * state->ms_dcoef[1]))
state->com.stereo_mode = MPA_MS_STEREO;
else
state->com.stereo_mode = MPA_LR_STEREO;
}
if(state->com.stereo_mode_param == MPA_JOINT_STEREO ||
state->com.stereo_mode_param == MPA_MS_STEREO) {
for(ch = 0; ch <= 2; ch += 2) {
for (gr = 0; gr < 2; gr++) {
if ( state->ipa_next_desired_block_type[gr][ch] != state->ipa_next_desired_block_type[gr][ch+1])
state->ipa_next_desired_block_type[gr][ch] =
state->ipa_next_desired_block_type[gr][ch+1] = SHORT_TYPE;
}
}
}
ms = state->com.stereo_mode == MPA_MS_STEREO ? 2 : 0;
for (gr = 0; gr < 2; gr++) {
for (ch = 0; ch < state->com.stereo; ch++) {
Ipp32s next_desired_block_type = state->ipa_next_desired_block_type[gr][ch+ms];
if (next_desired_block_type == NORM_TYPE) {
if (state->ipa_desired_block_type[ch] == SHORT_TYPE)
next_desired_block_type = STOP_TYPE;
} else {
if (state->ipa_desired_block_type[ch] == NORM_TYPE )
state->ipa_desired_block_type[ch] = START_TYPE;
if ( state->ipa_desired_block_type[ch] == STOP_TYPE ) {
state->ipa_desired_block_type[ch] = SHORT_TYPE;
}
}
state->com.si_blockType[gr][ch] = state->ipa_desired_block_type[ch];
state->ipa_desired_block_type[ch] = next_desired_block_type;
if ((mp3_bitrate[state->com.header.id][state->com.header.layer-1]
[state->com.header.bitRate] >> (state->com.stereo - 1)) <= 40)
state->com.si_blockType[gr][ch] = NORM_TYPE;
if (state->com.si_blockType[gr][ch] == NORM_TYPE)
state->com.si_winSwitch[gr][ch] = 0;
else
state->com.si_winSwitch[gr][ch] = 1;
state->com.si_mixedBlock[gr][ch] = 0;
}
}
}
/****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -