62 #define AMR_BLOCK_SIZE 160
63 #define AMR_SAMPLE_BOUND 32768.0
74 #define AMR_SAMPLE_SCALE (2.0 / 32768.0)
77 #define PRED_FAC_MODE_12k2 0.65
79 #define LSF_R_FAC (8000.0 / 32768.0)
80 #define MIN_LSF_SPACING (50.0488 / 8000.0)
81 #define PITCH_LAG_MIN_MODE_12k2 18
84 #define MIN_ENERGY -14.0
91 #define SHARP_MAX 0.79449462890625
94 #define AMR_TILT_RESPONSE 22
96 #define AMR_TILT_GAMMA_T 0.8
98 #define AMR_AGC_ALPHA 0.9
150 const double *in_b,
double weight_coeff_a,
151 double weight_coeff_b,
int length)
155 for (i = 0; i < length; i++)
156 out[i] = weight_coeff_a * in_a[i]
157 + weight_coeff_b * in_b[i];
184 for (i = 0; i < 4; i++)
213 mode = buf[0] >> 3 & 0x0F;
243 for (i = 0; i < 4; i++)
245 0.25 * (3 - i), 0.25 * (i + 1),
261 const float lsf_no_r[LP_FILTER_ORDER],
262 const int16_t *lsf_quantizer[5],
263 const int quantizer_offset,
264 const int sign,
const int update)
270 for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
271 memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
280 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
283 lsf_q[i] = lsf_r[i] * (
LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
300 const uint16_t *lsf_param = p->
frame.
lsf;
302 const int16_t *lsf_quantizer[5];
305 lsf_quantizer[0] =
lsf_5_1[lsf_param[0]];
306 lsf_quantizer[1] =
lsf_5_2[lsf_param[1]];
307 lsf_quantizer[2] =
lsf_5_3[lsf_param[2] >> 1];
308 lsf_quantizer[3] =
lsf_5_4[lsf_param[3]];
309 lsf_quantizer[4] =
lsf_5_5[lsf_param[4]];
329 const uint16_t *lsf_param = p->
frame.
lsf;
332 const int16_t *lsf_quantizer;
336 memcpy(lsf_r, lsf_quantizer, 3 *
sizeof(*lsf_r));
339 memcpy(lsf_r + 3, lsf_quantizer, 3 *
sizeof(*lsf_r));
342 memcpy(lsf_r + 6, lsf_quantizer, 4 *
sizeof(*lsf_r));
352 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
357 for (i = 1; i <= 3; i++)
373 const int prev_lag_int,
const int subframe)
375 if (subframe == 0 || subframe == 2) {
376 if (pitch_index < 463) {
377 *lag_int = (pitch_index + 107) * 10923 >> 16;
378 *lag_frac = pitch_index - *lag_int * 6 + 105;
380 *lag_int = pitch_index - 368;
384 *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
385 *lag_frac = pitch_index - *lag_int * 6 - 3;
395 int pitch_lag_int, pitch_lag_frac;
413 pitch_lag_int += pitch_lag_frac > 0;
420 pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
436 int i1,
int i2,
int i3)
441 pulse_position[i1] = (positions[2] << 1) + ( code & 1);
442 pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
443 pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
456 int pulse_position[8];
464 temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
465 pulse_position[3] = temp % 5;
466 pulse_position[7] = temp / 5;
467 if (pulse_position[7] & 1)
468 pulse_position[3] = 4 - pulse_position[3];
469 pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
470 pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
473 for (i = 0; i < 4; i++) {
474 const int pos1 = (pulse_position[i] << 2) + i;
475 const int pos2 = (pulse_position[i + 4] << 2) + i;
476 const float sign = fixed_index[i] ? -1.0 : 1.0;
477 fixed_sparse->
x[i ] = pos1;
478 fixed_sparse->
x[i + 4] = pos2;
479 fixed_sparse->
y[i ] = sign;
480 fixed_sparse->
y[i + 4] = pos2 < pos1 ? -sign : sign;
500 const enum Mode mode,
const int subframe)
509 int *pulse_position = fixed_sparse->
x;
511 const int fixed_index = pulses[0];
514 pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
515 pulse_position[0] = ( fixed_index & 7) * 5 +
track_position[pulse_subset];
516 pulse_position[1] = ((fixed_index >> 3) & 7) * 5 +
track_position[pulse_subset + 1];
519 pulse_subset = ((fixed_index & 1) << 1) + 1;
520 pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
521 pulse_subset = (fixed_index >> 4) & 3;
522 pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
523 fixed_sparse->
n = pulse_position[0] == pulse_position[1] ? 1 : 2;
525 pulse_position[0] = (fixed_index & 7) * 5;
526 pulse_subset = (fixed_index >> 2) & 2;
527 pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
528 pulse_subset = (fixed_index >> 6) & 2;
529 pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
533 pulse_position[1] =
gray_decode[(fixed_index >> 3) & 7] + 1;
534 pulse_position[2] =
gray_decode[(fixed_index >> 6) & 7] + 2;
535 pulse_subset = (fixed_index >> 9) & 1;
536 pulse_position[3] =
gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
539 for (i = 0; i < fixed_sparse->
n; i++)
540 fixed_sparse->
y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
589 const float *lsf_avg,
const enum Mode mode)
595 diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
611 const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
616 (1.0 - smoothing_factor) * fixed_gain_mean;
631 const enum Mode mode,
const int subframe,
632 float *fixed_gain_factor)
640 const uint16_t *gains;
651 p->
pitch_gain[4] = gains[0] * (1.0 / 16384.0);
652 *fixed_gain_factor = gains[1] * (1.0 / 4096.0);
685 if (lag < AMR_SUBFRAME_SIZE >> 1)
691 for (i = 0; i < in->
n; i++) {
694 const float *filterp;
696 if (x >= AMR_SUBFRAME_SIZE - lag) {
698 }
else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
720 const float *fixed_vector,
721 float fixed_gain,
float *
out)
741 for (i = 0; i < 5; i++)
749 }
else if (ir_filter_nr < 2)
755 if (fixed_gain < 5.0)
759 && ir_filter_nr < 2) {
791 float fixed_gain,
const float *fixed_vector,
804 p->
pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
883 memcpy(hf + 1, lpc_n,
sizeof(
float) * LP_FILTER_ORDER);
913 const float *gamma_n, *gamma_d;
925 lpc_n[i] = lpc[i] * gamma_n[i];
926 lpc_d[i] = lpc[i] * gamma_d[i];
929 memcpy(pole_out, p->
postfilter_mem,
sizeof(
float) * LP_FILTER_ORDER);
933 sizeof(
float) * LP_FILTER_ORDER);
936 pole_out + LP_FILTER_ORDER,
949 int *got_frame_ptr,
AVPacket *avpkt)
955 int buf_size = avpkt->
size;
957 int i, subframe, ret;
958 float fixed_gain_factor;
961 float synth_fixed_gain;
962 const float *synth_fixed_vector;
970 buf_out = (
float *)frame->
data[0];
988 for (i = 0; i < 4; i++)
991 for (subframe = 0; subframe < 4; subframe++) {
1004 &fixed_gain_factor);
1009 av_log(avctx,
AV_LOG_ERROR,
"The file is corrupted, pitch_lag = 0 is not allowed\n");
1046 synth_fixed_gain, spare_vector);
1056 postfilter(p, p->
lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);