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
151 const double *in_b,
double weight_coeff_a,
152 double weight_coeff_b,
int length)
156 for (i = 0; i < length; i++)
157 out[i] = weight_coeff_a * in_a[i]
158 + weight_coeff_b * in_b[i];
185 for (i = 0; i < 4; i++)
217 mode = buf[0] >> 3 & 0x0F;
247 for (i = 0; i < 4; i++)
249 0.25 * (3 - i), 0.25 * (i + 1),
265 const float lsf_no_r[LP_FILTER_ORDER],
266 const int16_t *lsf_quantizer[5],
267 const int quantizer_offset,
268 const int sign,
const int update)
274 for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
275 memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
284 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
287 lsf_q[i] = lsf_r[i] * (
LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
304 const uint16_t *lsf_param = p->
frame.
lsf;
306 const int16_t *lsf_quantizer[5];
309 lsf_quantizer[0] =
lsf_5_1[lsf_param[0]];
310 lsf_quantizer[1] =
lsf_5_2[lsf_param[1]];
311 lsf_quantizer[2] =
lsf_5_3[lsf_param[2] >> 1];
312 lsf_quantizer[3] =
lsf_5_4[lsf_param[3]];
313 lsf_quantizer[4] =
lsf_5_5[lsf_param[4]];
333 const uint16_t *lsf_param = p->
frame.
lsf;
336 const int16_t *lsf_quantizer;
340 memcpy(lsf_r, lsf_quantizer, 3 *
sizeof(*lsf_r));
343 memcpy(lsf_r + 3, lsf_quantizer, 3 *
sizeof(*lsf_r));
346 memcpy(lsf_r + 6, lsf_quantizer, 4 *
sizeof(*lsf_r));
356 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
361 for (i = 1; i <= 3; i++)
377 const int prev_lag_int,
const int subframe)
379 if (subframe == 0 || subframe == 2) {
380 if (pitch_index < 463) {
381 *lag_int = (pitch_index + 107) * 10923 >> 16;
382 *lag_frac = pitch_index - *lag_int * 6 + 105;
384 *lag_int = pitch_index - 368;
388 *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
389 *lag_frac = pitch_index - *lag_int * 6 - 3;
399 int pitch_lag_int, pitch_lag_frac;
417 pitch_lag_int += pitch_lag_frac > 0;
424 pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
440 int i1,
int i2,
int i3)
445 pulse_position[i1] = (positions[2] << 1) + ( code & 1);
446 pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
447 pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
460 int pulse_position[8];
468 temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
469 pulse_position[3] = temp % 5;
470 pulse_position[7] = temp / 5;
471 if (pulse_position[7] & 1)
472 pulse_position[3] = 4 - pulse_position[3];
473 pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
474 pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
477 for (i = 0; i < 4; i++) {
478 const int pos1 = (pulse_position[i] << 2) + i;
479 const int pos2 = (pulse_position[i + 4] << 2) + i;
480 const float sign = fixed_index[i] ? -1.0 : 1.0;
481 fixed_sparse->
x[i ] = pos1;
482 fixed_sparse->
x[i + 4] = pos2;
483 fixed_sparse->
y[i ] = sign;
484 fixed_sparse->
y[i + 4] = pos2 < pos1 ? -sign : sign;
504 const enum Mode mode,
const int subframe)
513 int *pulse_position = fixed_sparse->
x;
515 const int fixed_index = pulses[0];
518 pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
519 pulse_position[0] = ( fixed_index & 7) * 5 +
track_position[pulse_subset];
520 pulse_position[1] = ((fixed_index >> 3) & 7) * 5 +
track_position[pulse_subset + 1];
523 pulse_subset = ((fixed_index & 1) << 1) + 1;
524 pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
525 pulse_subset = (fixed_index >> 4) & 3;
526 pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
527 fixed_sparse->
n = pulse_position[0] == pulse_position[1] ? 1 : 2;
529 pulse_position[0] = (fixed_index & 7) * 5;
530 pulse_subset = (fixed_index >> 2) & 2;
531 pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
532 pulse_subset = (fixed_index >> 6) & 2;
533 pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
537 pulse_position[1] =
gray_decode[(fixed_index >> 3) & 7] + 1;
538 pulse_position[2] =
gray_decode[(fixed_index >> 6) & 7] + 2;
539 pulse_subset = (fixed_index >> 9) & 1;
540 pulse_position[3] =
gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
543 for (i = 0; i < fixed_sparse->
n; i++)
544 fixed_sparse->
y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
593 const float *lsf_avg,
const enum Mode mode)
599 diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
615 const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
620 (1.0 - smoothing_factor) * fixed_gain_mean;
635 const enum Mode mode,
const int subframe,
636 float *fixed_gain_factor)
644 const uint16_t *gains;
655 p->
pitch_gain[4] = gains[0] * (1.0 / 16384.0);
656 *fixed_gain_factor = gains[1] * (1.0 / 4096.0);
689 if (lag < AMR_SUBFRAME_SIZE >> 1)
695 for (i = 0; i < in->
n; i++) {
698 const float *filterp;
700 if (x >= AMR_SUBFRAME_SIZE - lag) {
702 }
else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
724 const float *fixed_vector,
725 float fixed_gain,
float *out)
745 for (i = 0; i < 5; i++)
753 }
else if (ir_filter_nr < 2)
759 if (fixed_gain < 5.0)
763 && ir_filter_nr < 2) {
795 float fixed_gain,
const float *fixed_vector,
808 p->
pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
887 memcpy(hf + 1, lpc_n,
sizeof(
float) * LP_FILTER_ORDER);
917 const float *gamma_n, *gamma_d;
929 lpc_n[i] = lpc[i] * gamma_n[i];
930 lpc_d[i] = lpc[i] * gamma_d[i];
933 memcpy(pole_out, p->
postfilter_mem,
sizeof(
float) * LP_FILTER_ORDER);
937 sizeof(
float) * LP_FILTER_ORDER);
940 pole_out + LP_FILTER_ORDER,
953 int *got_frame_ptr,
AVPacket *avpkt)
958 int buf_size = avpkt->
size;
960 int i, subframe, ret;
961 float fixed_gain_factor;
964 float synth_fixed_gain;
965 const float *synth_fixed_vector;
991 for (i = 0; i < 4; i++)
994 for (subframe = 0; subframe < 4; subframe++) {
1007 &fixed_gain_factor);
1012 av_log(avctx,
AV_LOG_ERROR,
"The file is corrupted, pitch_lag = 0 is not allowed\n");
1049 synth_fixed_gain, spare_vector);
1059 postfilter(p, p->
lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);