LPCdecode.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************
  2. iLBC Speech Coder ANSI-C Source Code
  3. LPC_decode.c
  4. Copyright (C) The Internet Society (2004).
  5. All Rights Reserved.
  6. ******************************************************************/
  7. #include <math.h>
  8. #include <string.h>
  9. #include "helpfun.h"
  10. #include "lsf.h"
  11. #include "iLBC_define.h"
  12. #include "constants.h"
  13. /*---------------------------------------------------------------*
  14. * interpolation of lsf coefficients for the decoder
  15. *--------------------------------------------------------------*/
  16. void LSFinterpolate2a_dec(
  17. float *a, /* (o) lpc coefficients for a sub-frame */
  18. float *lsf1, /* (i) first lsf coefficient vector */
  19. float *lsf2, /* (i) second lsf coefficient vector */
  20. float coef, /* (i) interpolation weight */
  21. int length /* (i) length of lsf vectors */
  22. ){
  23. float lsftmp[LPC_FILTERORDER];
  24. interpolate(lsftmp, lsf1, lsf2, coef, length);
  25. lsf2a(a, lsftmp);
  26. }
  27. /*---------------------------------------------------------------*
  28. * obtain dequantized lsf coefficients from quantization index
  29. *--------------------------------------------------------------*/
  30. void SimplelsfDEQ(
  31. float *lsfdeq, /* (o) dequantized lsf coefficients */
  32. int *index, /* (i) quantization index */
  33. int lpc_n /* (i) number of LPCs */
  34. ){
  35. int i, j, pos, cb_pos;
  36. /* decode first LSF */
  37. pos = 0;
  38. cb_pos = 0;
  39. for (i = 0; i < LSF_NSPLIT; i++) {
  40. for (j = 0; j < dim_lsfCbTbl[i]; j++) {
  41. lsfdeq[pos + j] = lsfCbTbl[cb_pos +
  42. (long)(index[i])*dim_lsfCbTbl[i] + j];
  43. }
  44. pos += dim_lsfCbTbl[i];
  45. cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
  46. }
  47. if (lpc_n>1) {
  48. /* decode last LSF */
  49. pos = 0;
  50. cb_pos = 0;
  51. for (i = 0; i < LSF_NSPLIT; i++) {
  52. for (j = 0; j < dim_lsfCbTbl[i]; j++) {
  53. lsfdeq[LPC_FILTERORDER + pos + j] =
  54. lsfCbTbl[cb_pos +
  55. (long)(index[LSF_NSPLIT + i])*
  56. dim_lsfCbTbl[i] + j];
  57. }
  58. pos += dim_lsfCbTbl[i];
  59. cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
  60. }
  61. }
  62. }
  63. /*----------------------------------------------------------------*
  64. * obtain synthesis and weighting filters form lsf coefficients
  65. *---------------------------------------------------------------*/
  66. void DecoderInterpolateLSF(
  67. float *syntdenum, /* (o) synthesis filter coefficients */
  68. float *weightdenum, /* (o) weighting denumerator
  69. coefficients */
  70. float *lsfdeq, /* (i) dequantized lsf coefficients */
  71. int length, /* (i) length of lsf coefficient vector */
  72. iLBC_Dec_Inst_t *iLBCdec_inst
  73. /* (i) the decoder state structure */
  74. ){
  75. int i, pos, lp_length;
  76. float lp[LPC_FILTERORDER + 1], *lsfdeq2;
  77. lsfdeq2 = lsfdeq + length;
  78. lp_length = length + 1;
  79. if (iLBCdec_inst->mode==30) {
  80. /* sub-frame 1: Interpolation between old and first */
  81. LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
  82. lsf_weightTbl_30ms[0], length);
  83. memcpy(syntdenum,lp,lp_length*sizeof(float));
  84. bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
  85. lp_length);
  86. /* sub-frames 2 to 6: interpolation between first
  87. and last LSF */
  88. pos = lp_length;
  89. for (i = 1; i < 6; i++) {
  90. LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
  91. lsf_weightTbl_30ms[i], length);
  92. memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
  93. bwexpand(weightdenum + pos, lp,
  94. LPC_CHIRP_WEIGHTDENUM, lp_length);
  95. pos += lp_length;
  96. }
  97. }
  98. else {
  99. pos = 0;
  100. for (i = 0; i < iLBCdec_inst->nsub; i++) {
  101. LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
  102. lsfdeq, lsf_weightTbl_20ms[i], length);
  103. memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
  104. bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
  105. lp_length);
  106. pos += lp_length;
  107. }
  108. }
  109. /* update memory */
  110. if (iLBCdec_inst->mode==30)
  111. memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
  112. length*sizeof(float));
  113. else
  114. memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
  115. length*sizeof(float));
  116. }