📄 pitch_ol.cpp
字号:
} t0 <<= 1; /* 1/sqrt(energy) */ if (dtx) { /* no test() call since this if is only in simulation env */ /* check tone */#ifdef VAD2 *rmax = max; *r0 = t0;#else /* check tone */ vad_tone_detection(vadSt, max, t0, pOverflow);#endif } t0 = Inv_sqrt(t0, pOverflow); if (scal_flag) { if (t0 > (Word32) 0x3fffffffL) { t0 = MAX_32; } else { t0 = t0 << 1; } } /* max = max/sqrt(energy) */ /* The following code is an inlined version of */ /* L_Extract (max, &max_h, &max_l), i.e. */ /* */ /* *max_h = extract_h (max); */ max_h = (Word16)(max >> 16); /* L_temp_2 = L_shr(max,1), which is used in */ /* the calculation of *max_l (see next operation) */ L_temp_2 = max >> 1; /* *max_l = extract_l (L_msu (L_shr (max, 1), *max_h, 16384)); */ L_temp_3 = (Word32)(max_h << 15); L_temp = L_temp_2 - L_temp_3; max_l = (Word16)L_temp; /* The following code is an inlined version of */ /* L_Extract (t0, &ener_h, &ener_l), i.e. */ /* */ /* *ener_h = extract_h (t0); */ ener_h = (Word16)(t0 >> 16); /* L_temp_2 = L_shr(t0,1), which is used in */ /* the calculation of *ener_l (see next operation) */ L_temp_2 = t0 >> 1; L_temp_3 = (Word32)(ener_h << 15); L_temp = L_temp_2 - L_temp_3; ener_l = (Word16)L_temp; t0 = Mpy_32(max_h, max_l, ener_h, ener_l, pOverflow); if (scal_flag) { t0 = L_shr(t0, scal_fac, pOverflow); if (t0 > (Word32) 0X0000FFFFL) { *cor_max = MAX_16; } else if (t0 < (Word32) 0xFFFF0000L) { *cor_max = MIN_16; } else { *cor_max = (Word16)(t0 >> 1); } } else { *cor_max = (Word16)t0; } return (p_max);}/*----------------------------------------------------------------------------; End Function: Lag_max----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: Lag_max_wrapper------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs corr = pointer to buffer of correlation values (Word32) scal_sig = pointer to buffer of scaled signal values (Word16) scal_fac = scaled signal factor (Word16) scal_flag = EFR compatible scaling flag (Word16) L_frame = length of frame to compute pitch (Word16) lag_max = maximum lag (Word16) lag_min = minimum lag (Word16) cor_max = pointer to the normalized correlation of selected lag (Word16) rmax = pointer to max(<s[i]*s[j]>), (Word32) r0 = pointer to the residual energy (Word32) dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag) pOverflow = pointer to overflow indicator (Flag) Outputs: cor_max contains the newly calculated normalized correlation of the selected lag rmax contains the newly calculated max(<s[i]*s[j]>) r0 contains the newly calculated residual energy pOverflow -> 1 if the math operations called by this routine saturate Returns: p_max = lag of the max correlation found (Word16) Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS (If VAD2 is not defined) Inputs vadSt = pointer to a vadState structure corr = pointer to buffer of correlation values (Word32) scal_sig = pointer to buffer of scaled signal values (Word16) scal_fac = scaled signal factor (Word16) scal_flag = EFR compatible scaling flag (Word16) L_frame = length of frame to compute pitch (Word16) lag_max = maximum lag (Word16) lag_min = minimum lag (Word16) cor_max = pointer to the normalized correlation of selected lag (Word16) dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag) pOverflow = pointer to overflow indicator (Flag) Outputs: cor_max contains the newly calculated normalized correlation of the selected lag vadSt contains the updated VAD state parameters pOverflow -> 1 if the math operations called by this routine saturate Returns: p_max = lag of the max correlation found (Word16) Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function provides external access to the local function Lag_max.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE#ifdef VAD2 CALL Lag_max(corr = corr scal_sig = scal_sig scal_fac = scal_fac scal_flag = scal_flag L_frame = L_frame lag_max = lag_max lag_min = lag_min cor_max = cor_max rmax = rmax r0 = r0 dtx = dtx pOverflow = pOverflow) MODIFYING(nothing) RETURNING(temp)#else CALL Lag_max(vadSt = vadSt corr = corr scal_sig = scal_sig scal_fac = scal_fac scal_flag = scal_flag L_frame = L_frame lag_max = lag_max lag_min = lag_min cor_max = cor_max dtx = dtx pOverflow = pOverflow) MODIFYING(nothing) RETURNING(temp)#endif------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/#ifdef VAD2Word16 Lag_max_wrapper( /* o : lag found */ Word32 corr[], /* i : correlation vector. */ Word16 scal_sig[], /* i : scaled signal. */ Word16 scal_fac, /* i : scaled signal factor. */ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */ Word16 L_frame, /* i : length of frame to compute pitch */ Word16 lag_max, /* i : maximum lag */ Word16 lag_min, /* i : minimum lag */ Word16 *cor_max, /* o : normalized correlation of selected lag */ Word32 *rmax, /* o : max(<s[i]*s[j]>) */ Word32 *r0, /* o : residual energy */ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */ Flag *pOverflow /* i/o : overflow Flag */){ Word16 temp; temp = Lag_max(corr, scal_sig, scal_fac, scal_flag, L_frame, lag_max, lag_min, cor_max, rmax, r0, dtx, pOverflow); return(temp);}#elseWord16 Lag_max_wrapper( /* o : lag found */ vadState *vadSt, /* i/o : VAD state struct */ Word32 corr[], /* i : correlation vector. */ Word16 scal_sig[], /* i : scaled signal. */ Word16 scal_fac, /* i : scaled signal factor. */ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */ Word16 L_frame, /* i : length of frame to compute pitch */ Word16 lag_max, /* i : maximum lag */ Word16 lag_min, /* i : minimum lag */ Word16 *cor_max, /* o : normalized correlation of selected lag */ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */ Flag *pOverflow /* i/o : overflow Flag */){ Word16 temp; temp = Lag_max(vadSt, corr, scal_sig, scal_fac, scal_flag, L_frame, lag_max, lag_min, cor_max, dtx, pOverflow); return(temp);}#endif/*----------------------------------------------------------------------------; End Function: Lag_max_wrapper----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: Pitch_ol------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: vadSt = pointer to a vadState structure mode = data of type enum Mode specifies the mode. signal = pointer to buffer of signal used to compute the open loop pitch where signal[-pit_max] to signal[-1] should be known pit_min = 16 bit value specifies the minimum pitch lag pit_max = 16 bit value specifies the maximum pitch lag L_frame = 16 bit value specifies the length of frame to compute pitch idx = 16 bit value specifies the frame index dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0 pOverflow = pointer to overflow indicator (Flag) Outputs vadSt = The vadSt state structure may be modified. pOverflow -> 1 if the math operations called by this routine saturate Returns: p_max1 = 16 bit value representing the open loop pitch lag. Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function computes the open loop pitch lag based on the perceptually weighted speech signal. This is done in the following steps: - find three maxima of the correlation <sw[n],sw[n-T]>, dividing the search range into three parts: pit_min ... 2*pit_min-1 2*pit_min ... 4*pit_min-1 4*pit_min ... pit_max - divide each maximum by <sw[n-t], sw[n-t]> where t is the delay at that maximum correlation. - select the delay of maximum normalized correlation (among the three candidates) while favoring the lower delay ranges.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEWord16 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 ){ Word16 i, j; Word16 max1, max2, max3; Word16 p_max1, p_max2, p_max3; Word16 scal_flag = 0; Word32 t0;#ifdef VAD2 Word32 r01, r02, r03; Word32 rmax1, rmax2, rmax3;#else Word16 corr_hp_max;#endif Word32 corr[PIT_MAX+1], *corr_ptr; // Scaled signal Word16 scaled_signal[L_FRAME + PIT_MAX]; Word16 *scal_sig, scal_fac;#ifndef VAD2 if (dtx) { // no test() call since this if is only in simulation env // update tone detection if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0)) { vad_tone_detection_update (vadSt, 1); } else { vad_tone_detection_update (vadSt, 0); } }#endif scal_sig = &scaled_signal[pit_max]; t0 = 0L; for (i = -pit_max; i < L_frame; i++) { t0 = L_mac (t0, signal[i], signal[i]); } *--------------------------------------------------------* * 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. * *--------------------------------------------------------* if (L_sub (t0, MAX_32) == 0L) // Test for overflow { for (i = -pit_max; i < L_frame; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -