📄 pitch_ol.cpp
字号:
{ scal_sig[i] = shr (signal[i], 3); } scal_fac = 3; } else if (L_sub (t0, (Word32) 1048576L) < (Word32) 0) // if (t0 < 2^20) { for (i = -pit_max; i < L_frame; i++) { scal_sig[i] = shl (signal[i], 3); } scal_fac = -3; } else { for (i = -pit_max; i < L_frame; i++) { scal_sig[i] = signal[i]; } scal_fac = 0; } // calculate all coreelations of scal_sig, from pit_min to pit_max corr_ptr = &corr[pit_max]; comp_corr (scal_sig, L_frame, pit_max, pit_min, corr_ptr); *--------------------------------------------------------------------* * The pitch lag search is divided in three sections. * * Each section cannot have a pitch multiple. * * We find a maximum for each section. * * We compare the maximum of each section by favoring small lags. * * * * First section: lag delay = pit_max downto 4*pit_min * * Second section: lag delay = 4*pit_min-1 downto 2*pit_min * * Third section: lag delay = 2*pit_min-1 downto pit_min * *--------------------------------------------------------------------* // mode dependent scaling in Lag_max if (sub(mode, MR122) == 0) { scal_flag = 1; } else { scal_flag = 0; }#ifdef VAD2 j = shl (pit_min, 2); p_max1 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, pit_max, j, &max1, &rmax1, &r01, dtx); i = sub (j, 1); j = shl (pit_min, 1); p_max2 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, j, &max2, &rmax2, &r02, dtx); i = sub (j, 1); p_max3 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, pit_min, &max3, &rmax3, &r03, dtx);#else j = shl (pit_min, 2); p_max1 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, pit_max, j, &max1, dtx); i = sub (j, 1); j = shl (pit_min, 1); p_max2 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, j, &max2, dtx); i = sub (j, 1); p_max3 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, pit_min, &max3, dtx); if (dtx) { // no test() call since this if is only in simulation env if (sub(idx, 1) == 0) { // calculate max high-passed filtered correlation of all lags hp_max (corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max); // update complex background detector vad_complex_detection_update(vadSt, corr_hp_max); } }#endif *--------------------------------------------------------------------* * Compare the 3 sections maximum, and favor small lag. * *--------------------------------------------------------------------* if (sub (mult (max1, THRESHOLD), max2) < 0) { max1 = max2; p_max1 = p_max2;#ifdef VAD2 if (dtx) { rmax1 = rmax2; r01 = r02;#endif } if (sub (mult (max1, THRESHOLD), max3) < 0) { p_max1 = p_max3;#ifdef VAD2 if (dtx) { rmax1 = rmax3; r01 = r03; }#endif }#ifdef VAD2 if (dtx) { vadSt->L_Rmax = L_add(vadSt->L_Rmax, rmax1); // Save max correlation vadSt->L_R0 = L_add(vadSt->L_R0, r01); // Save max energy }#endif return (p_max1);}------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/Word16 Pitch_ol( /* o : open loop pitch lag */ vadState *vadSt, /* i/o : VAD state struct */ enum Mode mode, /* i : coder mode */ Word16 signal[], /* i : signal used to compute the open loop pitch */ /* signal[-pit_max] to signal[-1] should be known */ Word16 pit_min, /* i : minimum pitch lag */ Word16 pit_max, /* i : maximum pitch lag */ Word16 L_frame, /* i : length of frame to compute pitch */ Word16 idx, /* i : frame index */ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */ Flag *pOverflow /* i/o : overflow Flag */){ Word16 i; Word16 j; Word16 max1; Word16 max2; Word16 max3; Word16 p_max1; Word16 p_max2; Word16 p_max3; Word16 scal_flag = 0; Word32 t0;#ifdef VAD2 Word32 r01; Word32 r02; Word32 r03; Word32 rmax1; Word32 rmax2; Word32 rmax3;#else Word16 corr_hp_max;#endif Word32 corr[PIT_MAX+1]; Word32 *corr_ptr; /* Scaled signal */ Word16 scaled_signal[L_FRAME + PIT_MAX]; Word16 *scal_sig; Word16 *p_signal; Word16 scal_fac; Word32 L_temp;#ifndef VAD2 if (dtx) { /* no test() call since this if is only in simulation env */ /* update tone detection */ if ((mode == MR475) || (mode == MR515)) { vad_tone_detection_update(vadSt, 1, pOverflow); } else { vad_tone_detection_update(vadSt, 0, pOverflow); } }#endif t0 = 0L; p_signal = &signal[-pit_max]; for (i = -pit_max; i < L_frame; i++) { t0 += (((Word32) * (p_signal)) * *(p_signal)) << 1; p_signal++; if (t0 < 0) { t0 = MAX_32; break; } } /*--------------------------------------------------------* * Scaling of input signal. * * * * if Overflow -> scal_sig[i] = signal[i]>>3 * * else if t0 < 1^20 -> scal_sig[i] = signal[i]<<3 * * else -> scal_sig[i] = signal[i] * *--------------------------------------------------------*/ /*--------------------------------------------------------* * Verification for risk of overflow. * *--------------------------------------------------------*/ scal_sig = &scaled_signal[0]; p_signal = &signal[-pit_max]; if (t0 == MAX_32) /* Test for overflow */ { for (i = (pit_max + L_frame + 1) >> 1; i != 0; i--) { *(scal_sig++) = (Word16)(((Word32) * (p_signal++) >> 3)); *(scal_sig++) = (Word16)(((Word32) * (p_signal++) >> 3)); } *(scal_sig++) = (Word16)(((Word32) * (p_signal++) >> 3)); scal_fac = 3; } else if (t0 < (Word32)1048576L) /* if (t0 < 2^20) */ { for (i = (pit_max + L_frame + 1) >> 1; i != 0; i--) { *(scal_sig++) = (Word16)(((Word32) * (p_signal++) << 3)); *(scal_sig++) = (Word16)(((Word32) * (p_signal++) << 3)); } *(scal_sig++) = (Word16)(((Word32) * (p_signal++) << 3)); scal_fac = -3; } else { oscl_memcpy(scal_sig, p_signal, (L_frame + pit_max)*sizeof(*signal)); scal_fac = 0; } /* calculate all coreelations of scal_sig, from pit_min to pit_max */ corr_ptr = &corr[pit_max]; scal_sig = &scaled_signal[pit_max]; comp_corr(scal_sig, L_frame, pit_max, pit_min, corr_ptr); /*--------------------------------------------------------------------* * The pitch lag search is divided in three sections. * * Each section cannot have a pitch multiple. * * We find a maximum for each section. * * We compare the maximum of each section by favoring small lags. * * * * First section: lag delay = pit_max downto 4*pit_min * * Second section: lag delay = 4*pit_min-1 downto 2*pit_min * * Third section: lag delay = 2*pit_min-1 downto pit_min * *--------------------------------------------------------------------*/ /* mode dependent scaling in Lag_max */ if (mode == MR122) { scal_flag = 1; } else { scal_flag = 0; }#ifdef VAD2 L_temp = ((Word32)pit_min) << 2; if (L_temp != (Word32)((Word16) L_temp)) { *pOverflow = 1; j = (pit_min > 0) ? MAX_16 : MIN_16; } else { j = (Word16)L_temp; } p_max1 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, pit_max, j, &max1, &rmax1, &r01, dtx, pOverflow); i = j - 1; j = pit_min << 1; p_max2 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, j, &max2, &rmax2, &r02, dtx, pOverflow); i = j - 1; p_max3 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, pit_min, &max3, &rmax3, &r03, dtx, pOverflow);#else L_temp = ((Word32)pit_min) << 2; if (L_temp != (Word32)((Word16) L_temp)) { *pOverflow = 1; j = (pit_min > 0) ? MAX_16 : MIN_16; } else { j = (Word16)L_temp; } p_max1 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, pit_max, j, &max1, dtx, pOverflow); i = j - 1; j = pit_min << 1; p_max2 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, j, &max2, dtx, pOverflow); i = j - 1; p_max3 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame, i, pit_min, &max3, dtx, pOverflow); if (dtx) { /* no test() call since this if is only in simulation env */ if (idx == 1) { /* calculate max high-passed filtered correlation of all lags */ hp_max(corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max, pOverflow); /* update complex background detector */ vad_complex_detection_update(vadSt, corr_hp_max); } }#endif /*--------------------------------------------------------------------* * Compare the 3 sections maximum, and favor small lag. * *--------------------------------------------------------------------*/ i = mult(max1, THRESHOLD, pOverflow); if (i < max2) { max1 = max2; p_max1 = p_max2;#ifdef VAD2 if (dtx) { rmax1 = rmax2; r01 = r02; }#endif } i = mult(max1, THRESHOLD, pOverflow); if (i < max3) { p_max1 = p_max3;#ifdef VAD2 if (dtx) { rmax1 = rmax3; r01 = r03; }#endif }#ifdef VAD2 if (dtx) { /* Save max correlation */ vadSt->L_Rmax = L_add(vadSt->L_Rmax, rmax1, pOverflow); /* Save max energy */ vadSt->L_R0 = L_add(vadSt->L_R0, r01, pOverflow); }#endif return (p_max1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -