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];
169 for (i = 0; i < 4; i++)
230 for (i = 0; i < 4; i++)
232 0.25 * (3 - i), 0.25 * (i + 1),
248 const float lsf_no_r[LP_FILTER_ORDER],
249 const int16_t *lsf_quantizer[5],
250 const int quantizer_offset,
251 const int sign,
const int update)
257 for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
258 memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
267 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
270 lsf_q[i] = lsf_r[i] * (
LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
287 const uint16_t *lsf_param = p->
frame.
lsf;
289 const int16_t *lsf_quantizer[5];
292 lsf_quantizer[0] =
lsf_5_1[lsf_param[0]];
293 lsf_quantizer[1] =
lsf_5_2[lsf_param[1]];
294 lsf_quantizer[2] =
lsf_5_3[lsf_param[2] >> 1];
295 lsf_quantizer[3] =
lsf_5_4[lsf_param[3]];
296 lsf_quantizer[4] =
lsf_5_5[lsf_param[4]];
316 const uint16_t *lsf_param = p->
frame.
lsf;
319 const int16_t *lsf_quantizer;
323 memcpy(lsf_r, lsf_quantizer, 3 *
sizeof(*lsf_r));
326 memcpy(lsf_r + 3, lsf_quantizer, 3 *
sizeof(*lsf_r));
329 memcpy(lsf_r + 6, lsf_quantizer, 4 *
sizeof(*lsf_r));
339 memcpy(p->
prev_lsf_r, lsf_r, LP_FILTER_ORDER *
sizeof(*lsf_r));
344 for (i = 1; i <= 3; i++)
360 const int prev_lag_int,
const int subframe)
362 if (subframe == 0 || subframe == 2) {
363 if (pitch_index < 463) {
364 *lag_int = (pitch_index + 107) * 10923 >> 16;
365 *lag_frac = pitch_index - *lag_int * 6 + 105;
367 *lag_int = pitch_index - 368;
371 *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
372 *lag_frac = pitch_index - *lag_int * 6 - 3;
382 int pitch_lag_int, pitch_lag_frac;
400 pitch_lag_int += pitch_lag_frac > 0;
406 pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
422 int i1,
int i2,
int i3)
427 pulse_position[i1] = (positions[2] << 1) + ( code & 1);
428 pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
429 pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
442 int pulse_position[8];
450 temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
451 pulse_position[3] = temp % 5;
452 pulse_position[7] = temp / 5;
453 if (pulse_position[7] & 1)
454 pulse_position[3] = 4 - pulse_position[3];
455 pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
456 pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
459 for (i = 0; i < 4; i++) {
460 const int pos1 = (pulse_position[i] << 2) + i;
461 const int pos2 = (pulse_position[i + 4] << 2) + i;
462 const float sign = fixed_index[i] ? -1.0 : 1.0;
463 fixed_sparse->
x[i ] = pos1;
464 fixed_sparse->
x[i + 4] = pos2;
465 fixed_sparse->
y[i ] = sign;
466 fixed_sparse->
y[i + 4] = pos2 < pos1 ? -sign : sign;
486 const enum Mode mode,
const int subframe)
495 int *pulse_position = fixed_sparse->
x;
497 const int fixed_index = pulses[0];
500 pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
501 pulse_position[0] = ( fixed_index & 7) * 5 +
track_position[pulse_subset];
502 pulse_position[1] = ((fixed_index >> 3) & 7) * 5 +
track_position[pulse_subset + 1];
505 pulse_subset = ((fixed_index & 1) << 1) + 1;
506 pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
507 pulse_subset = (fixed_index >> 4) & 3;
508 pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
509 fixed_sparse->
n = pulse_position[0] == pulse_position[1] ? 1 : 2;
511 pulse_position[0] = (fixed_index & 7) * 5;
512 pulse_subset = (fixed_index >> 2) & 2;
513 pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
514 pulse_subset = (fixed_index >> 6) & 2;
515 pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
519 pulse_position[1] =
gray_decode[(fixed_index >> 3) & 7] + 1;
520 pulse_position[2] =
gray_decode[(fixed_index >> 6) & 7] + 2;
521 pulse_subset = (fixed_index >> 9) & 1;
522 pulse_position[3] =
gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
525 for (i = 0; i < fixed_sparse->
n; i++)
526 fixed_sparse->
y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
575 const float *lsf_avg,
const enum Mode mode)
581 diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
597 const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
602 (1.0 - smoothing_factor) * fixed_gain_mean;
617 const enum Mode mode,
const int subframe,
618 float *fixed_gain_factor)
626 const uint16_t *gains;
637 p->
pitch_gain[4] = gains[0] * (1.0 / 16384.0);
638 *fixed_gain_factor = gains[1] * (1.0 / 4096.0);
671 if (lag < AMR_SUBFRAME_SIZE >> 1)
677 for (i = 0; i < in->
n; i++) {
680 const float *filterp;
682 if (x >= AMR_SUBFRAME_SIZE - lag) {
684 }
else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
706 const float *fixed_vector,
707 float fixed_gain,
float *out)
727 for (i = 0; i < 5; i++)
735 }
else if (ir_filter_nr < 2)
741 if (fixed_gain < 5.0)
745 && ir_filter_nr < 2) {
777 float fixed_gain,
const float *fixed_vector,
778 float *
samples, uint8_t overflow)
790 p->
pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
867 memcpy(hf + 1, lpc_n,
sizeof(
float) * LP_FILTER_ORDER);
896 const float *gamma_n, *gamma_d;
908 lpc_n[i] = lpc[i] * gamma_n[i];
909 lpc_d[i] = lpc[i] * gamma_d[i];
912 memcpy(pole_out, p->
postfilter_mem,
sizeof(
float) * LP_FILTER_ORDER);
916 sizeof(
float) * LP_FILTER_ORDER);
919 pole_out + LP_FILTER_ORDER,
932 int *got_frame_ptr,
AVPacket *avpkt)
936 const uint8_t *buf = avpkt->
data;
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;
969 for (i = 0; i < 4; i++)
972 for (subframe = 0; subframe < 4; subframe++) {
1025 synth_fixed_gain, spare_vector);
1035 postfilter(p, p->
lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);