FFmpeg
Macros | Functions | Variables
g729postfilter.c File Reference
#include <stdint.h>
#include <string.h>
#include "libavutil/common.h"
#include "libavutil/intmath.h"
#include "audiodsp.h"
#include "g729.h"
#include "g729postfilter.h"
#include "celp_math.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "celp_filters.h"
#include "mathops.h"

Go to the source code of this file.

Macros

#define FRAC_BITS   15
 

Functions

static void residual_filter (int16_t *out, const int16_t *filter_coeffs, const int16_t *in, int subframe_size)
 Residual signal calculation (4.2.1 if G.729) More...
 
static int16_t long_term_filter (AudioDSPContext *adsp, int pitch_delay_int, const int16_t *residual, int16_t *residual_filt, int subframe_size)
 long-term postfilter (4.2.1) More...
 
static int16_t get_tilt_comp (AudioDSPContext *adsp, int16_t *lp_gn, const int16_t *lp_gd, int16_t *speech, int subframe_size)
 Calculate reflection coefficient for tilt compensation filter (4.2.3). More...
 
static int16_t apply_tilt_comp (int16_t *out, int16_t *res_pst, int refl_coeff, int subframe_size, int16_t ht_prev_data)
 Apply tilt compensation filter (4.2.3). More...
 
void ff_g729_postfilter (AudioDSPContext *adsp, int16_t *ht_prev_data, int *voicing, const int16_t *lp_filter_coeffs, int pitch_delay_int, int16_t *residual, int16_t *res_filter_data, int16_t *pos_filter_data, int16_t *speech, int subframe_size)
 Signal postfiltering (4.2) More...
 
int16_t ff_g729_adaptive_gain_control (int gain_before, int gain_after, int16_t *speech, int subframe_size, int16_t gain_prev)
 Adaptive gain control (4.2.4) More...
 

Variables

static const int16_t ff_g729_interp_filt_short [(ANALYZED_FRAC_DELAYS+1) *SHORT_INT_FILT_LEN]
 short interpolation filter (of length 33, according to spec) for computing signal with non-integer delay More...
 
static const int16_t ff_g729_interp_filt_long [(ANALYZED_FRAC_DELAYS+1) *LONG_INT_FILT_LEN]
 long interpolation filter (of length 129, according to spec) for computing signal with non-integer delay More...
 
static const int16_t formant_pp_factor_num_pow [10]
 formant_pp_factor_num_pow[i] = FORMANT_PP_FACTOR_NUM^(i+1) More...
 
static const int16_t formant_pp_factor_den_pow [10]
 formant_pp_factor_den_pow[i] = FORMANT_PP_FACTOR_DEN^(i+1) More...
 

Macro Definition Documentation

◆ FRAC_BITS

#define FRAC_BITS   15

Definition at line 36 of file g729postfilter.c.

Function Documentation

◆ residual_filter()

static void residual_filter ( int16_t *  out,
const int16_t *  filter_coeffs,
const int16_t *  in,
int  subframe_size 
)
static

Residual signal calculation (4.2.1 if G.729)

Parameters
[out]outoutput data filtered through A(z/FORMANT_PP_FACTOR_NUM)
filter_coeffs(3.12) A(z/FORMANT_PP_FACTOR_NUM) filter coefficients
ininput speech data to process
subframe_sizesize of one subframe
Note
in buffer must contain 10 items of previous speech data before top of the buffer
Remarks
It is safe to pass the same buffer for input and output.

Definition at line 89 of file g729postfilter.c.

Referenced by ff_g729_postfilter().

◆ long_term_filter()

static int16_t long_term_filter ( AudioDSPContext adsp,
int  pitch_delay_int,
const int16_t *  residual,
int16_t *  residual_filt,
int  subframe_size 
)
static

long-term postfilter (4.2.1)

Parameters
dspinitialized DSP context
pitch_delay_intinteger part of the pitch delay in the first subframe
residualfiltering input data
[out]residual_filtspeech signal with applied A(z/FORMANT_PP_FACTOR_NUM) filter
subframe_sizesize of subframe
Returns
0 if long-term prediction gain is less than 3dB, 1 - otherwise

Definition at line 113 of file g729postfilter.c.

Referenced by ff_g729_postfilter().

◆ get_tilt_comp()

static int16_t get_tilt_comp ( AudioDSPContext adsp,
int16_t *  lp_gn,
const int16_t *  lp_gd,
int16_t *  speech,
int  subframe_size 
)
static

Calculate reflection coefficient for tilt compensation filter (4.2.3).

Parameters
dspinitialized DSP context
lp_gn(3.12) coefficients of A(z/FORMANT_PP_FACTOR_NUM) filter
lp_gd(3.12) coefficients of A(z/FORMANT_PP_FACTOR_DEN) filter
speechspeech to update
subframe_sizesize of subframe
Returns
(3.12) reflection coefficient
Remarks
The routine also calculates the gain term for the short-term filter (gf) and multiplies the speech data by 1/gf.
Note
All members of lp_gn, except 10-19 must be equal to zero.

