yading@10: /* yading@10: * G.729, G729 Annex D postfilter yading@10: * Copyright (c) 2008 Vladimir Voroshilov yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: #ifndef FFMPEG_G729POSTFILTER_H yading@10: #define FFMPEG_G729POSTFILTER_H yading@10: yading@10: #include yading@10: #include "dsputil.h" yading@10: yading@10: /** yading@10: * tilt compensation factor (G.729, k1>0) yading@10: * 0.2 in Q15 yading@10: */ yading@10: #define G729_TILT_FACTOR_PLUS 6554 yading@10: yading@10: /** yading@10: * tilt compensation factor (G.729, k1<0) yading@10: * 0.9 in Q15 yading@10: */ yading@10: #define G729_TILT_FACTOR_MINUS 29491 yading@10: yading@10: /* 4.2.2 */ yading@10: #define FORMANT_PP_FACTOR_NUM 18022 //0.55 in Q15 yading@10: #define FORMANT_PP_FACTOR_DEN 22938 //0.70 in Q15 yading@10: yading@10: /** yading@10: * gain adjustment factor (G.729, 4.2.4) yading@10: * 0.9875 in Q15 yading@10: */ yading@10: #define G729_AGC_FACTOR 32358 yading@10: #define G729_AGC_FAC1 (32768-G729_AGC_FACTOR) yading@10: yading@10: /** yading@10: * 1.0 / (1.0 + 0.5) in Q15 yading@10: * where 0.5 is the minimum value of yading@10: * weight factor, controlling amount of long-term postfiltering yading@10: */ yading@10: #define MIN_LT_FILT_FACTOR_A 21845 yading@10: yading@10: /** yading@10: * Short interpolation filter length yading@10: */ yading@10: #define SHORT_INT_FILT_LEN 2 yading@10: yading@10: /** yading@10: * Long interpolation filter length yading@10: */ yading@10: #define LONG_INT_FILT_LEN 8 yading@10: yading@10: /** yading@10: * Number of analyzed fractional pitch delays in second stage of long-term yading@10: * postfilter yading@10: */ yading@10: #define ANALYZED_FRAC_DELAYS 7 yading@10: yading@10: /** yading@10: * Amount of past residual signal data stored in buffer yading@10: */ yading@10: #define RES_PREV_DATA_SIZE (PITCH_DELAY_MAX + LONG_INT_FILT_LEN + 1) yading@10: yading@10: /** yading@10: * \brief Signal postfiltering (4.2) yading@10: * \param dsp initialized DSP context yading@10: * \param ht_prev_data [in/out] (Q12) pointer to variable receiving tilt yading@10: * compensation filter data from previous subframe yading@10: * \param voicing [in/out] (Q0) pointer to variable receiving voicing decision yading@10: * \param lp_filter_coeffs (Q12) LP filter coefficients yading@10: * \param pitch_delay_int integer part of the pitch delay yading@10: * \param residual [in/out] (Q0) residual signal buffer (used in long-term postfilter) yading@10: * \param res_filter_data [in/out] (Q0) speech data of previous subframe yading@10: * \param pos_filter_data [in/out] (Q0) previous speech data for short-term postfilter yading@10: * \param speech [in/out] (Q0) signal buffer yading@10: * \param subframe_size size of subframe yading@10: * yading@10: * Filtering has the following stages: yading@10: * Long-term postfilter (4.2.1) yading@10: * Short-term postfilter (4.2.2). yading@10: * Tilt-compensation (4.2.3) yading@10: */ yading@10: void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing, yading@10: const int16_t *lp_filter_coeffs, int pitch_delay_int, yading@10: int16_t* residual, int16_t* res_filter_data, yading@10: int16_t* pos_filter_data, int16_t *speech, yading@10: int subframe_size); yading@10: yading@10: /** yading@10: * \brief Adaptive gain control (4.2.4) yading@10: * \param gain_before (Q0) gain of speech before applying postfilters yading@10: * \param gain_after (Q0) gain of speech after applying postfilters yading@10: * \param speech [in/out] (Q0) signal buffer yading@10: * \param subframe_size length of subframe yading@10: * \param gain_prev (Q12) previous value of gain coefficient yading@10: * yading@10: * \return (Q12) last value of gain coefficient yading@10: */ yading@10: int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech, yading@10: int subframe_size, int16_t gain_prev); yading@10: yading@10: #endif // FFMPEG_G729POSTFILTER_H