annotate ffmpeg/libavcodec/g729postfilter.h @ 13:844d341cf643 tip

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