g729postfilter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * G.729, G729 Annex D postfilter
  3. * Copyright (c) 2008 Vladimir Voroshilov
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef FFMPEG_G729POSTFILTER_H
  22. #define FFMPEG_G729POSTFILTER_H
  23. #include <stdint.h>
  24. /**
  25. * tilt compensation factor (G.729, k1>0)
  26. * 0.2 in Q15
  27. */
  28. #define G729_TILT_FACTOR_PLUS 6554
  29. /**
  30. * tilt compensation factor (G.729, k1<0)
  31. * 0.9 in Q15
  32. */
  33. #define G729_TILT_FACTOR_MINUS 29491
  34. /* 4.2.2 */
  35. #define FORMANT_PP_FACTOR_NUM 18022 //0.55 in Q15
  36. #define FORMANT_PP_FACTOR_DEN 22938 //0.70 in Q15
  37. /**
  38. * gain adjustment factor (G.729, 4.2.4)
  39. * 0.9875 in Q15
  40. */
  41. #define G729_AGC_FACTOR 32358
  42. #define G729_AGC_FAC1 (32768-G729_AGC_FACTOR)
  43. /**
  44. * 1.0 / (1.0 + 0.5) in Q15
  45. * where 0.5 is the minimum value of
  46. * weight factor, controlling amount of long-term postfiltering
  47. */
  48. #define MIN_LT_FILT_FACTOR_A 21845
  49. /**
  50. * Short interpolation filter length
  51. */
  52. #define SHORT_INT_FILT_LEN 2
  53. /**
  54. * Long interpolation filter length
  55. */
  56. #define LONG_INT_FILT_LEN 8
  57. /**
  58. * Number of analyzed fractional pitch delays in second stage of long-term
  59. * postfilter
  60. */
  61. #define ANALYZED_FRAC_DELAYS 7
  62. /**
  63. * Amount of past residual signal data stored in buffer
  64. */
  65. #define RES_PREV_DATA_SIZE (PITCH_DELAY_MAX + LONG_INT_FILT_LEN + 1)
  66. /**
  67. * \brief Signal postfiltering (4.2)
  68. * \param dsp initialized DSP context
  69. * \param ht_prev_data [in/out] (Q12) pointer to variable receiving tilt
  70. * compensation filter data from previous subframe
  71. * \param voicing [in/out] (Q0) pointer to variable receiving voicing decision
  72. * \param lp_filter_coeffs (Q12) LP filter coefficients
  73. * \param pitch_delay_int integer part of the pitch delay
  74. * \param residual [in/out] (Q0) residual signal buffer (used in long-term postfilter)
  75. * \param res_filter_data [in/out] (Q0) speech data of previous subframe
  76. * \param pos_filter_data [in/out] (Q0) previous speech data for short-term postfilter
  77. * \param speech [in/out] (Q0) signal buffer
  78. * \param subframe_size size of subframe
  79. *
  80. * Filtering has the following stages:
  81. * Long-term postfilter (4.2.1)
  82. * Short-term postfilter (4.2.2).
  83. * Tilt-compensation (4.2.3)
  84. */
  85. void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing,
  86. const int16_t *lp_filter_coeffs, int pitch_delay_int,
  87. int16_t* residual, int16_t* res_filter_data,
  88. int16_t* pos_filter_data, int16_t *speech,
  89. int subframe_size);
  90. /**
  91. * \brief Adaptive gain control (4.2.4)
  92. * \param gain_before (Q0) gain of speech before applying postfilters
  93. * \param gain_after (Q0) gain of speech after applying postfilters
  94. * \param speech [in/out] (Q0) signal buffer
  95. * \param subframe_size length of subframe
  96. * \param gain_prev (Q12) previous value of gain coefficient
  97. *
  98. * \return (Q12) last value of gain coefficient
  99. */
  100. int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech,
  101. int subframe_size, int16_t gain_prev);
  102. #endif // FFMPEG_G729POSTFILTER_H