ltp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifndef LTP_H
  31. #define LTP_H
  32. #include "speex/speex_bits.h"
  33. #include "arch.h"
  34. /** LTP parameters. */
  35. typedef struct {
  36. const signed char *gain_cdbk;
  37. int gain_bits;
  38. int pitch_bits;
  39. } ltp_params;
  40. #ifdef FIXED_POINT
  41. #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)))
  42. #else
  43. #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]))
  44. #endif
  45. spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len);
  46. 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);
  47. /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
  48. int pitch_search_3tap(
  49. spx_word16_t target[], /* Target vector */
  50. spx_word16_t *sw,
  51. spx_coef_t ak[], /* LPCs for this subframe */
  52. spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
  53. spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
  54. spx_sig_t exc[], /* Overlapping codebook */
  55. const void *par,
  56. int start, /* Smallest pitch value allowed */
  57. int end, /* Largest pitch value allowed */
  58. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  59. int p, /* Number of LPC coeffs */
  60. int nsf, /* Number of samples in subframe */
  61. SpeexBits *bits,
  62. char *stack,
  63. spx_word16_t *exc2,
  64. spx_word16_t *r,
  65. int complexity,
  66. int cdbk_offset,
  67. int plc_tuning,
  68. spx_word32_t *cumul_gain
  69. );
  70. /*Unquantize adaptive codebook and update pitch contribution*/
  71. void pitch_unquant_3tap(
  72. spx_word16_t exc[], /* Input excitation */
  73. spx_word32_t exc_out[], /* Output excitation */
  74. int start, /* Smallest pitch value allowed */
  75. int end, /* Largest pitch value allowed */
  76. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  77. const void *par,
  78. int nsf, /* Number of samples in subframe */
  79. int *pitch_val,
  80. spx_word16_t *gain_val,
  81. SpeexBits *bits,
  82. char *stack,
  83. int lost,
  84. int subframe_offset,
  85. spx_word16_t last_pitch_gain,
  86. int cdbk_offset
  87. );
  88. /** Forced pitch delay and gain */
  89. int forced_pitch_quant(
  90. spx_word16_t target[], /* Target vector */
  91. spx_word16_t *sw,
  92. spx_coef_t ak[], /* LPCs for this subframe */
  93. spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
  94. spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
  95. spx_sig_t exc[], /* Excitation */
  96. const void *par,
  97. int start, /* Smallest pitch value allowed */
  98. int end, /* Largest pitch value allowed */
  99. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  100. int p, /* Number of LPC coeffs */
  101. int nsf, /* Number of samples in subframe */
  102. SpeexBits *bits,
  103. char *stack,
  104. spx_word16_t *exc2,
  105. spx_word16_t *r,
  106. int complexity,
  107. int cdbk_offset,
  108. int plc_tuning,
  109. spx_word32_t *cumul_gain
  110. );
  111. /** Unquantize forced pitch delay and gain */
  112. void forced_pitch_unquant(
  113. spx_word16_t exc[], /* Input excitation */
  114. spx_word32_t exc_out[], /* Output excitation */
  115. int start, /* Smallest pitch value allowed */
  116. int end, /* Largest pitch value allowed */
  117. spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */
  118. const void *par,
  119. int nsf, /* Number of samples in subframe */
  120. int *pitch_val,
  121. spx_word16_t *gain_val,
  122. SpeexBits *bits,
  123. char *stack,
  124. int lost,
  125. int subframe_offset,
  126. spx_word16_t last_pitch_gain,
  127. int cdbk_offset
  128. );
  129. #endif /* LTP_H */