lsp_az.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_az.c
  11. * Purpose : Converts from the line spectral pairs (LSP) to
  12. * : LP coefficients, for a 10th order filter.
  13. * Description :
  14. * - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
  15. * - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
  16. * - A(z) = ( F1(z) + F2(z) ) / 2
  17. *
  18. ********************************************************************************
  19. */
  20. /*
  21. ********************************************************************************
  22. * MODULE INCLUDE FILE AND VERSION ID
  23. ********************************************************************************
  24. */
  25. #include "lsp_az.h"
  26. const char lsp_az_id[] = "@(#)$Id $"
  27. lsp_az_h;
  28. /*
  29. ********************************************************************************
  30. * INCLUDE FILES
  31. ********************************************************************************
  32. */
  33. #include "typedef.h"
  34. #include "basic_op.h"
  35. #include "oper_32b.h"
  36. #include "count.h"
  37. /*
  38. ********************************************************************************
  39. * LOCAL VARIABLES AND TABLES
  40. ********************************************************************************
  41. */
  42. /*
  43. ********************************************************************************
  44. * LOCAL PROGRAM CODE
  45. ********************************************************************************
  46. */
  47. /*************************************************************************
  48. *
  49. * FUNCTION: Get_lsp_pol
  50. *
  51. * PURPOSE: Find the polynomial F1(z) or F2(z) from the LSPs.
  52. * If the LSP vector is passed at address 0 F1(z) is computed
  53. * and if it is passed at address 1 F2(z) is computed.
  54. *
  55. * DESCRIPTION:
  56. * This is performed by expanding the product polynomials:
  57. *
  58. * F1(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
  59. * i=0,2,4,6,8
  60. * F2(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
  61. * i=1,3,5,7,9
  62. *
  63. * where lsp[] is the LSP vector in the cosine domain.
  64. *
  65. * The expansion is performed using the following recursion:
  66. *
  67. * f[0] = 1
  68. * b = -2.0 * lsp[0]
  69. * f[1] = b
  70. * for i=2 to 5 do
  71. * b = -2.0 * lsp[2*i-2];
  72. * f[i] = b*f[i-1] + 2.0*f[i-2];
  73. * for j=i-1 down to 2 do
  74. * f[j] = f[j] + b*f[j-1] + f[j-2];
  75. * f[1] = f[1] + b;
  76. *
  77. *************************************************************************/
  78. static void Get_lsp_pol (Word16 *lsp, Word32 *f)
  79. {
  80. Word16 i, j, hi, lo;
  81. Word32 t0;
  82. /* f[0] = 1.0; */
  83. *f = L_mult_ex (4096, 2048); move32 ();
  84. f++; move32 ();
  85. *f = L_msu_ex ((Word32) 0, *lsp, 512); /* f[1] = -2.0 * lsp[0]; */
  86. f++; move32 ();
  87. lsp += 2; /* Advance lsp pointer */
  88. for (i = 2; i <= 5; i++)
  89. {
  90. *f = f[-2]; move32 ();
  91. for (j = 1; j < i; j++, f--)
  92. {
  93. L_Extract (f[-1], &hi, &lo);
  94. t0 = Mpy_32_16 (hi, lo, *lsp); /* t0 = f[-1] * lsp */
  95. t0 = L_shl_ex (t0, 1);
  96. *f = L_add_ex (*f, f[-2]); move32 (); /* *f += f[-2] */
  97. *f = L_sub_ex (*f, t0);move32 (); /* *f -= t0 */
  98. }
  99. *f = L_msu_ex (*f, *lsp, 512); move32 (); /* *f -= lsp<<9 */
  100. f += i; /* Advance f pointer */
  101. lsp += 2; /* Advance lsp pointer */
  102. }
  103. return;
  104. }
  105. /*
  106. ********************************************************************************
  107. * PUBLIC PROGRAM CODE
  108. ********************************************************************************
  109. */
  110. /*************************************************************************
  111. *
  112. * FUNCTION: Lsp_Az
  113. *
  114. * PURPOSE: Converts from the line spectral pairs (LSP) to
  115. * LP coefficients, for a 10th order filter.
  116. *
  117. * DESCRIPTION:
  118. * - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
  119. * - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
  120. * - A(z) = ( F1(z) + F2(z) ) / 2
  121. *
  122. *************************************************************************/
  123. void Lsp_Az (
  124. Word16 lsp[], /* (i) : line spectral frequencies */
  125. Word16 a[] /* (o) : predictor coefficients (order = 10) */
  126. )
  127. {
  128. Word16 i, j;
  129. Word32 f1[6], f2[6];
  130. Word32 t0;
  131. Get_lsp_pol (&lsp[0], f1);
  132. Get_lsp_pol (&lsp[1], f2);
  133. for (i = 5; i > 0; i--)
  134. {
  135. f1[i] = L_add_ex (f1[i], f1[i - 1]); move32 (); /* f1[i] += f1[i-1]; */
  136. f2[i] = L_sub_ex (f2[i], f2[i - 1]); move32 (); /* f2[i] -= f2[i-1]; */
  137. }
  138. a[0] = 4096; move16 ();
  139. for (i = 1, j = 10; i <= 5; i++, j--)
  140. {
  141. t0 = L_add_ex (f1[i], f2[i]); /* f1[i] + f2[i] */
  142. a[i] = extract_l_ex (L_shr_r_ex (t0, 13)); move16 ();
  143. t0 = L_sub_ex (f1[i], f2[i]); /* f1[i] - f2[i] */
  144. a[j] = extract_l_ex (L_shr_r_ex (t0, 13)); move16 ();
  145. }
  146. return;
  147. }