Definition at line 430 of file g729postfilter.c.

Referenced by ff_g729_postfilter().

◆ apply_tilt_comp()

static int16_t apply_tilt_comp ( int16_t *  out,
int16_t *  res_pst,
int  refl_coeff,
int  subframe_size,
int16_t  ht_prev_data 
)
static

Apply tilt compensation filter (4.2.3).

Parameters
[in,out]res_pstresidual signal (partially filtered)
k1(3.12) reflection coefficient
subframe_sizesize of subframe
ht_prev_dataprevious data for 4.2.3, equation 86
Returns
new value for ht_prev_data

Definition at line 482 of file g729postfilter.c.

Referenced by ff_g729_postfilter().

◆ ff_g729_postfilter()

void ff_g729_postfilter ( AudioDSPContext adsp,
int16_t *  ht_prev_data,
int *  voicing,
const int16_t *  lp_filter_coeffs,
int  pitch_delay_int,
int16_t *  residual,
int16_t *  res_filter_data,
int16_t *  pos_filter_data,
int16_t *  speech,
int  subframe_size 
)

Signal postfiltering (4.2)

Parameters
dspinitialized DSP context
[in,out]ht_prev_data(Q12) pointer to variable receiving tilt compensation filter data from previous subframe
[in,out]voicing(Q0) pointer to variable receiving voicing decision
lp_filter_coeffs(Q12) LP filter coefficients
pitch_delay_intinteger part of the pitch delay
[in,out]residual(Q0) residual signal buffer (used in long-term postfilter)
[in,out]res_filter_data(Q0) speech data of previous subframe
[in,out]pos_filter_data(Q0) previous speech data for short-term postfilter
[in,out]speech(Q0) signal buffer
subframe_sizesize of subframe

Filtering has the following stages: Long-term postfilter (4.2.1) Short-term postfilter (4.2.2). Tilt-compensation (4.2.3)

Definition at line 520 of file g729postfilter.c.

Referenced by decode_frame().

◆ ff_g729_adaptive_gain_control()

int16_t ff_g729_adaptive_gain_control ( int  gain_before,
int  gain_after,
int16_t *  speech,
int  subframe_size,
int16_t  gain_prev 
)

Adaptive gain control (4.2.4)

Parameters
gain_beforegain of speech before applying postfilters
gain_aftergain of speech after applying postfilters
[in,out]speechsignal buffer
subframe_sizelength of subframe
gain_prev(3.12) previous value of gain coefficient
Returns
(3.12) last value of gain coefficient

Definition at line 581 of file g729postfilter.c.

Referenced by decode_frame().

Variable Documentation

◆ ff_g729_interp_filt_short

const int16_t ff_g729_interp_filt_short[(ANALYZED_FRAC_DELAYS+1) *SHORT_INT_FILT_LEN]
static
Initial value:
= {
0, 31650, 28469, 23705, 18050, 12266, 7041, 2873,
0, -1597, -2147, -1992, -1492, -933, -484, -188,
}

short interpolation filter (of length 33, according to spec) for computing signal with non-integer delay

Definition at line 43 of file g729postfilter.c.

Referenced by long_term_filter().

◆ ff_g729_interp_filt_long

const int16_t ff_g729_interp_filt_long[(ANALYZED_FRAC_DELAYS+1) *LONG_INT_FILT_LEN]
static
Initial value:
= {
0, 31915, 29436, 25569, 20676, 15206, 9639, 4439,
0, -3390, -5579, -6549, -6414, -5392, -3773, -1874,
0, 1595, 2727, 3303, 3319, 2850, 2030, 1023,
0, -887, -1527, -1860, -1876, -1614, -1150, -579,
0, 501, 859, 1041, 1044, 892, 631, 315,
0, -266, -453, -543, -538, -455, -317, -156,
0, 130, 218, 258, 253, 212, 147, 72,
0, -59, -101, -122, -123, -106, -77, -40,
}

long interpolation filter (of length 129, according to spec) for computing signal with non-integer delay

Definition at line 52 of file g729postfilter.c.

Referenced by long_term_filter().

◆ formant_pp_factor_num_pow

const int16_t formant_pp_factor_num_pow[10]
static
Initial value:
= {
18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83
}

formant_pp_factor_num_pow[i] = FORMANT_PP_FACTOR_NUM^(i+1)

Definition at line 66 of file g729postfilter.c.

Referenced by ff_g729_postfilter().

◆ formant_pp_factor_den_pow

const int16_t formant_pp_factor_den_pow[10]
static
Initial value:
= {
22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925
}

formant_pp_factor_den_pow[i] = FORMANT_PP_FACTOR_DEN^(i+1)

Definition at line 74 of file g729postfilter.c.

Referenced by ff_g729_postfilter().