lsfwt.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. ********************************************************************************
  3. *
  4. * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
  5. * R99 Version 3.3.0
  6. * REL-4 Version 4.1.0
  7. *
  8. ********************************************************************************
  9. *
  10. * File : lsfwt.c
  11. * Purpose : Compute LSF weighting factors
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "lsfwt.h"
  21. const char lsfwt_id[] = "@(#)$Id $" lsfwt_h;
  22. /*
  23. ********************************************************************************
  24. * INCLUDE FILES
  25. ********************************************************************************
  26. */
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "typedef.h"
  30. #include "basic_op.h"
  31. #include "count.h"
  32. #include "cnst.h"
  33. /*
  34. ********************************************************************************
  35. * PUBLIC PROGRAM CODE
  36. ********************************************************************************
  37. */
  38. /****************************************************
  39. *
  40. * FUNCTION Lsf_wt *
  41. * *
  42. ****************************************************
  43. * Compute LSF weighting factors *
  44. * *
  45. * d[i] = lsf[i+1] - lsf[i-1] *
  46. * *
  47. * The weighting factors are approximated by two line segment. *
  48. * *
  49. * First segment passes by the following 2 points: *
  50. * *
  51. * d[i] = 0Hz wf[i] = 3.347 *
  52. * d[i] = 450Hz wf[i] = 1.8 *
  53. * *
  54. * Second segment passes by the following 2 points: *
  55. * *
  56. * d[i] = 450Hz wf[i] = 1.8 *
  57. * d[i] = 1500Hz wf[i] = 1.0 *
  58. * *
  59. * if( d[i] < 450Hz ) *
  60. * wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) * d[i] *
  61. * else *
  62. * wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) * (d[i] - 450) *
  63. * *
  64. * *
  65. * if( d[i] < 1843) *
  66. * wf[i] = 3427 - (28160*d[i])>>15 *
  67. * else *
  68. * wf[i] = 1843 - (6242*(d[i]-1843))>>15 *
  69. * *
  70. *--------------------------------------------------------------------------*/
  71. void Lsf_wt (
  72. Word16 *lsf, /* input : LSF vector */
  73. Word16 *wf) /* output: square of weighting factors */
  74. {
  75. Word16 temp;
  76. Word16 i;
  77. /* wf[0] = lsf[1] - 0 */
  78. wf[0] = lsf[1]; move16 ();
  79. for (i = 1; i < 9; i++)
  80. {
  81. wf[i] = sub_ex (lsf[i + 1], lsf[i - 1]); move16 ();
  82. }
  83. /* wf[9] = 0.5 - lsf[8] */
  84. wf[9] = sub_ex (16384, lsf[8]);move16 ();
  85. for (i = 0; i < 10; i++)
  86. {
  87. temp = sub_ex (wf[i], 1843);
  88. test ();
  89. if (temp < 0)
  90. {
  91. wf[i] = sub_ex (3427, mult_ex (wf[i], 28160)); move16 ();
  92. }
  93. else
  94. {
  95. wf[i] = sub_ex (1843, mult_ex (temp, 6242)); move16 ();
  96. }
  97. wf[i] = shl_ex (wf[i], 3); move16 ();
  98. }
  99. return;
  100. }