ltp.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Copyright (C) 2002 Jean-Marc Valin */
  2. /**
  3. @file ltp.h
  4. @brief Long-Term Prediction functions
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <speex/speex_bits.h>
  31. #include "arch.h"
  32. /** LTP parameters. */
  33. typedef struct {
  34. const signed char *gain_cdbk;
  35. int gain_bits;
  36. int pitch_bits;
  37. } ltp_params;
  38. #ifdef FIXED_POINT
  39. #define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -SHR16(g[0],1)) + (g[2]>0 ? g[2] : -SHR16(g[2],1)))
  40. #else
  41. #define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -.5*g[0]) + (g[2]>0 ? g[2] : -.5*g[2]))
  42. #endif
  43. spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len);
  44. void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack);
  45. void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack);
  46. /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
  47. int pitch_search_3tap(
  48. spx_word16_t target[], /* Target vector */
  49. spx_word16_t *sw,
  50. spx_coef_t ak[], /* LPCs for this subframe */
  51. spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
  52. spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
  53. spx_sig_t exc[], /* Overlapping codebook */
  54. const void *par,
  55. int start, /* Smallest pitch value allowed */
  56. int end, /* Largest pitch value allowed */
  57. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  58. int p, /* Number of LPC coeffs */
  59. int nsf, /* Number of samples in subframe */
  60. SpeexBits *bits,
  61. char *stack,
  62. spx_word16_t *exc2,
  63. spx_word16_t *r,
  64. int complexity,
  65. int cdbk_offset,
  66. int plc_tuning,
  67. spx_word32_t *cumul_gain
  68. );
  69. /*Unquantize adaptive codebook and update pitch contribution*/
  70. void pitch_unquant_3tap(
  71. spx_word16_t exc[], /* Input excitation */
  72. spx_word32_t exc_out[], /* Output excitation */
  73. int start, /* Smallest pitch value allowed */
  74. int end, /* Largest pitch value allowed */
  75. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  76. const void *par,
  77. int nsf, /* Number of samples in subframe */
  78. int *pitch_val,
  79. spx_word16_t *gain_val,
  80. SpeexBits *bits,
  81. char *stack,
  82. int lost,
  83. int subframe_offset,
  84. spx_word16_t last_pitch_gain,
  85. int cdbk_offset
  86. );
  87. /** Forced pitch delay and gain */
  88. int forced_pitch_quant(
  89. spx_word16_t target[], /* Target vector */
  90. spx_word16_t *sw,
  91. spx_coef_t ak[], /* LPCs for this subframe */
  92. spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
  93. spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
  94. spx_sig_t exc[], /* Excitation */
  95. const void *par,
  96. int start, /* Smallest pitch value allowed */
  97. int end, /* Largest pitch value allowed */
  98. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  99. int p, /* Number of LPC coeffs */
  100. int nsf, /* Number of samples in subframe */
  101. SpeexBits *bits,
  102. char *stack,
  103. spx_word16_t *exc2,
  104. spx_word16_t *r,
  105. int complexity,
  106. int cdbk_offset,
  107. int plc_tuning,
  108. spx_word32_t *cumul_gain
  109. );
  110. /** Unquantize forced pitch delay and gain */
  111. void forced_pitch_unquant(
  112. spx_word16_t exc[], /* Input excitation */
  113. spx_word32_t exc_out[], /* Output excitation */
  114. int start, /* Smallest pitch value allowed */
  115. int end, /* Largest pitch value allowed */
  116. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  117. const void *par,
  118. int nsf, /* Number of samples in subframe */
  119. int *pitch_val,
  120. spx_word16_t *gain_val,
  121. SpeexBits *bits,
  122. char *stack,
  123. int lost,
  124. int subframe_offset,
  125. spx_word16_t last_pitch_gain,
  126. int cdbk_offset
  127. );