60 #define AMR_BLOCK_SIZE 160
61 #define AMR_SAMPLE_BOUND 32768.0
72 #define AMR_SAMPLE_SCALE (2.0 / 32768.0)
75 #define PRED_FAC_MODE_12k2 0.65
77 #define LSF_R_FAC (8000.0 / 32768.0)
78 #define MIN_LSF_SPACING (50.0488 / 8000.0)
79 #define PITCH_LAG_MIN_MODE_12k2 18
82 #define MIN_ENERGY -14.0
89 #define SHARP_MAX 0.79449462890625
92 #define AMR_TILT_RESPONSE 22
94 #define AMR_TILT_GAMMA_T 0.8
96 #define AMR_AGC_ALPHA 0.9
144 const double *in_b,
double weight_coeff_a,
145 double weight_coeff_b,
int length)
149 for (i = 0; i < length; i++)
150 out[i] = weight_coeff_a * in_a[i]
151 + weight_coeff_b * in_b[i];
177 for (i = 0; i < 4; i++)
204 mode = buf[0] >> 3 & 0x0F;
233 for (i = 0; i < 4; i++)
235 0.25 * (3 - i), 0.25 * (i + 1),
251 const float lsf_no_r[LP_FILTER_ORDER],
252 const int16_t *lsf_quantizer[5],
253 const int quantizer_offset,
254 const int sign,
const int update)
260 for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
261 memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
270 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
273 lsf_q[i] = lsf_r[i] * (
LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
290 const uint16_t *lsf_param = p->
frame.
lsf;
292 const int16_t *lsf_quantizer[5];
295 lsf_quantizer[0] =
lsf_5_1[lsf_param[0]];
296 lsf_quantizer[1] =
lsf_5_2[lsf_param[1]];
297 lsf_quantizer[2] =
lsf_5_3[lsf_param[2] >> 1];
298 lsf_quantizer[3] =
lsf_5_4[lsf_param[3]];
299 lsf_quantizer[4] =
lsf_5_5[lsf_param[4]];
319 const uint16_t *lsf_param = p->
frame.
lsf;
322 const int16_t *lsf_quantizer;
326 memcpy(lsf_r, lsf_quantizer, 3 *
sizeof(*lsf_r));
329 memcpy(lsf_r + 3, lsf_quantizer, 3 *
sizeof(*lsf_r));
332 memcpy(lsf_r + 6, lsf_quantizer, 4 *
sizeof(*lsf_r));
342 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
347 for (i = 1; i <= 3; i++)
363 const int prev_lag_int,
const int subframe)
365 if (subframe == 0 || subframe == 2) {
366 if (pitch_index < 463) {
367 *lag_int = (pitch_index + 107) * 10923 >> 16;
368 *lag_frac = pitch_index - *lag_int * 6 + 105;
370 *lag_int = pitch_index - 368;
374 *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
375 *lag_frac = pitch_index - *lag_int * 6 - 3;
385 int pitch_lag_int, pitch_lag_frac;
403 pitch_lag_int += pitch_lag_frac > 0;
409 pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
425 int i1,
int i2,
int i3)
430 pulse_position[i1] = (positions[2] << 1) + ( code & 1);
431 pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
432 pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
445 int pulse_position[8];
453 temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
454 pulse_position[3] = temp % 5;
455 pulse_position[7] = temp / 5;
456 if (pulse_position[7] & 1)
457 pulse_position[3] = 4 - pulse_position[3];
458 pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
459 pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
462 for (i = 0; i < 4; i++) {
463 const int pos1 = (pulse_position[i] << 2) + i;
464 const int pos2 = (pulse_position[i + 4] << 2) + i;
465 const float sign = fixed_index[i] ? -1.0 : 1.0;
466 fixed_sparse->
x[i ] = pos1;
467 fixed_sparse->
x[i + 4] = pos2;
468 fixed_sparse->
y[i ] = sign;
469 fixed_sparse->
y[i + 4] = pos2 < pos1 ? -sign : sign;
489 const enum Mode mode,
const int subframe)
498 int *pulse_position = fixed_sparse->
x;
500 const int fixed_index = pulses[0];
503 pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
504 pulse_position[0] = ( fixed_index & 7) * 5 +
track_position[pulse_subset];
505 pulse_position[1] = ((fixed_index >> 3) & 7) * 5 +
track_position[pulse_subset + 1];
508 pulse_subset = ((fixed_index & 1) << 1) + 1;
509 pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
510 pulse_subset = (fixed_index >> 4) & 3;
511 pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
512 fixed_sparse->
n = pulse_position[0] == pulse_position[1] ? 1 : 2;
514 pulse_position[0] = (fixed_index & 7) * 5;
515 pulse_subset = (fixed_index >> 2) & 2;
516 pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
517 pulse_subset = (fixed_index >> 6) & 2;
518 pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
522 pulse_position[1] =
gray_decode[(fixed_index >> 3) & 7] + 1;
523 pulse_position[2] =
gray_decode[(fixed_index >> 6) & 7] + 2;
524 pulse_subset = (fixed_index >> 9) & 1;
525 pulse_position[3] =
gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
528 for (i = 0; i < fixed_sparse->
n; i++)
529 fixed_sparse->
y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
578 const float *lsf_avg,
const enum Mode mode)
584 diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
600 const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
605 (1.0 - smoothing_factor) * fixed_gain_mean;
620 const enum Mode mode,
const int subframe,
621 float *fixed_gain_factor)
629 const uint16_t *gains;
640 p->
pitch_gain[4] = gains[0] * (1.0 / 16384.0);
641 *fixed_gain_factor = gains[1] * (1.0 / 4096.0);
674 if (lag < AMR_SUBFRAME_SIZE >> 1)
680 for (i = 0; i < in->
n; i++) {
683 const float *filterp;
685 if (x >= AMR_SUBFRAME_SIZE - lag) {
687 }
else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
709 const float *fixed_vector,
710 float fixed_gain,
float *out)
730 for (i = 0; i < 5; i++)
738 }
else if (ir_filter_nr < 2)
744 if (fixed_gain < 5.0)
748 && ir_filter_nr < 2) {
780 float fixed_gain,
const float *fixed_vector,
793 p->
pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
870 memcpy(hf + 1, lpc_n,
sizeof(
float) * LP_FILTER_ORDER);
899 const float *gamma_n, *gamma_d;
911 lpc_n[i] = lpc[i] * gamma_n[i];
912 lpc_d[i] = lpc[i] * gamma_d[i];
915 memcpy(pole_out, p->
postfilter_mem,
sizeof(
float) * LP_FILTER_ORDER);
919 sizeof(
float) * LP_FILTER_ORDER);
922 pole_out + LP_FILTER_ORDER,
935 int *got_frame_ptr,
AVPacket *avpkt)
940 int buf_size = avpkt->
size;
942 int i, subframe, ret;
943 float fixed_gain_factor;
946 float synth_fixed_gain;
947 const float *synth_fixed_vector;
972 for (i = 0; i < 4; i++)
975 for (subframe = 0; subframe < 4; subframe++) {
1030 synth_fixed_gain, spare_vector);
1040 postfilter(p, p->
lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);