📄 mp3enc_psychoacoustic_int.cpp
字号:
ippsFFTFwd_RToCCS_16s_Sfs(sw_short[win_counter], fft_line, ipa_pFFTSpecShort, scaleFactor[win_counter], ipa_pBuffer); r = (Ipp16s*)ipa_r_short[ch][ipa_current_f_r_index[ch]][win_counter]; ippsMagnitude_16sc_Sfs((Ipp16sc *)fft_line, r, pa_iblen_short, 1); ippsThreshold_LT_16s_I(r, pa_iblen_short, 1); FIND_NORM_SHIFT_16S(&r[(pa_iblen_short >> 2)], pa_iblen_short - (pa_iblen_short >> 2), shift) if (min_shift > shift) min_shift = shift; if (maxScaleFactor < scaleFactor[win_counter]) maxScaleFactor = scaleFactor[win_counter]; } for (win_counter = 0; win_counter < 3; win_counter++) { r = (Ipp16s*)ipa_r_short[ch][ipa_current_f_r_index[ch]][win_counter]; /* The scalefactor 12 - (2*shift+1) is calculated from max value to multiplay. */ /* This value less than */ /* (pBlock->iblen_short - (pBlock->iblen_short >> 2)) * 25 < 96 * 25 = 2400 */ /* The value 25 is used in comparison (Psychoacoustic module) */ ippsDotProd_16s32s_Sfs(&r[(pa_iblen_short >> 2)], &r[(pa_iblen_short >> 2)], pa_iblen_short - (pa_iblen_short >> 2), &s_en[win_counter], 12 + 2 * (maxScaleFactor- scaleFactor[win_counter]) - (2*min_shift+1)); }}/****************************************************************************/void MP3EncoderInt::InitPsychoacoustic(){ int i, j, ch; ipa_next_frame_PE[0] = ipa_next_frame_PE[1] = 0; ipa_block_type[0] = ipa_block_type[1] = NORM_TYPE; ipa_desired_block_type[0] = ipa_desired_block_type[1] = NORM_TYPE; for (i = 0; i < MAX_PPT_LONG; i++) { ipa_nb_long[0][0][i] = ipa_nb_long[0][1][i] = 0x7FFFFFFF; ipa_nb_long[1][0][i] = ipa_nb_long[1][1][i] = 0x7FFFFFFF; } ipa_nb_longScaleFactor[0] = 0x7FFFFFF; ipa_nb_longScaleFactor[1] = 0x7FFFFFF; for (ch = 0; ch < 2; ch++) for (i = 0; i < 512; i++) { ipa_r[ch][0][i] = ipa_r[ch][1][i] = ipa_r[ch][2][i] = 1; ipa_re[ch][0][i] = ipa_re[ch][1][i] = ipa_re[ch][2][i] = 1; ipa_im[ch][0][i] = ipa_im[ch][1][i] = ipa_im[ch][2][i] = 0; } for (ch = 0; ch < 2; ch++) { ipa_rScaleFactor[ch][0] = 0; ipa_rScaleFactor[ch][1] = 0; ipa_rScaleFactor[ch][2] = 0; } for (ch = 0; ch < 2; ch++) for (j = 0; j < 3; j++) { for (i = 0; i < 128; i++) { ipa_r_short[ch][0][j][i] = ipa_r_short[ch][1][j][i] = ipa_r_short[ch][2][j][i] = 1; ipa_re_short[ch][0][j][i] = ipa_re_short[ch][1][j][i] = ipa_re_short[ch][2][j][i] = 1; ipa_im_short[ch][0][j][i] = ipa_im_short[ch][1][j][i] = ipa_im_short[ch][2][j][i] = 0; } for (i = 0; i < MAX_PPT_SHORT; i++) { ipa_nb_short[ch][0][j][i] = ipa_nb_short[ch][1][j][i] = 0x7FFFFFFF; }// ipa_nb_shortScaleFactor[ch][i] = 0x7FFFFFF; }}Status MP3EncoderInt::InitPsychoacousticCom(){ int i; int size, size_short, max_len; int num_ptt, b, bb; Ipp16s *bval; Ipp16s *sprdngf; int jj; const int num_ptt_long_tbl[3] = {63,62,59}; pa_iblen_long = 512; pa_iblen_short = 128; ipa_current_f_r_index[0] = ipa_current_f_r_index[1] = 2; ipa_nb_curr_index[0] = ipa_nb_curr_index[1] = 1; ipa_nb_prev_index[0] = ipa_nb_prev_index[1] = 0; pa_num_ptt_long = num_ptt = num_ptt_long_tbl[header.samplingFreq]; bval = imp3enc_bval_l[header.samplingFreq]; sprdngf = (Ipp16s*)ipa_sprdngf_long; for (jj = 0; jj < 1; jj++) { for (b = 0; b < num_ptt; b++) { Ipp16s *tmp_ptr = sprdngf + b * num_ptt; int tmp = 0; int 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((short)tmp, tmp_ptr, num_ptt, scalef); }/* num_ptt = pBlock->shortWindow->num_ptt; bval = (Ipp16s*)pBlock->shortWindow->bval; sprdngf = (Ipp16s*)pBlock->sprdngf_short;*/ }// pa_num_ptt_short = num_ptt = num_ptt_short_tbl[header.samplingFreq];// sprdngf = (Ipp16s*)ipa_sprdngf_short; max_len = 0; for (i = 0; i < pa_num_ptt_long; i++) { int len = mp3enc_pa_numlines_l[header.samplingFreq][i]; if (len > max_len) max_len = len; } ipa_longScale = 0; while (max_len > (1 << ipa_longScale)) { ipa_longScale++; } if (ippsFFTInitAlloc_R_16s(&(ipa_pFFTSpecLong), 10, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast) != ippStsOk) return UMC_ALLOC; if (ippsFFTInitAlloc_R_16s(&(ipa_pFFTSpecShort), 8, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast) != ippStsOk) return UMC_ALLOC; if (ippsFFTGetBufSize_R_16s(ipa_pFFTSpecLong, &size) != ippStsOk) return UMC_ALLOC; if (ippsFFTGetBufSize_R_16s(ipa_pFFTSpecShort, &size_short) != ippStsOk) return UMC_ALLOC; if (size < size_short) size = size_short; if (size != 0) { ipa_pBuffer = ippsMalloc_8u(size); if (ipa_pBuffer == NULL) return UMC_ALLOC; } return UMC_OK;}/****************************************************************************/void MP3EncoderInt::FreePsychoacoustic(){ if (ipa_pFFTSpecShort) ippsFFTFree_R_16s(ipa_pFFTSpecShort); if (ipa_pFFTSpecLong) ippsFFTFree_R_16s(ipa_pFFTSpecLong); if (ipa_pBuffer) ippsFree(ipa_pBuffer);}/****************************************************************************/void MP3EncoderInt::Psychoacoustic(Ipp16s *pa_buffer, int gr, int ch){ VM_ALIGN16_DECL(Ipp32s) rsqr_long[1024]; VM_ALIGN16_DECL(Ipp32s) rsqr_short[1024]; Ipp32s s_en[3]; Ipp32s min, max; int rsqr_longScale; int rsqr_shortScale[3]; int next_desired_block_type; ipa_curr_frame_PE_st[gr][ch] = ipa_curr_frame_PE[ch] = ipa_next_frame_PE[ch]; psy_long_window(pa_buffer, rsqr_long, &rsqr_longScale, ch); psy_short_window(pa_buffer, s_en, rsqr_short, rsqr_shortScale, ch); ippsMinMax_32s(s_en, 3, &min, &max); /* part 1 */ if (ipa_next_frame_PE[ch] > 2900) { next_desired_block_type = SHORT_TYPE; } else if (max > 20 * min) { next_desired_block_type = SHORT_TYPE; } else if ((max > 10 * min) && (ipa_next_frame_PE[ch] > 1500)) { next_desired_block_type = SHORT_TYPE; } else { next_desired_block_type = NORM_TYPE; } /* part 2 */ if (next_desired_block_type == NORM_TYPE && ipa_desired_block_type[ch] == START_TYPE) VM_ASSERT(0); if (next_desired_block_type == NORM_TYPE) { if (ipa_desired_block_type[ch] == SHORT_TYPE) next_desired_block_type = STOP_TYPE; } else { if (ipa_desired_block_type[ch] == NORM_TYPE ) ipa_desired_block_type[ch] = START_TYPE; if ( ipa_desired_block_type[ch] == STOP_TYPE ) { ipa_desired_block_type[ch] = SHORT_TYPE; } } ipa_block_type[ch] = ipa_desired_block_type[ch]; ipa_desired_block_type[ch] = next_desired_block_type; ipa_current_f_r_index[ch]++; if (ipa_current_f_r_index[ch] >= 3) ipa_current_f_r_index[ch] = 0; ipa_nb_curr_index[ch] ^= 1; ipa_nb_prev_index[ch] ^= 1; si_blockType[gr][ch] = ipa_block_type[ch]; if (si_blockType[gr][ch] == NORM_TYPE) si_winSwitch[gr][ch] = 0; else si_winSwitch[gr][ch] = 1; si_mixedBlock[gr][ch] = 0;}/****************************************************************************/};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -