📄 c2_9pf.cpp
字号:
rr = rr codvec = codvec ) MODIFYING(nothing) RETURNING(nothing) ----------------------------------------------------------------------------*/ search_2i40( subNr, dn, rr, codvec, pOverflow); return; } /****************************************************************************/ /* ------------------------------------------------------------------------------ FUNCTION NAME: build_code ------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: subNr = subframe number (Word16) codvec = vector containing the position of pulses (Word16) dn_sign = vector containing the sign of pulses (Word16) cod = innovative code vector (Word16) h = vector containing the impulse response of the weighted synthesis filter (Word16) y = vector containing the filtered innovative code (Word16) sign = vector containing the sign of 2 pulses (Word16) Outputs: cod vector contains the new innovative code y vector contains the new filtered innovative code sign vector contains the sign of 2 pulses Returns: indx = codebook index (Word16) Global Variables Used: None Local Variables Needed: trackTable = table used for tracking codewords (Word16) ------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function builds the codeword, the filtered codeword and index of the codevector, based on the signs and positions of 2 pulses. ------------------------------------------------------------------------------ REQUIREMENTS None ------------------------------------------------------------------------------ REFERENCES [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 ------------------------------------------------------------------------------ PSEUDO-CODE static Word16 build_code( Word16 subNr, // i : subframe number Word16 codvec[], // i : position of pulses Word16 dn_sign[], // i : sign of pulses Word16 cod[], // o : innovative code vector Word16 h[], // i : impulse response of weighted synthesis filter Word16 y[], // o : filtered innovative code Word16 sign[] // o : sign of 2 pulses ) { Word16 i, j, k, track, first, index, _sign[NB_PULSE], indx, rsign; Word16 *p0, *p1, *pt; Word32 s; static Word16 trackTable[4*5] = { 0, 1, 0, 1, -1, // subframe 1; track to code; -1 do not code this position 0, -1, 1, 0, 1, // subframe 2 0, 1, 0, -1, 1, // subframe 3 0, 1, -1, 0, 1};// subframe 4 pt = &trackTable[add(subNr, shl(subNr, 2))]; for (i = 0; i < L_CODE; i++) { cod[i] = 0; } indx = 0; rsign = 0; for (k = 0; k < NB_PULSE; k++) { i = codvec[k]; // read pulse position j = dn_sign[i]; // read sign index = mult(i, 6554); // index = pos/5 // track = pos%5 track = sub(i, extract_l(L_shr(L_mult(index, 5), 1))); first = pt[track]; if (first == 0) { if (k == 0) { track = 0; } else { track = 1; index = shl(index, 3); } } else { if (k == 0) { track = 0; index = add(index, 64); // table bit is MSB } else { track = 1; index = shl(index, 3); } } if (j > 0) { cod[i] = 8191; _sign[k] = 32767; rsign = add(rsign, shl(1, track)); } else { cod[i] = -8192; _sign[k] = (Word16) - 32768L; } indx = add(indx, index); } *sign = rsign; p0 = h - codvec[0]; p1 = h - codvec[1]; for (i = 0; i < L_CODE; i++) { s = 0; s = L_mac(s, *p0++, _sign[0]); s = L_mac(s, *p1++, _sign[1]); y[i] = pv_round(s); } return indx; } ------------------------------------------------------------------------------ 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] ------------------------------------------------------------------------------ */ static Word16 build_code( Word16 subNr, /* i : subframe number */ Word16 codvec[], /* i : position of pulses */ Word16 dn_sign[], /* i : sign of pulses */ Word16 cod[], /* o : innovative code vector */ Word16 h[], /* i : impulse response of weighted synthesis */ /* filter */ Word16 y[], /* o : filtered innovative code */ Word16 sign[], /* o : sign of 2 pulses */ Flag *pOverflow /* o : Flag set when overflow occurs */ ) { register Word16 i; register Word16 j; register Word16 k; register Word16 track; register Word16 first; register Word16 index; register Word16 rsign; Word16 indx; Word16 _sign[NB_PULSE]; Word16 *p0; Word16 *p1; const Word16 *pt; Word32 s; pt = trackTable + subNr + (subNr << 2); for (i = 0; i < L_CODE; i++) { *(cod + i) = 0; } indx = 0; rsign = 0; for (k = 0; k < NB_PULSE; k++) { i = *(codvec + k); /* read pulse position */ j = *(dn_sign + i); /* read sign */ s = ((Word32)(i * 6554)) >> 15; index = (Word16) s; /* index = pos/5 */ track = i - (5 * index); /* track = pos%5 */ first = *(pt + track); if (k == 0) { track = 0; if (first != 0) { index += 64; /* table bit is MSB */ } } else { track = 1; index <<= 3; } if (j > 0) { *(cod + i) = 8191; *(_sign + k) = 32767; rsign += (1 << track); } else { *(cod + i) = ~(8192) + 1; *(_sign + k) = (Word16)(~(32768) + 1); } indx += index; } *sign = rsign; p0 = h - *codvec; p1 = h - *(codvec + 1); for (i = 0; i < L_CODE; i++) { s = 0; s = L_mult( *p0++, *_sign, pOverflow); s = L_mac( s, *p1++, *(_sign + 1), pOverflow); *(y + i) = pv_round( s, pOverflow); } return(indx); } /****************************************************************************/ /* ------------------------------------------------------------------------------ FUNCTION NAME: Test_build_code ------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: subNr = subframe number (Word16) codvec = vector containing the position of pulses (Word16) dn_sign = vector containing the sign of pulses (Word16) cod = innovative code vector (Word16) h = vector containing the impulse response of the weighted synthesis filter (Word16) y = vector containing the filtered innovative code (Word16) sign = vector containing the sign of 2 pulses (Word16) Outputs: cod vector contains the new innovative code y vector contains the new filtered innovative code sign vector contains the sign of 2 pulses Returns: indx = codebook index (Word16) Global Variables Used: None Local Variables Needed: trackTable = table used for tracking codewords (Word16) ------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function provides external access to the local function build_code. ------------------------------------------------------------------------------ REQUIREMENTS None ------------------------------------------------------------------------------ REFERENCES [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 ------------------------------------------------------------------------------ PSEUDO-CODE CALL build_code ( subNr = subNr codvec = codvec dn_sign = dn_sign cod = cod h = h y = y sign = sign ) MODIFYING(nothing) RETURNING(indx) ------------------------------------------------------------------------------ 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 Test_build_code( Word16 subNr, /* i : subframe number */ Word16 codvec[], /* i : position of pulses */ Word16 dn_sign[], /* i : sign of pulses */ Word16 cod[], /* o : innovative code vector */ Word16 h[], /* i : impulse response of weighted synthesis */ /* filter */ Word16 y[], /* o : filtered innovative code */ Word16 sign[], /* o : sign of 2 pulses */ Flag * pOverflow /* o : Flag set when overflow occurs */ ) { Word16 test_index; /*---------------------------------------------------------------------------- CALL build_code ( subNr = subNr codvec = codvec dn_sign = dn_sign cod = cod h = h y = y sign = sign ) MODIFYING(nothing) RETURNING(indx) ----------------------------------------------------------------------------*/ test_index = build_code( subNr, codvec, dn_sign, cod, h, y, sign, pOverflow); return(test_index); }#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -