Changeset 823 for pjproject/trunk/pjmedia/src/pjmedia-codec/speex/ltp.c
- Timestamp:
- Nov 23, 2006 10:19:46 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/speex/ltp.c
r641 r823 1 /* Copyright (C) 2002 Jean-Marc Valin1 /* Copyright (C) 2002-2006 Jean-Marc Valin 2 2 File: ltp.c 3 3 Long-Term Prediction functions … … 153 153 154 154 #ifndef OVERRIDE_COMPUTE_PITCH_ERROR 155 PJ_INLINE(spx_word32_t)compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control)155 static inline spx_word32_t compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control) 156 156 { 157 157 spx_word32_t sum = 0; … … 178 178 VARDECL(spx_word32_t *corr); 179 179 VARDECL(spx_word32_t *energy); 180 180 #ifdef FIXED_POINT 181 int scaledown = 0; 182 #endif 183 181 184 ALLOC(best_score, N, spx_word32_t); 182 185 ALLOC(best_ener, N, spx_word32_t); … … 190 193 pitch[i]=start; 191 194 } 192 195 #ifdef FIXED_POINT 196 for (i=-end;i<len;i++) 197 { 198 if (ABS16(sw[i])>16383) 199 { 200 scaledown=1; 201 break; 202 } 203 } 204 /* If the weighted input is close to saturation, then we scale it down */ 205 if (scaledown) 206 { 207 for (i=-end;i<len;i++) 208 { 209 sw[i]=SHR16(sw[i],1); 210 } 211 } 212 #endif 193 213 energy[0]=inner_prod(sw-start, sw-start, len); 194 214 e0=inner_prod(sw, sw, len); … … 202 222 203 223 pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack); 224 #ifdef FIXED_POINT 225 /* If we scaled weighted input down, we need to scale it up again (OK, so we've just lost the LSB, who cares?) */ 226 if (scaledown) 227 { 228 for (i=-end;i<len;i++) 229 { 230 sw[i]=SHL16(sw[i],1); 231 } 232 } 233 #endif 204 234 205 235 /* FIXME: Fixed-point and floating-point code should be merged */ … … 343 373 int *cdbk_index, 344 374 int plc_tuning, 345 spx_word32_t cumul_gain 375 spx_word32_t cumul_gain, 376 int scaledown 346 377 ) 347 378 { … … 367 398 x[2]=tmp1+2*nsf; 368 399 400 for (j=0;j<nsf;j++) 401 new_target[j] = target[j]; 402 369 403 { 370 404 VARDECL(spx_mem_t *mm); … … 380 414 e[j]=0; 381 415 } 416 #ifdef FIXED_POINT 417 /* Scale target and excitation down if needed (avoiding overflow) */ 418 if (scaledown) 419 { 420 for (j=0;j<nsf;j++) 421 e[j] = SHR16(e[j],1); 422 for (j=0;j<nsf;j++) 423 new_target[j] = SHR16(new_target[j],1); 424 } 425 #endif 382 426 for (j=0;j<p;j++) 383 427 mm[j] = 0; … … 392 436 { 393 437 spx_word16_t e0=exc2[-pitch-1+i]; 438 #ifdef FIXED_POINT 439 /* Scale excitation down if needed (avoiding overflow) */ 440 if (scaledown) 441 e0 = SHR16(e0,1); 442 #endif 394 443 x[i][0]=MULT16_16_Q14(r[0], e0); 395 444 for (j=0;j<nsf-1;j++) … … 398 447 399 448 for (i=0;i<3;i++) 400 corr[i]=inner_prod(x[i], target,nsf);449 corr[i]=inner_prod(x[i],new_target,nsf); 401 450 for (i=0;i<3;i++) 402 451 for (j=0;j<=i;j++) … … 479 528 spx_word32_t tmp = ADD32(ADD32(MULT16_16(gain[0],x[2][i]),MULT16_16(gain[1],x[1][i])), 480 529 MULT16_16(gain[2],x[0][i])); 481 new_target[i] = SUB16( target[i], EXTRACT16(PSHR32(tmp,6)));530 new_target[i] = SUB16(new_target[i], EXTRACT16(PSHR32(tmp,6))); 482 531 } 483 532 err = inner_prod(new_target, new_target, nsf); … … 521 570 const signed char *gain_cdbk; 522 571 int gain_cdbk_size; 523 572 int scaledown=0; 573 524 574 VARDECL(int *nbest); 525 575 … … 546 596 } 547 597 598 #ifdef FIXED_POINT 599 /* Check if we need to scale everything down in the pitch search to avoid overflows */ 600 for (i=0;i<nsf;i++) 601 { 602 if (ABS16(target[i])>16383) 603 { 604 scaledown=1; 605 break; 606 } 607 } 608 for (i=-end;i<nsf;i++) 609 { 610 if (ABS16(exc2[i])>16383) 611 { 612 scaledown=1; 613 break; 614 } 615 } 616 #endif 548 617 if (N>end-start+1) 549 618 N=end-start+1; … … 563 632 exc[j]=0; 564 633 err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, gain_cdbk, gain_cdbk_size, pitch, p, nsf, 565 bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain );634 bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain, scaledown); 566 635 if (err<best_err || best_err<0) 567 636 { … … 589 658 for (i=0;i<nsf;i++) 590 659 target[i]=best_target[i]; 591 660 #ifdef FIXED_POINT 661 /* Scale target back up if needed */ 662 if (scaledown) 663 { 664 for (i=0;i<nsf;i++) 665 target[i]=SHL16(target[i],1); 666 } 667 #endif 592 668 return pitch; 593 669 }
Note: See TracChangeset
for help on using the changeset viewer.