spstproc.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 : subframePostProc.c
  11. * Purpose : Subframe post processing
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "spstproc.h"
  21. const char spstproc_id[] = "@(#)$Id $" spstproc_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 "oper_32b.h"
  32. #include "count.h"
  33. #include "syn_filt.h"
  34. #include "cnst.h"
  35. /*
  36. ********************************************************************************
  37. * LOCAL VARIABLES AND TABLES
  38. ********************************************************************************
  39. */
  40. /*
  41. ********************************************************************************
  42. * PUBLIC PROGRAM CODE
  43. ********************************************************************************
  44. */
  45. int subframePostProc(
  46. Word16 *speech, /* i : speech segment */
  47. enum Mode mode, /* i : coder mode */
  48. Word16 i_subfr, /* i : Subframe nr */
  49. Word16 gain_pit, /* i : Pitch gain Q14 */
  50. Word16 gain_code, /* i : Decoded innovation gain */
  51. Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
  52. Word16 synth[], /* i : Local snthesis */
  53. Word16 xn[], /* i : Target vector for pitch search */
  54. Word16 code[], /* i : Fixed codebook exitation */
  55. Word16 y1[], /* i : Filtered adaptive exitation */
  56. Word16 y2[], /* i : Filtered fixed codebook excitation */
  57. Word16 *mem_syn, /* i/o : memory of synthesis filter */
  58. Word16 *mem_err, /* o : pointer to error signal */
  59. Word16 *mem_w0, /* o : memory of weighting filter */
  60. Word16 *exc, /* o : long term prediction residual */
  61. Word16 *sharp /* o : pitch sharpening value */
  62. )
  63. {
  64. Word16 i, j, k;
  65. Word16 temp;
  66. Word32 L_temp;
  67. Word16 tempShift;
  68. Word16 kShift;
  69. Word16 pitch_fac;
  70. test ();
  71. if (sub_ex(mode, MR122) != 0)
  72. {
  73. tempShift = 1; move16 ();
  74. kShift = 2; move16 ();
  75. pitch_fac = gain_pit; move16 ();
  76. }
  77. else
  78. {
  79. tempShift = 2; move16 ();
  80. kShift = 4; move16 ();
  81. pitch_fac = shr_ex (gain_pit, 1);
  82. }
  83. /*------------------------------------------------------------*
  84. * - Update pitch sharpening "sharp" with quantized gain_pit *
  85. *------------------------------------------------------------*/
  86. *sharp = gain_pit; move16 ();
  87. test ();
  88. if (sub_ex(*sharp, SHARPMAX) > 0)
  89. {
  90. *sharp = SHARPMAX; move16 ();
  91. }
  92. /*------------------------------------------------------*
  93. * - Find the total excitation *
  94. * - find synthesis speech corresponding to exc[] *
  95. * - update filters memories for finding the target *
  96. * vector in the next subframe *
  97. * (update error[-m..-1] and mem_w_err[]) *
  98. *------------------------------------------------------*/
  99. for (i = 0; i < L_SUBFR; i++) {
  100. /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */
  101. /*
  102. * 12k2 others
  103. * ---------------------------------
  104. * exc Q0 Q0
  105. * gain_pit Q14 Q14
  106. * pitch_fac Q13 Q14
  107. * product: Q14 Q15
  108. *
  109. * code Q12 Q13
  110. * gain_code Q1 Q1
  111. * product Q14 Q15
  112. * sum Q14 Q15
  113. *
  114. * tempShift 2 1
  115. * sum<<tempShift Q16 Q16
  116. * result -> exc Q0 Q0
  117. */
  118. L_temp = L_mult_ex (exc[i + i_subfr], pitch_fac);
  119. L_temp = L_mac_ex (L_temp, code[i], gain_code);
  120. L_temp = L_shl_ex (L_temp, tempShift);
  121. exc[i + i_subfr] = round_ex (L_temp); move16 ();
  122. }
  123. Syn_filt(Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR,
  124. mem_syn, 1);
  125. for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++) {
  126. mem_err[j] = sub_ex(speech[i_subfr + i],
  127. synth[i_subfr + i]); move16 ();
  128. /*
  129. * 12k2 others
  130. * ---------------------------------
  131. * y1 Q0 Q0
  132. * gain_pit Q14 Q14
  133. * product Q15 Q15
  134. * shifted prod. Q16 Q16
  135. * temp Q0 Q0
  136. *
  137. * y2 Q10 Q12
  138. * gain_code Q1 Q1
  139. * product Q12 Q14
  140. * kshift 4 2
  141. * shifted prod. Q16 Q16
  142. * k Q0 Q0
  143. * mem_w0,xn,sum Q0 Q0
  144. */
  145. temp = extract_h_ex(L_shl_ex(L_mult_ex(y1[i], gain_pit), 1));
  146. k = extract_h_ex(L_shl_ex(L_mult_ex(y2[i], gain_code), kShift));
  147. mem_w0[j] = sub_ex(xn[i], add_ex(temp, k)); move16 ();
  148. }
  149. return 0;
  150. }