36 #define MIN_LSP_SEP (0.05 / (2.0 * M_PI))
39 #define NB_SUBFRAMES 3
40 #define SUBFRAME_SIZE 54
41 #define FILTER_ORDER 10
190 if (bitrate > **buf) {
194 "Claimed bitrate and buffer size mismatch.\n");
198 }
else if (bitrate < **buf) {
200 "Buffer is too small for the claimed bitrate.\n");
207 "Bitrate byte is missing, guessing the bitrate from packet size.\n");
230 float denom = 2.0 / (2.0 * 8.0 + 1.0);
250 for (i = 0; i < 8; i++) {
251 float tt = ((float)i - 8.0 / 2.0) / 8.0;
253 for (n = -8; n <= 8; n++, idx++) {
254 float arg1 =
M_PI * 0.9 * (tt -
n);
255 float arg2 =
M_PI * (tt -
n);
284 const float *codebook = codebooks[i];
287 e->
lspf[k++] = codebook[e->
frame.
lsp[i] * row_size + j];
296 for (i = 0, k = 0; i < evrc_lspq_nb_codebooks[e->
bitrate] - 1; i++) {
311 const float *prev,
int index)
313 static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 };
315 1.0 - lsp_interpolation_factors[index],
326 static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 };
327 dst[0] = (1.0 - d_interpolation_factors[
index ]) * prev
328 + d_interpolation_factors[index ] * current;
329 dst[1] = (1.0 - d_interpolation_factors[index + 1]) * prev
330 + d_interpolation_factors[index + 1] * current;
331 dst[2] = (1.0 - d_interpolation_factors[index + 2]) * prev
332 + d_interpolation_factors[index + 2] * current;
354 a[0] = k < 2 ? 0.25 : 0;
355 b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
358 a[i + 1] = a[i] - 2 * lsp[i * 2 ] * a1[i] + a2[i];
359 b[i + 1] = b[i] - 2 * lsp[i * 2 + 1] * b1[i] + b2[i];
379 t = (offset - delay + 0.5) * 8.0 + 0.5;
387 coef_idx = t * (2 * 8 + 1);
390 for (i = 0; i < 2 * 8 + 1; i++)
400 const float delay[3],
int length)
402 float denom, locdelay, dpr, invl;
405 invl = 1.0 / ((float) length);
409 denom = (delay[1] - delay[0]) * invl;
410 for (i = 0; i < dpr; i++) {
411 locdelay = delay[0] + i * denom;
412 bl_intrp(e, excitation + i, locdelay);
415 denom = (delay[2] - delay[1]) * invl;
417 for (i = dpr; i < dpr + 10; i++) {
418 locdelay = delay[1] + (i - dpr) * denom;
419 bl_intrp(e, excitation + i, locdelay);
422 for (i = 0; i <
length; i++)
423 excitation[i] *= gain;
428 int i, pos1, pos2,
offset;
430 offset = (fixed_index[3] >> 9) & 3;
432 for (i = 0; i < 3; i++) {
433 pos1 = ((fixed_index[i] & 0x7f) / 11) * 5 + ((i +
offset) % 5);
434 pos2 = ((fixed_index[i] & 0x7f) % 11) * 5 + ((i +
offset) % 5);
436 cod[pos1] = (fixed_index[i] & 0x80) ? -1.0 : 1.0;
439 cod[pos2] = -cod[pos1];
441 cod[pos2] += cod[pos1];
444 pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 +
offset) % 5);
445 pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 +
offset) % 5);
447 cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0;
448 cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0;
456 sign = (fixed_index & 0x200) ? -1.0 : 1.0;
458 pos = ((fixed_index & 0x7) * 7) + 4;
460 pos = (((fixed_index >> 3) & 0x7) * 7) + 2;
462 pos = (((fixed_index >> 6) & 0x7) * 7);
472 float *excitation,
float pitch_gain,
473 int pitch_lag,
int subframe_size)
482 pitch_gain = av_clipf(pitch_gain, 0.2, 0.9);
484 for (i = pitch_lag; i < subframe_size; i++)
485 excitation[i] += pitch_gain * excitation[i - pitch_lag];
500 float *memory,
int buffer_length,
float *samples)
504 for (i = 0; i < buffer_length; i++) {
507 samples[i] -= filter_coeffs[j] * memory[j];
508 memory[j] = memory[j - 1];
510 samples[i] -= filter_coeffs[0] * memory[0];
511 memory[0] = samples[i];
521 coeff[i] = inbuf[i] * fac;
527 const float *coef,
float *memory,
int length)
532 for (i = 0; i <
length; i++) {
536 sum += coef[j] * memory[j];
537 memory[j] = memory[j - 1];
539 sum += coef[0] * memory[0];
540 memory[0] = input[i];
554 { 0.0 , 0.0 , 0.0 , 0.0 },
555 { 0.0 , 0.0 , 0.57, 0.57 },
556 { 0.0 , 0.0 , 0.0 , 0.0 },
557 { 0.35, 0.50, 0.50, 0.75 },
558 { 0.20, 0.50, 0.57, 0.75 },
567 float *
out,
int idx,
const struct PfCoeff *pfc,
573 float sum1 = 0.0, sum2 = 0.0, gamma, gain;
574 float tilt = pfc->
tilt;
581 for (i = 0; i < length - 1; i++)
582 sum2 += in[i] * in[i + 1];
586 for (i = 0; i <
length; i++) {
587 scratch[i] = in[i] - tilt * e->
last;
617 gamma =
FFMIN(gamma, 1.0);
619 for (i = 0; i <
length; i++) {
626 memcpy(scratch, temp, length *
sizeof(
float));
631 for (i = 0, sum1 = 0, sum2 = 0; i <
length; i++) {
632 sum1 += in[i] * in[i];
633 sum2 += scratch[i] * scratch[i];
635 gain = sum2 ? sqrt(sum1 / sum2) : 1.0;
637 for (i = 0; i <
length; i++)
655 e->
lspf[i] = e->
prev_lspf[i] * 0.875 + 0.125 * (i + 1) * 0.048;
674 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
703 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
709 for (j = 0; j < subframe_size; j++)
713 for (j = 0; j < subframe_size; j++)
721 for (j = 0; j < subframe_size; j++)
724 for (j = 0; j < subframe_size; j++)
733 samples += subframe_size;
738 int *got_frame_ptr,
AVPacket *avpkt)
743 int buf_size = avpkt->
size;
746 int i, j,
ret, error_flag = 0;
751 samples = (
float *)frame->
data[0];
776 }
else if (e->
frame.
lsp[0] == 0xf &&
827 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
845 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
862 acb_sum, idelay, subframe_size);
864 acb_sum, pitch_lag, subframe_size);
867 for (j = 0; j < subframe_size; j++)
871 for (j = 0; j < subframe_size; j++)
882 samples += subframe_size;
899 samples = (
float *)frame->
data[0];
900 for (i = 0; i < 160; i++)