spreproc.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 : spreproc.c
  11. * Purpose : Subframe preprocessing
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "spreproc.h"
  21. const char spreproc_id[] = "@(#)$Id $" spreproc_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 "weight_a.h"
  33. #include "syn_filt.h"
  34. #include "residu.h"
  35. #include "copy.h"
  36. #include "count.h"
  37. /*
  38. ********************************************************************************
  39. * PUBLIC PROGRAM CODE
  40. ********************************************************************************
  41. */
  42. int subframePreProc(
  43. enum Mode mode, /* i : coder mode */
  44. const Word16 gamma1[], /* i : spectral exp. factor 1 */
  45. const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
  46. const Word16 gamma2[], /* i : spectral exp. factor 2 */
  47. Word16 *A, /* i : A(z) unquantized for the 4 subframes */
  48. Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
  49. Word16 *speech, /* i : speech segment */
  50. Word16 *mem_err, /* i : pointer to error signal */
  51. Word16 *mem_w0, /* i : memory of weighting filter */
  52. Word16 *zero, /* i : pointer to zero vector */
  53. Word16 ai_zero[], /* o : history of weighted synth. filter */
  54. Word16 exc[], /* o : long term prediction residual */
  55. Word16 h1[], /* o : impulse response */
  56. Word16 xn[], /* o : target vector for pitch search */
  57. Word16 res2[], /* o : long term prediction residual */
  58. Word16 error[] /* o : error of LPC synthesis filter */
  59. )
  60. {
  61. Word16 i;
  62. Word16 Ap1[MP1]; /* A(z) with spectral expansion */
  63. Word16 Ap2[MP1]; /* A(z) with spectral expansion */
  64. const Word16 *g1; /* Pointer to correct gammma1 vector */
  65. /*---------------------------------------------------------------*
  66. * mode specific pointer to gamma1 values *
  67. *---------------------------------------------------------------*/
  68. test (); test ();
  69. if ( sub_ex(mode, MR122) == 0 || sub_ex(mode, MR102) == 0 )
  70. {
  71. g1 = gamma1_12k2; move16 ();
  72. }
  73. else
  74. {
  75. g1 = gamma1; move16 ();
  76. }
  77. /*---------------------------------------------------------------*
  78. * Find the weighted LPC coefficients for the weighting filter. *
  79. *---------------------------------------------------------------*/
  80. Weight_Ai(A, g1, Ap1);
  81. Weight_Ai(A, gamma2, Ap2);
  82. /*---------------------------------------------------------------*
  83. * Compute impulse response, h1[], of weighted synthesis filter *
  84. *---------------------------------------------------------------*/
  85. for (i = 0; i <= M; i++)
  86. {
  87. ai_zero[i] = Ap1[i]; move16 ();
  88. }
  89. Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0);
  90. Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0);
  91. /*------------------------------------------------------------------------*
  92. * *
  93. * Find the target vector for pitch search: *
  94. * *
  95. *------------------------------------------------------------------------*/
  96. /* LPC residual */
  97. Residu(Aq, speech, res2, L_SUBFR);
  98. Copy(res2, exc, L_SUBFR);
  99. Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0);
  100. Residu(Ap1, error, xn, L_SUBFR);
  101. /* target signal xn[]*/
  102. Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0);
  103. return 0;
  104. }