41 0, 31650, 28469, 23705, 18050, 12266, 7041, 2873,
42 0, -1597, -2147, -1992, -1492, -933, -484, -188,
50 0, 31915, 29436, 25569, 20676, 15206, 9639, 4439,
51 0, -3390, -5579, -6549, -6414, -5392, -3773, -1874,
52 0, 1595, 2727, 3303, 3319, 2850, 2030, 1023,
53 0, -887, -1527, -1860, -1876, -1614, -1150, -579,
54 0, 501, 859, 1041, 1044, 892, 631, 315,
55 0, -266, -453, -543, -538, -455, -317, -156,
56 0, 130, 218, 258, 253, 212, 147, 72,
57 0, -59, -101, -122, -123, -106, -77, -40,
65 18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83
73 22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925
91 for (n = subframe_size - 1; n >= 0; n--) {
93 for (i = 0; i < 10; i++)
94 sum += filter_coeffs[i] * in[n - i - 1];
96 out[
n] = in[
n] + (sum >> 12);
111 const int16_t*
residual, int16_t *residual_filt,
121 int corr_int_num, corr_int_den;
126 int16_t gain_num,gain_den;
127 int16_t sh_gain_num, sh_gain_den;
130 int16_t gain_long_num,gain_long_den;
131 int16_t sh_gain_long_num, sh_gain_long_den;
133 int16_t best_delay_int, best_delay_frac;
135 int16_t delayed_signal_offset;
136 int lt_filt_factor_a, lt_filt_factor_b;
138 int16_t * selected_signal;
139 const int16_t * selected_signal_const;
147 tmp |=
FFABS(residual[i]);
156 sig_scaled[i] = residual[i] >> shift;
159 sig_scaled[i] = residual[i] << -shift;
165 sig_scaled + RES_PREV_DATA_SIZE,
169 sh_ener =
FFMAX(sh_ener, 0);
192 best_delay_int = pitch_delay_int - 1;
193 for (i = pitch_delay_int - 1; i <= pitch_delay_int + 1; i++) {
195 sig_scaled + RES_PREV_DATA_SIZE - i,
197 if (sum > corr_int_num) {
205 sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,
215 &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],
217 ANALYZED_FRAC_DELAYS+1,
232 &delayed_signal[k][1],
234 corr_den[k][0] = sum + delayed_signal[k][0 ] * delayed_signal[k][0 ];
235 corr_den[k][1] = sum + delayed_signal[k][subframe_size] * delayed_signal[k][subframe_size];
237 tmp =
FFMAX3(tmp, corr_den[k][0], corr_den[k][1]);
240 sh_gain_den =
av_log2(tmp) - 14;
241 if (sh_gain_den >= 0) {
243 sh_gain_num =
FFMAX(sh_gain_den, sh_ener);
248 delayed_signal_offset = 1;
250 gain_den = corr_int_den >> sh_gain_den;
251 gain_num = corr_int_num >> sh_gain_num;
252 gain_num_square = gain_num * gain_num;
254 for (i = 0; i < 2; i++) {
255 int16_t gain_num_short, gain_den_short;
256 int gain_num_short_square;
260 sig_scaled + RES_PREV_DATA_SIZE,
262 gain_num_short =
FFMAX(sum >> sh_gain_num, 0);
269 gain_num_short_square = gain_num_short * gain_num_short;
270 gain_den_short = corr_den[k][i] >> sh_gain_den;
277 gain_num = gain_num_short;
278 gain_den = gain_den_short;
279 gain_num_square = gain_num_short_square;
280 delayed_signal_offset = i;
281 best_delay_frac = k + 1;
291 L64_temp0 = (int64_t)gain_num_square << ((sh_gain_num << 1) + 1);
292 L64_temp1 = ((int64_t)gain_den * ener) << (sh_gain_den + sh_ener);
293 if (L64_temp0 < L64_temp1)
301 memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size *
sizeof(int16_t));
306 if (best_delay_frac) {
309 &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],
317 sig_scaled + RES_PREV_DATA_SIZE,
322 sh_gain_long_num = 0;
328 sh_gain_long_num =
tmp;
338 sh_gain_long_den =
tmp;
343 L_temp0 = gain_num * gain_num;
346 L_temp1 = gain_long_num * gain_long_num;
349 tmp = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den);
356 if (L_temp1 > L_temp0) {
358 selected_signal = residual_filt;
359 gain_num = gain_long_num;
360 gain_den = gain_long_den;
361 sh_gain_num = sh_gain_long_num;
362 sh_gain_den = sh_gain_long_den;
365 selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset];
369 for (i = 0; i < subframe_size; i++)
370 selected_signal[i] <<= shift;
372 for (i = 0; i < subframe_size; i++)
373 selected_signal[i] >>= -shift;
376 selected_signal_const = selected_signal;
379 selected_signal_const = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset);
381 tmp = sh_gain_num - sh_gain_den;
387 if (gain_num > gain_den)
392 lt_filt_factor_a = (gain_den << 15) / (gain_den + gain_num);
395 L64_temp0 = (((int64_t)gain_num) << sh_gain_num) >> 1;
396 L64_temp1 = ((int64_t)gain_den) << sh_gain_den;
401 lt_filt_factor_b = 32767 - lt_filt_factor_a + 1;
404 selected_signal_const,
405 lt_filt_factor_a, lt_filt_factor_b,
406 1<<14, 15, subframe_size);
428 const int16_t *lp_gd, int16_t* speech,
453 if (
FFABS(rh1) > rh0 || !rh0)
457 for (i = 0; i < 20; i++)
458 gain_term +=
FFABS(lp_gn[i + 10]);
461 if (gain_term > 0x400) {
462 temp = 0x2000000 / gain_term;
463 for (i = 0; i < subframe_size; i++)
464 speech[i] = (speech[i] * temp + 0x4000) >> 15;
467 return -(rh1 << 15) / rh0;
480 int subframe_size, int16_t ht_prev_data)
487 if (refl_coeff > 0) {
496 ga = (fact << 15) / av_clip_int16(32768 -
FFABS(gt));
500 tmp = res_pst[subframe_size - 1];
502 for (i = subframe_size - 1; i >= 1; i--) {
503 tmp2 = (res_pst[i] << 15) + ((gt * res_pst[i-1]) << 1);
504 tmp2 = (tmp2 + 0x4000) >> 15;
506 tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact;
509 tmp2 = (res_pst[0] << 15) + ((gt * ht_prev_data) << 1);
510 tmp2 = (tmp2 + 0x4000) >> 15;
511 tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact;
518 const int16_t *lp_filter_coeffs,
int pitch_delay_int,
519 int16_t*
residual, int16_t* res_filter_data,
520 int16_t* pos_filter_data, int16_t *speech,
int subframe_size)
529 memset(lp_gn, 0, 33 *
sizeof(int16_t));
532 for (i = 0; i < 10; i++)
536 for (i = 0; i < 10; i++)
540 memcpy(speech - 10, res_filter_data, 10 *
sizeof(int16_t));
543 memcpy(res_filter_data, speech + subframe_size - 10, 10 *
sizeof(int16_t));
548 residual, residual_filt_buf + 10,
550 *voicing =
FFMAX(*voicing, i);
556 tilt_comp_coeff =
get_tilt_comp(adsp, lp_gn, lp_gd, residual_filt_buf + 10, subframe_size);
560 residual_filt_buf + 10,
561 subframe_size, 10, 0, 0, 0x800);
562 memcpy(pos_filter_data, pos_filter_data + subframe_size, 10 *
sizeof(int16_t));
564 *ht_prev_data =
apply_tilt_comp(speech, pos_filter_data + 10, tilt_comp_coeff,
565 subframe_size, *ht_prev_data);
579 int subframe_size, int16_t gain_prev)
583 int exp_before, exp_after;
585 if(!gain_after && gain_before)
590 exp_before = 14 -
av_log2(gain_before);
591 gain_before =
bidir_sal(gain_before, exp_before);
593 exp_after = 14 -
av_log2(gain_after);
594 gain_after =
bidir_sal(gain_after, exp_after);
596 if (gain_before < gain_after) {
597 gain = (gain_before << 15) / gain_after;
598 gain =
bidir_sal(gain, exp_after - exp_before - 1);
600 gain = ((gain_before - gain_after) << 14) / gain_after + 0x4000;
601 gain =
bidir_sal(gain, exp_after - exp_before);
607 for (n = 0; n < subframe_size; n++) {
610 gain_prev = av_clip_int16(gain + gain_prev);
611 speech[
n] = av_clip_int16((speech[n] * gain_prev + 0x2000) >> 14);
int32_t(* scalarproduct_int16)(const int16_t *v1, const int16_t *v2, int len)
Calculate scalar product of two vectors.
static int shift(int a, int b)
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, const int16_t *in, int buffer_length, int filter_length, int stop_on_overflow, int shift, int rounder)
LP synthesis filter.
#define ANALYZED_FRAC_DELAYS
Number of analyzed fractional pitch delays in second stage of long-term postfilter.
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)
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 de...
#define LONG_INT_FILT_LEN
Long interpolation filter length.
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)
static const int16_t formant_pp_factor_num_pow[10]
formant_pp_factor_num_pow[i] = FORMANT_PP_FACTOR_NUM^(i+1)
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)
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 de...
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).
void ff_acelp_weighted_vector_sum(int16_t *out, const int16_t *in_a, const int16_t *in_b, int16_t weight_coeff_a, int16_t weight_coeff_b, int16_t rounder, int shift, int length)
weighted sum of two vectors with rounding.
#define MIN_LT_FILT_FACTOR_A
1.0 / (1.0 + 0.5) in Q15 where 0.5 is the minimum value of weight factor, controlling amount of long-...
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).
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define G729_AGC_FACTOR
gain adjustment factor (G.729, 4.2.4) 0.9875 in Q15
static const int16_t formant_pp_factor_den_pow[10]
formant_pp_factor_den_pow[i] = FORMANT_PP_FACTOR_DEN^(i+1)
Libavcodec external API header.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
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)
#define G729_TILT_FACTOR_PLUS
tilt compensation factor (G.729, k1>0) 0.2 in Q15
void ff_acelp_interpolate(int16_t *out, const int16_t *in, const int16_t *filter_coeffs, int precision, int frac_pos, int filter_length, int length)
Generic FIR interpolation routine.
#define SHORT_INT_FILT_LEN
Short interpolation filter length.
static int bidir_sal(int value, int offset)
Shift value left or right depending on sign of offset parameter.
#define RES_PREV_DATA_SIZE
Amount of past residual signal data stored in buffer.
#define G729_TILT_FACTOR_MINUS
tilt compensation factor (G.729, k1<0) 0.9 in Q15