hp_max.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 : hp_max.c
  11. * Purpose : Find the maximum correlation of scal_sig[] in a given
  12. * delay range.
  13. *
  14. ********************************************************************************
  15. */
  16. /*
  17. ********************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. ********************************************************************************
  20. */
  21. #include "hp_max.h"
  22. const char hp_max_id[] = "@(#)$Id $" hp_max_h;
  23. /*
  24. ********************************************************************************
  25. * INCLUDE FILES
  26. ********************************************************************************
  27. */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include "typedef.h"
  31. #include "basic_op.h"
  32. #include "oper_32b.h"
  33. #include "count.h"
  34. #include "cnst.h"
  35. /*
  36. ********************************************************************************
  37. * PUBLIC PROGRAM CODE
  38. ********************************************************************************
  39. */
  40. Word16 hp_max (
  41. Word32 corr[], /* i : correlation vector. */
  42. Word16 scal_sig[], /* i : scaled signal. */
  43. Word16 L_frame, /* i : length of frame to compute pitch */
  44. Word16 lag_max, /* i : maximum lag */
  45. Word16 lag_min, /* i : minimum lag */
  46. Word16 *cor_hp_max) /* o : max high-pass filtered norm. correlation */
  47. {
  48. Word16 i;
  49. Word16 *p, *p1;
  50. Word32 max, t0, t1;
  51. Word16 max16, t016, cor_max;
  52. Word16 shift, shift1, shift2;
  53. max = MIN_32; move32 ();
  54. t0 = 0L; move32 ();
  55. for (i = lag_max-1; i > lag_min; i--)
  56. {
  57. /* high-pass filtering */
  58. t0 = L_sub_ex (L_sub_ex(L_shl_ex(corr[-i], 1), corr[-i-1]), corr[-i+1]);
  59. t0 = L_abs_ex (t0);
  60. test ();
  61. if (L_sub_ex (t0, max) >= 0)
  62. {
  63. max = t0; move32 ();
  64. }
  65. }
  66. /* compute energy */
  67. p = scal_sig; move16 ();
  68. p1 = &scal_sig[0]; move16 ();
  69. t0 = 0L; move32 ();
  70. for (i = 0; i < L_frame; i++, p++, p1++)
  71. {
  72. t0 = L_mac_ex (t0, *p, *p1);
  73. }
  74. p = scal_sig; move16 ();
  75. p1 = &scal_sig[-1]; move16 ();
  76. t1 = 0L; move32 ();
  77. for (i = 0; i < L_frame; i++, p++, p1++)
  78. {
  79. t1 = L_mac_ex (t1, *p, *p1);
  80. }
  81. /* high-pass filtering */
  82. t0 = L_sub_ex(L_shl_ex(t0, 1), L_shl_ex(t1, 1));
  83. t0 = L_abs_ex (t0);
  84. /* max/t0 */
  85. shift1 = sub_ex(norm_l_ex(max), 1);
  86. max16 = extract_h_ex(L_shl_ex(max, shift1));
  87. shift2 = norm_l_ex(t0);
  88. t016 = extract_h_ex(L_shl_ex(t0, shift2));
  89. test ();
  90. if (t016 != 0)
  91. {
  92. cor_max = div_s(max16, t016);
  93. }
  94. else
  95. {
  96. cor_max = 0; move16 ();
  97. }
  98. shift = sub_ex(shift1, shift2);
  99. test ();
  100. if (shift >= 0)
  101. {
  102. *cor_hp_max = shr_ex(cor_max, shift); move16 (); /* Q15 */
  103. }
  104. else
  105. {
  106. *cor_hp_max = shl_ex(cor_max, negate_ex(shift)); move16 (); /* Q15 */
  107. }
  108. return 0;
  109. }