lsp_lsf.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 : lsp_lsf.c
  11. * Purpose : Lsp_lsf: Transformation lsp to lsf
  12. * : Lsf_lsp: Transformation lsf to lsp
  13. *
  14. ********************************************************************************
  15. */
  16. /*
  17. ********************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. ********************************************************************************
  20. */
  21. #include "lsp_lsf.h"
  22. const char lsp_lsf_id[] = "@(#)$Id $" lsp_lsf_h;
  23. /*
  24. ********************************************************************************
  25. * INCLUDE FILES
  26. ********************************************************************************
  27. */
  28. #include "typedef.h"
  29. #include "basic_op.h"
  30. #include "count.h"
  31. /*
  32. ********************************************************************************
  33. * LOCAL VARIABLES AND TABLES
  34. ********************************************************************************
  35. */
  36. #include "lsp_lsf.tab" /* Look-up table for transformations */
  37. /*
  38. ********************************************************************************
  39. * PUBLIC PROGRAM CODE
  40. ********************************************************************************
  41. */
  42. /*************************************************************************
  43. *
  44. * FUNCTIONS: Lsp_lsf and Lsf_lsp
  45. *
  46. * PURPOSE:
  47. * Lsp_lsf: Transformation lsp to lsf
  48. * Lsf_lsp: Transformation lsf to lsp
  49. *
  50. * DESCRIPTION:
  51. * lsp[i] = cos(2*pi*lsf[i]) and lsf[i] = arccos(lsp[i])/(2*pi)
  52. *
  53. * The transformation from lsp[i] to lsf[i] and lsf[i] to lsp[i] are
  54. * approximated by a look-up table and interpolation.
  55. *
  56. *************************************************************************/
  57. void Lsf_lsp (
  58. Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
  59. Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
  60. Word16 m /* (i) : LPC order */
  61. )
  62. {
  63. Word16 i, ind, offset;
  64. Word32 L_tmp;
  65. for (i = 0; i < m; i++)
  66. {
  67. ind = shr_ex (lsf[i], 8); /* ind = b8-b15 of lsf[i] */
  68. offset = lsf[i] & 0x00ff; logic16 (); /* offset = b0-b7 of lsf[i] */
  69. /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */
  70. L_tmp = L_mult_ex (sub_ex (table[ind + 1], table[ind]), offset);
  71. lsp[i] = add_ex (table[ind], extract_l_ex (L_shr_ex (L_tmp, 9)));
  72. move16 ();
  73. }
  74. return;
  75. }
  76. void Lsp_lsf (
  77. Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
  78. Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
  79. Word16 m /* (i) : LPC order */
  80. )
  81. {
  82. Word16 i, ind;
  83. Word32 L_tmp;
  84. ind = 63; move16 (); /* begin at end of table -1 */
  85. for (i = m - 1; i >= 0; i--)
  86. {
  87. /* find value in table that is just greater than lsp[i] */
  88. test ();
  89. while (sub_ex (table[ind], lsp[i]) < 0)
  90. {
  91. ind--;
  92. test ();
  93. }
  94. /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
  95. slope[ind] )/4096 */
  96. L_tmp = L_mult_ex (sub_ex (lsp[i], table[ind]), slope[ind]);
  97. /*(lsp[i]-table[ind])*slope[ind])>>12*/
  98. lsf[i] = round_ex (L_shl_ex (L_tmp, 3)); move16 ();
  99. lsf[i] = add_ex (lsf[i], shl_ex (ind, 8)); move16 ();
  100. }
  101. return;
  102. }