📄 set_sign.cpp
字号:
INPUT AND OUTPUT DEFINITIONS Inputs: dn = buffer of correlation values (Word16) cn = buffer of residual after long term prediction (Word16) sign = sign of correlation buffer elements (Word16) pos_max = buffer containing position of maximum correlation (Word16) nb_track = number of tracks (Word16) ipos = buffer containing the starting position for each pulse (Word16) step = step size in the tracks (Word16) pOverflow = pointer to Overflow flag (Flag) Outputs: sign buffer contains the sign of correlation values dn buffer contains the sign-adjusted correlation values pos_max buffer contains the maximum correlation position ipos buffer contains the starting position of each pulse pOverflow -> 1 if the math operations called by this function result in saturation Returns: None Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function builds the sign vector according to dn and cn, and modifies dn to include the sign information (dn[i]=sign[i]*dn[i]). It also finds the position of maximum of correlation in each track and the starting position for each pulse.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES set_sign.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid set_sign12k2 ( Word16 dn[], //i/o : correlation between target and h[] Word16 cn[], //i : residual after long term prediction Word16 sign[], //o : sign of d[n] Word16 pos_max[], //o : position of maximum correlation Word16 nb_track, //i : number of tracks tracks Word16 ipos[], //o : starting position for each pulse Word16 step //i : the step size in the tracks){ Word16 i, j; Word16 val, cor, k_cn, k_dn, max, max_of_all; Word16 pos = 0; // initialization only needed to keep gcc silent Word16 en[L_CODE]; // correlation vector Word32 s; // The reference ETSI code uses a global flag for Overflow. However in the // actual implementation a pointer to the overflow flag is passed in. This // pointer is passed into the basic math functions called by this routine. // calculate energy for normalization of cn[] and dn[] s = 256; for (i = 0; i < L_CODE; i++) { s = L_mac (s, cn[i], cn[i]); } s = Inv_sqrt (s); k_cn = extract_h (L_shl (s, 5)); s = 256; for (i = 0; i < L_CODE; i++) { s = L_mac (s, dn[i], dn[i]); } s = Inv_sqrt (s); k_dn = extract_h (L_shl (s, 5)); for (i = 0; i < L_CODE; i++) { val = dn[i]; cor = pv_round (L_shl (L_mac (L_mult (k_cn, cn[i]), k_dn, val), 10)); if (cor >= 0) { sign[i] = 32767; // sign = +1 } else { sign[i] = -32767; // sign = -1 cor = negate (cor); val = negate (val); } // modify dn[] according to the fixed sign dn[i] = val; en[i] = cor; } max_of_all = -1; for (i = 0; i < nb_track; i++) { max = -1; for (j = i; j < L_CODE; j += step) { cor = en[j]; val = sub (cor, max); if (val > 0) { max = cor; pos = j; } } // store maximum correlation position pos_max[i] = pos; val = sub (max, max_of_all); if (val > 0) { max_of_all = max; // starting position for i0 ipos[0] = i; } } // // Set starting position of each pulse. // pos = ipos[0]; ipos[nb_track] = pos; for (i = 1; i < nb_track; i++) { pos = add (pos, 1); if (sub (pos, nb_track) >= 0) { pos = 0; } ipos[i] = pos; ipos[add(i, nb_track)] = pos; }}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/void set_sign12k2( Word16 dn[], /* i/o : correlation between target and h[] */ Word16 cn[], /* i : residual after long term prediction */ Word16 sign[], /* o : sign of d[n] */ Word16 pos_max[], /* o : position of maximum correlation */ Word16 nb_track, /* i : number of tracks tracks */ Word16 ipos[], /* o : starting position for each pulse */ Word16 step, /* i : the step size in the tracks */ Flag *pOverflow /* i/o: overflow flag */){ Word16 i, j; Word16 val; Word16 cor; Word16 k_cn; Word16 k_dn; Word16 max; Word16 max_of_all; Word16 pos = 0; /* initialization only needed to keep gcc silent */ Word16 en[L_CODE]; /* correlation vector */ Word32 s; Word32 t; Word32 L_temp; Word16 *p_cn; Word16 *p_dn; Word16 *p_sign; Word16 *p_en; /* calculate energy for normalization of cn[] and dn[] */ s = 256; t = 256; p_cn = cn; p_dn = dn; /* crosscorrelation values do not have strong peaks, so scaling applied in cor_h_x (sf=2) guaranteed that the mac of the energy for this vector will not overflow */ for (i = L_CODE; i != 0; i--) { val = *(p_cn++); s = L_mac(s, val, val, pOverflow); val = *(p_dn++); t += ((Word32) val * val) << 1; } s = Inv_sqrt(s, pOverflow); k_cn = (Word16)((L_shl(s, 5, pOverflow)) >> 16); t = Inv_sqrt(t, pOverflow); k_dn = (Word16)(t >> 11); p_cn = &cn[L_CODE-1]; p_sign = &sign[L_CODE-1]; p_en = &en[L_CODE-1]; for (i = L_CODE - 1; i >= 0; i--) { L_temp = ((Word32)k_cn * *(p_cn--)) << 1; val = dn[i]; s = L_mac(L_temp, k_dn, val, pOverflow); L_temp = L_shl(s, 10, pOverflow); cor = pv_round(L_temp, pOverflow); if (cor >= 0) { *(p_sign--) = 32767; /* sign = +1 */ } else { *(p_sign--) = -32767; /* sign = -1 */ cor = - (cor); /* modify dn[] according to the fixed sign */ dn[i] = - val; } *(p_en--) = cor; } max_of_all = -1; for (i = 0; i < nb_track; i++) { max = -1; for (j = i; j < L_CODE; j += step) { cor = en[j]; if (cor > max) { max = cor; pos = j; } } /* store maximum correlation position */ pos_max[i] = pos; if (max > max_of_all) { max_of_all = max; /* starting position for i0 */ ipos[0] = i; } } /*----------------------------------------------------------------* * Set starting position of each pulse. * *----------------------------------------------------------------*/ pos = ipos[0]; ipos[nb_track] = pos; for (i = 1; i < nb_track; i++) { pos++; if (pos >= nb_track) { pos = 0; } ipos[ i] = pos; ipos[ i + nb_track] = pos; } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -