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
143 const double *in_b,
double weight_coeff_a,
144 double weight_coeff_b,
int length)
148 for (i = 0; i < length; i++)
149 out[i] = weight_coeff_a * in_a[i]
150 + weight_coeff_b * in_b[i];
176 for (i = 0; i < 4; i++)
200 mode = buf[0] >> 3 & 0x0F;
229 for (i = 0; i < 4; i++)
231 0.25 * (3 - i), 0.25 * (i + 1),
247 const float lsf_no_r[LP_FILTER_ORDER],
248 const int16_t *lsf_quantizer[5],
249 const int quantizer_offset,
250 const int sign,
const int update)
256 for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
257 memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
266 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
269 lsf_q[i] = lsf_r[i] * (
LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
286 const uint16_t *lsf_param = p->
frame.
lsf;
288 const int16_t *lsf_quantizer[5];
291 lsf_quantizer[0] =
lsf_5_1[lsf_param[0]];
292 lsf_quantizer[1] =
lsf_5_2[lsf_param[1]];
293 lsf_quantizer[2] =
lsf_5_3[lsf_param[2] >> 1];
294 lsf_quantizer[3] =
lsf_5_4[lsf_param[3]];
295 lsf_quantizer[4] =
lsf_5_5[lsf_param[4]];
315 const uint16_t *lsf_param = p->
frame.
lsf;
318 const int16_t *lsf_quantizer;
322 memcpy(lsf_r, lsf_quantizer, 3 *
sizeof(*lsf_r));
325 memcpy(lsf_r + 3, lsf_quantizer, 3 *
sizeof(*lsf_r));
328 memcpy(lsf_r + 6, lsf_quantizer, 4 *
sizeof(*lsf_r));
338 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
343 for (i = 1; i <= 3; i++)
359 const int prev_lag_int,
const int subframe)
361 if (subframe == 0 || subframe == 2) {
362 if (pitch_index < 463) {
363 *lag_int = (pitch_index + 107) * 10923 >> 16;
364 *lag_frac = pitch_index - *lag_int * 6 + 105;
366 *lag_int = pitch_index - 368;
370 *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
371 *lag_frac = pitch_index - *lag_int * 6 - 3;
381 int pitch_lag_int, pitch_lag_frac;
399 pitch_lag_int += pitch_lag_frac > 0;
405 pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
421 int i1,
int i2,
int i3)
426 pulse_position[i1] = (positions[2] << 1) + ( code & 1);
427 pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
428 pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
441 int pulse_position[8];
449 temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
450 pulse_position[3] = temp % 5;
451 pulse_position[7] = temp / 5;
452 if (pulse_position[7] & 1)
453 pulse_position[3] = 4 - pulse_position[3];
454 pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
455 pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
458 for (i = 0; i < 4; i++) {
459 const int pos1 = (pulse_position[i] << 2) + i;
460 const int pos2 = (pulse_position[i + 4] << 2) + i;
461 const float sign = fixed_index[i] ? -1.0 : 1.0;
462 fixed_sparse->
x[i ] = pos1;
463 fixed_sparse->
x[i + 4] = pos2;
464 fixed_sparse->
y[i ] = sign;
465 fixed_sparse->
y[i + 4] = pos2 < pos1 ? -sign : sign;
485 const enum Mode mode,
const int subframe)
494 int *pulse_position = fixed_sparse->
x;
496 const int fixed_index = pulses[0];
499 pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
500 pulse_position[0] = ( fixed_index & 7) * 5 +
track_position[pulse_subset];
501 pulse_position[1] = ((fixed_index >> 3) & 7) * 5 +
track_position[pulse_subset + 1];
504 pulse_subset = ((fixed_index & 1) << 1) + 1;
505 pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
506 pulse_subset = (fixed_index >> 4) & 3;
507 pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
508 fixed_sparse->
n = pulse_position[0] == pulse_position[1] ? 1 : 2;
510 pulse_position[0] = (fixed_index & 7) * 5;
511 pulse_subset = (fixed_index >> 2) & 2;
512 pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
513 pulse_subset = (fixed_index >> 6) & 2;
514 pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
518 pulse_position[1] =
gray_decode[(fixed_index >> 3) & 7] + 1;
519 pulse_position[2] =
gray_decode[(fixed_index >> 6) & 7] + 2;
520 pulse_subset = (fixed_index >> 9) & 1;
521 pulse_position[3] =
gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
524 for (i = 0; i < fixed_sparse->
n; i++)
525 fixed_sparse->
y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
574 const float *lsf_avg,
const enum Mode mode)
580 diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
596 const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
601 (1.0 - smoothing_factor) * fixed_gain_mean;
616 const enum Mode mode,
const int subframe,
617 float *fixed_gain_factor)
625 const uint16_t *gains;
636 p->
pitch_gain[4] = gains[0] * (1.0 / 16384.0);
637 *fixed_gain_factor = gains[1] * (1.0 / 4096.0);
670 if (lag < AMR_SUBFRAME_SIZE >> 1)
676 for (i = 0; i < in->
n; i++) {
679 const float *filterp;
681 if (x >= AMR_SUBFRAME_SIZE - lag) {
683 }
else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
705 const float *fixed_vector,
706 float fixed_gain,
float *
out)
726 for (i = 0; i < 5; i++)
734 }
else if (ir_filter_nr < 2)
740 if (fixed_gain < 5.0)
744 && ir_filter_nr < 2) {
776 float fixed_gain,
const float *fixed_vector,
789 p->
pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
866 memcpy(hf + 1, lpc_n,
sizeof(
float) * LP_FILTER_ORDER);
895 const float *gamma_n, *gamma_d;
907 lpc_n[i] = lpc[i] * gamma_n[i];
908 lpc_d[i] = lpc[i] * gamma_d[i];
911 memcpy(pole_out, p->
postfilter_mem,
sizeof(
float) * LP_FILTER_ORDER);
915 sizeof(
float) * LP_FILTER_ORDER);
918 pole_out + LP_FILTER_ORDER,
931 int *got_frame_ptr,
AVPacket *avpkt)
937 int buf_size = avpkt->
size;
939 int i, subframe, ret;
940 float fixed_gain_factor;
943 float synth_fixed_gain;
944 const float *synth_fixed_vector;
952 buf_out = (
float *)frame->
data[0];
969 for (i = 0; i < 4; i++)
972 for (subframe = 0; subframe < 4; subframe++) {
1027 synth_fixed_gain, spare_vector);
1037 postfilter(p, p->
lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);