28 #define BITSTREAM_READER_LE
40 #define CNG_RANDOM_SEED 12345
42 typedef struct g723_1_context {
115 int temp, info_bits, i;
122 if (info_bits == 3) {
132 if (info_bits == 2) {
229 return (
ff_sqrt(val << 1) >> 1) & (~1);
240 return width -
av_log2(num) - 1;
243 #define normalize_bits_int16(num) normalize_bits(num, 15)
244 #define normalize_bits_int32(num) normalize_bits(num, 31)
254 for (i = 0; i <
length; i++)
255 max |=
FFABS(vector[i]);
258 bits=
FFMAX(bits, 0);
260 for (i = 0; i <
length; i++)
261 dst[i] = vector[i] << bits >> 3;
275 uint8_t *lsp_index,
int bad_frame)
278 int i, j,
temp, stable;
287 lsp_index[0] = lsp_index[1] = lsp_index[2] = 0;
304 temp = ((prev_lsp[i] -
dc_lsp[i]) * pred + (1 << 14)) >> 15;
309 cur_lsp[0] =
FFMAX(cur_lsp[0], 0x180);
310 cur_lsp[LPC_ORDER - 1] =
FFMIN(cur_lsp[LPC_ORDER - 1], 0x7e00);
314 temp = min_dist + cur_lsp[j - 1] - cur_lsp[j];
317 cur_lsp[j - 1] -=
temp;
323 temp = cur_lsp[j - 1] + min_dist - cur_lsp[j] - 4;
333 memcpy(cur_lsp, prev_lsp, LPC_ORDER *
sizeof(*cur_lsp));
342 #define MULL2(a, b) \
358 int index = (lpc[j] >> 7) & 0x1FF;
359 int offset = lpc[j] & 0x7f;
362 ((offset << 8) + 0x80) << 1;
364 lpc[j] = -(av_sat_dadd32(1 << 15, temp1 + temp2) >> 16);
373 f1[1] = (lpc[0] << 14) + (lpc[2] << 14);
374 f1[2] = lpc[0] * lpc[2] + (2 << 28);
377 f2[1] = (lpc[1] << 14) + (lpc[3] << 14);
378 f2[2] = lpc[1] * lpc[3] + (2 << 28);
384 for (i = 2; i < LPC_ORDER / 2; i++) {
385 f1[i + 1] = f1[i - 1] +
MULL2(f1[i], lpc[2 * i]);
386 f2[i + 1] = f2[i - 1] +
MULL2(f2[i], lpc[2 * i + 1]);
388 for (j = i; j >= 2; j--) {
389 f1[j] =
MULL2(f1[j - 1], lpc[2 * i]) +
390 (f1[j] >> 1) + (f1[j - 2] >> 1);
391 f2[j] =
MULL2(f2[j - 1], lpc[2 * i + 1]) +
392 (f2[j] >> 1) + (f2[j - 2] >> 1);
397 f1[1] = ((lpc[2 * i] << 16 >> i) + f1[1]) >> 1;
398 f2[1] = ((lpc[2 * i + 1] << 16 >> i) + f2[1]) >> 1;
402 for (i = 0; i < LPC_ORDER / 2; i++) {
403 int64_t ff1 = f1[i + 1] + f1[i];
404 int64_t ff2 = f2[i + 1] - f2[i];
406 lpc[i] = av_clipl_int32(((ff1 + ff2) << 3) + (1 << 15)) >> 16;
407 lpc[LPC_ORDER - i - 1] = av_clipl_int32(((ff1 - ff2) << 3) +
423 int16_t *lpc_ptr = lpc;
450 for (j = 0; j < SUBFRAME_LEN - i; j++)
451 buf[i + j] += vector[j];
465 enum Rate cur_rate,
int pitch_lag,
int index)
502 for (i = 0; i < 8; i += 2) {
503 offset = ((cb_pos & 7) << 3) + cb_shift + i;
504 vector[
offset] = (cb_sign & 1) ? cb_gain : -cb_gain;
516 vector[i] += beta * vector[i - lag] >> 15;
524 static void get_residual(int16_t *residual, int16_t *prev_excitation,
int lag)
529 residual[0] = prev_excitation[
offset];
530 residual[1] = prev_excitation[offset + 1];
534 residual[i] = prev_excitation[offset + (i - 2) % lag];
540 return av_sat_add32(sum, sum);
551 const int16_t *cb_ptr;
552 int lag = pitch_lag + subfrm->
ad_cb_lag - 1;
569 vector[i] = av_sat_dadd32(1 << 15, av_sat_add32(sum, sum)) >> 16;
584 int pitch_lag,
int length,
int dir)
586 int limit, ccr, lag = 0;
593 limit = pitch_lag + 3;
595 for (i = pitch_lag - 3; i <= limit; i++) {
598 if (ccr > *ccr_max) {
617 int tgt_eng,
int ccr,
int res_eng)
624 temp1 = tgt_eng * res_eng >> 1;
625 temp2 = ccr * ccr << 1;
628 if (ccr >= res_eng) {
631 ppf->
opt_gain = (ccr << 15) / res_eng *
635 temp1 = (tgt_eng << 15) + (ccr * ppf->
opt_gain << 1);
637 pf_residual = av_sat_add32(temp1, temp2 + (1 << 15)) >> 16;
639 if (tgt_eng >= pf_residual << 1) {
642 temp1 = (tgt_eng << 14) / pf_residual;
679 int energy[5] = {0, 0, 0, 0, 0};
681 int fwd_lag =
autocorr_max(buf, offset, &energy[1], pitch_lag,
683 int back_lag =
autocorr_max(buf, offset, &energy[3], pitch_lag,
691 if (!back_lag && !fwd_lag)
707 for (i = 0; i < 5; i++)
708 temp1 =
FFMAX(energy[i], temp1);
711 for (i = 0; i < 5; i++)
712 energy[i] = (energy[i] << scale) >> 16;
714 if (fwd_lag && !back_lag) {
717 }
else if (!fwd_lag) {
726 temp1 = energy[4] * ((energy[1] * energy[1] + (1 << 14)) >> 15);
727 temp2 = energy[2] * ((energy[3] * energy[3] + (1 << 14)) >> 15);
728 if (temp1 >= temp2) {
749 int *exc_eng,
int *scale)
761 index =
autocorr_max(buf, offset, &ccr, pitch_lag, SUBFRAME_LEN * 2, -1);
762 ccr = av_sat_add32(ccr, 1 << 15) >> 16;
766 *exc_eng = av_sat_add32(tgt_eng, 1 << 15) >> 16;
772 best_eng =
dot_product(buf - index, buf - index, SUBFRAME_LEN * 2);
773 best_eng = av_sat_add32(best_eng, 1 << 15) >> 16;
775 temp = best_eng * *exc_eng >> 3;
777 if (temp < ccr * ccr) {
793 int gain,
int *rseed)
799 for (i = 0; i < lag; i++)
800 out[i] = vector_ptr[i - lag] * 3 >> 2;
805 *rseed = *rseed * 521 + 259;
806 out[i] = gain * *rseed >> 15;
808 memset(buf, 0, (FRAME_LEN +
PITCH_MAX) *
sizeof(*buf));
821 #define iir_filter(fir_coef, iir_coef, src, dest, width)\
824 int res_shift = 16 & ~-(width);\
825 int in_shift = 16 - res_shift;\
827 for (m = 0; m < SUBFRAME_LEN; m++) {\
829 for (n = 1; n <= LPC_ORDER; n++) {\
830 filter -= (fir_coef)[n - 1] * (src)[m - n] -\
831 (iir_coef)[n - 1] * ((dest)[m - n] >> in_shift);\
834 (dest)[m] = av_clipl_int32(((src)[m] << 16) + (filter << 3) +\
835 (1 << 15)) >> res_shift;\
854 int temp = buf[i] >> 2;
856 denom = av_sat_dadd32(denom, temp);
862 num = num << bits1 >> 1;
865 bits2 = 5 + bits1 -
bits2;
866 bits2 =
FFMAX(0, bits2);
868 gain = (num >> 1) / (denom >> 16);
876 buf[i] = av_clip_int16((buf[i] * (p->
pf_gain + (p->
pf_gain >> 4)) +
890 int16_t *
buf, int16_t *dst)
906 iir_filter(filter_coef[0], filter_coef[1], buf + i,
907 filter_signal + i, 1);
929 temp = auto_corr[1] >> 16;
931 temp = (auto_corr[0] >> 2) / temp;
938 dst[j] = av_sat_dadd32(signal_ptr[j],
939 (signal_ptr[j - 1] >> 16) * temp) >> 16;
943 temp = 2 * scale + 4;
945 energy = av_clipl_int32((int64_t)auto_corr[1] << -temp);
947 energy = auto_corr[1] >>
temp;
961 else if (gain < 0x20)
962 return gain - 8 << 7;
964 return gain - 20 << 8;
969 *state = (*state * 521 + 259) & 0xFFFF;
970 return (*state & 0x7FFF) * base >> 15;
975 int i,
shift, seg, seg2, t,
val, val_add, x,
y;
994 seg2 =
FFMIN(seg, 3);
998 for (i = 0; i <
shift; i++) {
999 t = seg * 32 + (val << seg2);
1008 t = seg * 32 + (val << seg2);
1011 t = seg * 32 + (val + 1 << seg2);
1013 val = (seg2 - 1 << 4) + val;
1017 t = seg * 32 + (val - 1 << seg2);
1019 val = (seg2 - 1 << 4) + val;
1033 int16_t *vector_ptr;
1045 for (i = 0; i < SUBFRAMES / 2; i++) {
1050 for (j = 0; j < 11; j++) {
1051 signs[i * 11 + j] = (t & 1) * 2 - 1 << 14;
1061 for (j = 0; j <
pulses[i]; j++, idx++) {
1064 pos[idx] = tmp[idx2] * 2 + off[i];
1065 tmp[idx2] = tmp[--t];
1083 t |=
FFABS(vector_ptr[j]);
1084 t =
FFMIN(t, 0x7FFF);
1094 for (j = 0; j < SUBFRAME_LEN * 2; j++) {
1095 t = vector_ptr[j] << -
shift;
1100 for (j = 0; j < SUBFRAME_LEN * 2; j++) {
1101 t = vector_ptr[j] >>
shift;
1108 for (j = 0; j < 11; j++)
1109 b0 += tmp[pos[(i / 2) * 11 + j]] * signs[(i / 2) * 11 + j];
1110 b0 = b0 * 2 * 2979LL + (1 << 29) >> 30;
1113 if (shift * 2 + 3 >= 0)
1114 c >>= shift * 2 + 3;
1116 c <<= -(shift * 2 + 3);
1117 c = (av_clipl_int32(sum << 1) -
c) * 2979LL >> 15;
1119 delta = b0 * b0 * 2 -
c;
1134 x = av_clip(x, -10000, 10000);
1136 for (j = 0; j < 11; j++) {
1137 idx = (i / 2) * 11 + j;
1138 vector_ptr[pos[idx]] = av_clip_int16(vector_ptr[pos[idx]] +
1139 (x * signs[idx] >> 15));
1143 memcpy(vector_ptr +
PITCH_MAX, vector_ptr,
1144 sizeof(*vector_ptr) * SUBFRAME_LEN * 2);
1145 vector_ptr += SUBFRAME_LEN * 2;
1153 int *got_frame_ptr,
AVPacket *avpkt)
1158 int buf_size = avpkt->
size;
1159 int dec_mode = buf[0] & 3;
1166 int bad_frame = 0, i, j,
ret;
1167 int16_t *audio = p->
audio;
1172 "Expected %d bytes, got %d - skipping packet\n",
1190 out = (int16_t *)frame->
data[0];
1221 int v = av_clip_int16(vector_ptr[j] << 1);
1222 vector_ptr[j] = av_clip_int16(v + acb_vector[j]);
1242 vector_ptr + i + ppf[j].
index,
1261 memset(frame->
data[0], 0,
1307 out[i] = av_clip_int16(p->
audio[LPC_ORDER + i] << 1);
1315 #define OFFSET(x) offsetof(G723_1_Context, x)
1316 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1320 { .i64 = 1 }, 0, 1,
AD },
1341 .priv_class = &g723_1dec_class,
1344 #if CONFIG_G723_1_ENCODER
1345 #define BITSTREAM_WRITER_LE
1364 }
else if (avctx->
bit_rate == 5300) {
1369 "Bitrate not supported, use 6.3k\n");
1385 static void highpass_filter(int16_t *
buf, int16_t *fir,
int *iir)
1389 *iir = (buf[i] << 15) + ((-*fir) << 15) +
MULL2(*iir, 0x7f00);
1391 buf[i] = av_clipl_int32((int64_t)*iir + (1 << 15)) >> 16;
1401 static void comp_autocorr(int16_t *buf, int16_t *autocorr)
1420 autocorr[0] = av_clipl_int32((int64_t)(temp << scale) +
1425 memset(autocorr + 1, 0,
LPC_ORDER *
sizeof(int16_t));
1430 autocorr[i] = av_clipl_int32((int64_t)temp + (1 << 15)) >> 16;
1443 static void levinson_durbin(int16_t *lpc, int16_t *autocorr, int16_t error)
1446 int16_t partial_corr;
1449 memset(lpc, 0,
LPC_ORDER *
sizeof(int16_t));
1454 for (j = 0; j < i; j++)
1455 temp -= lpc[j] * autocorr[i - j - 1];
1456 temp = ((autocorr[i] << 13) + temp) << 3;
1458 if (
FFABS(temp) >= (error << 16))
1461 partial_corr = temp / (error << 1);
1463 lpc[i] = av_clipl_int32((int64_t)(partial_corr << 14) +
1467 temp =
MULL2(temp, partial_corr);
1468 error = av_clipl_int32((int64_t)(error << 16) - temp +
1471 memcpy(vector, lpc, i *
sizeof(int16_t));
1472 for (j = 0; j < i; j++) {
1473 temp = partial_corr * vector[i - j - 1] << 1;
1474 lpc[j] = av_clipl_int32((int64_t)(lpc[j] << 16) - temp +
1487 static void comp_lpc_coeff(int16_t *buf, int16_t *lpc)
1490 int16_t *autocorr_ptr = autocorr;
1491 int16_t *lpc_ptr = lpc;
1495 comp_autocorr(buf + i, autocorr_ptr);
1496 levinson_durbin(lpc_ptr, autocorr_ptr + 1, autocorr_ptr[0]);
1503 static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
1518 f[0] = f[1] = 1 << 25;
1521 for (i = 0; i < LPC_ORDER / 2; i++) {
1523 f[2 * i + 2] = -f[2 * i] - ((lsp[i] + lsp[LPC_ORDER - 1 - i]) << 12);
1525 f[2 * i + 3] = f[2 * i + 1] - ((lsp[i] - lsp[LPC_ORDER - 1 - i]) << 12);
1530 f[LPC_ORDER + 1] >>= 1;
1534 for (i = 1; i < LPC_ORDER + 2; i++)
1539 for (i = 0; i < LPC_ORDER + 2; i++)
1540 f[i] = av_clipl_int32((int64_t)(f[i] << shift) + (1 << 15)) >> 16;
1548 for (i = 0; i <= LPC_ORDER / 2; i++)
1549 temp += f[2 * i] *
cos_tab[0];
1550 prev_val = av_clipl_int32(temp << 1);
1555 for (j = 0; j <= LPC_ORDER / 2; j++)
1557 cur_val = av_clipl_int32(temp << 1);
1560 if ((cur_val ^ prev_val) < 0) {
1561 int abs_cur =
FFABS(cur_val);
1562 int abs_prev =
FFABS(prev_val);
1563 int sum = abs_cur + abs_prev;
1567 abs_prev = abs_prev << shift >> 8;
1568 lsp[count++] = ((i - 1) << 7) + (abs_prev >> 1) / (sum >> 16);
1570 if (count == LPC_ORDER)
1578 for (j = 0; j <= LPC_ORDER / 2; j++){
1579 temp += f[LPC_ORDER - 2 * j + p] *
1582 cur_val = av_clipl_int32(temp<<1);
1587 if (count != LPC_ORDER)
1588 memcpy(lsp, prev_lsp, LPC_ORDER *
sizeof(int16_t));
1598 #define get_index(num, offset, size) \
1600 int error, max = -1;\
1603 for (i = 0; i < LSP_CB_SIZE; i++) {\
1604 for (j = 0; j < size; j++){\
1605 temp[j] = (weight[j + (offset)] * lsp_band##num[i][j] +\
1608 error = dot_product(lsp + (offset), temp, size) << 1;\
1609 error -= dot_product(lsp_band##num[i], temp, size);\
1612 lsp_index[num] = i;\
1623 static void lsp_quantize(
uint8_t *lsp_index, int16_t *lsp, int16_t *prev_lsp)
1630 weight[0] = (1 << 20) / (lsp[1] - lsp[0]);
1635 min =
FFMIN(lsp[i] - lsp[i - 1], lsp[i + 1] - lsp[i]);
1637 weight[i] = (1 << 20) / min;
1639 weight[i] = INT16_MAX;
1645 max =
FFMAX(weight[i], max);
1649 weight[i] <<=
shift;
1655 (((prev_lsp[i] -
dc_lsp[i]) * 12288 + (1 << 14)) >> 15);
1669 static void perceptual_filter(
G723_1_Context *p, int16_t *flt_coef,
1670 int16_t *unq_lpc, int16_t *buf)
1676 memcpy(vector, p->
fir_mem,
sizeof(int16_t) * LPC_ORDER);
1677 memcpy(vector + LPC_ORDER, buf + LPC_ORDER,
sizeof(int16_t) *
FRAME_LEN);
1683 flt_coef[k + 2 * l +
LPC_ORDER] = (unq_lpc[k + l] *
1687 iir_filter(flt_coef + 2 * l, flt_coef + 2 * l + LPC_ORDER, vector + i,
1691 memcpy(p->
iir_mem, buf + FRAME_LEN,
sizeof(int16_t) * LPC_ORDER);
1692 memcpy(p->
fir_mem, vector + FRAME_LEN,
sizeof(int16_t) * LPC_ORDER);
1701 static int estimate_pitch(int16_t *buf,
int start)
1704 int max_ccr = 0x4000;
1705 int max_eng = 0x7fff;
1709 int ccr, eng, orig_eng, ccr_eng, exp;
1716 for (i = PITCH_MIN; i <=
PITCH_MAX - 3; i++) {
1728 ccr = av_clipl_int32((int64_t)(ccr << exp) + (1 << 15)) >> 16;
1732 ccr = ccr << temp >> 16;
1736 eng = av_clipl_int32((int64_t)(orig_eng << temp) + (1 << 15)) >> 16;
1746 if (exp + 1 < max_exp)
1750 if (exp + 1 == max_exp)
1751 temp = max_ccr >> 1;
1754 ccr_eng = ccr * max_eng;
1755 diff = ccr_eng - eng *
temp;
1756 if (diff > 0 && (i - index < PITCH_MIN || diff > ccr_eng >> 2)) {
1774 static void comp_harmonic_coeff(int16_t *buf, int16_t pitch_lag,
HFParam *hf)
1776 int ccr, eng, max_ccr, max_eng;
1781 for (i = 0, j = pitch_lag - 3; j <= pitch_lag + 3; i++, j++) {
1793 for (i = 0; i < 15; i++)
1797 for (i = 0; i < 15; i++) {
1798 energy[i] = av_clipl_int32((int64_t)(energy[i] << exp) +
1807 for (i = 0; i <= 6; i++) {
1808 eng = energy[i << 1];
1809 ccr = energy[(i << 1) + 1];
1814 ccr = (ccr * ccr + (1 << 14)) >> 15;
1815 diff = ccr * max_eng - eng * max_ccr;
1823 if (hf->
index == -1) {
1824 hf->
index = pitch_lag;
1828 eng = energy[14] * max_eng;
1829 eng = (eng >> 2) + (eng >> 3);
1830 ccr = energy[(hf->
index << 1) + 1] * energy[(hf->
index << 1) + 1];
1832 eng = energy[(hf->
index << 1) + 1];
1837 hf->
gain = ((eng << 15) / max_eng * 0x2800 + (1 << 14)) >> 15;
1839 hf->
index += pitch_lag - 3;
1847 static void harmonic_filter(
HFParam *hf,
const int16_t *
src, int16_t *dest)
1853 dest[i] = av_clipl_int32((src[i] << 16) - temp + (1 << 15)) >> 16;
1857 static void harmonic_noise_sub(
HFParam *hf,
const int16_t *src, int16_t *dest)
1862 dest[i] = av_clipl_int32(((dest[i] - src[i]) << 16) + temp +
1877 static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc,
1878 int16_t *perf_fir, int16_t *perf_iir,
1879 const int16_t *src, int16_t *dest,
int scale)
1887 memcpy(buf_16, perf_fir,
sizeof(int16_t) * LPC_ORDER);
1888 memcpy(dest - LPC_ORDER, perf_iir,
sizeof(int16_t) * LPC_ORDER);
1893 temp -= qnt_lpc[j - 1] * bptr_16[i - j];
1895 buf[i] = (src[i] << 15) + (temp << 3);
1896 bptr_16[i] = av_clipl_int32(buf[i] + (1 << 15)) >> 16;
1900 int64_t fir = 0, iir = 0;
1902 fir -= perf_lpc[j - 1] * bptr_16[i - j];
1903 iir += perf_lpc[j + LPC_ORDER - 1] * dest[i - j];
1905 dest[i] = av_clipl_int32(((buf[i] + (fir << 3)) << scale) + (iir << 3) +
1908 memcpy(perf_fir, buf_16 + SUBFRAME_LEN,
sizeof(int16_t) * LPC_ORDER);
1909 memcpy(perf_iir, dest + SUBFRAME_LEN - LPC_ORDER,
1910 sizeof(int16_t) * LPC_ORDER);
1920 int16_t *impulse_resp,
const int16_t *buf,
1930 int pitch_lag = p->
pitch_lag[index >> 1];
1933 int odd_frame = index & 1;
1934 int iter = 3 + odd_frame;
1938 int i, j, k, l, max;
1948 for (i = 0; i < iter; i++) {
1953 for (k = 0; k <= j; k++)
1954 temp += residual[
PITCH_ORDER - 1 + k] * impulse_resp[j - k];
1955 flt_buf[
PITCH_ORDER - 1][j] = av_clipl_int32((temp << 1) +
1960 flt_buf[j][0] = ((residual[j] << 13) + (1 << 14)) >> 15;
1962 temp = (flt_buf[j + 1][k - 1] << 15) +
1963 residual[j] * impulse_resp[k];
1964 flt_buf[j][k] = av_clipl_int32((temp << 1) + (1 << 15)) >> 16;
1971 ccr_buf[count++] = av_clipl_int32(temp << 1);
1976 ccr_buf[count++] =
dot_product(flt_buf[j], flt_buf[j],
1981 for (k = 0; k < j; k++) {
1983 ccr_buf[count++] = av_clipl_int32(temp<<2);
1990 for (i = 0; i < 20 * iter; i++)
1995 for (i = 0; i < 20 * iter; i++){
1996 ccr_buf[i] = av_clipl_int32((int64_t)(ccr_buf[i] << temp) +
2001 for (i = 0; i < iter; i++) {
2003 if (!odd_frame && pitch_lag + i - 1 >=
SUBFRAME_LEN - 2 ||
2009 for (j = 0, k = 0; j < tbl_size; j++, k += 20) {
2011 for (l = 0; l < 20; l++)
2012 temp += ccr_buf[20 * i + l] * cb_tbl[k + l];
2013 temp = av_clipl_int32(temp);
2024 pitch_lag += acb_lag - 1;
2039 static void sub_acb_contrib(
const int16_t *residual,
const int16_t *impulse_resp,
2045 int64_t
temp = buf[i] << 14;
2046 for (j = 0; j <= i; j++)
2047 temp -= residual[j] * impulse_resp[i - j];
2049 buf[i] = av_clipl_int32((temp << 2) + (1 << 15)) >> 16;
2059 static void get_fcb_param(
FCBParam *optim, int16_t *impulse_resp,
2060 int16_t *buf,
int pulse_cnt,
int pitch_lag)
2069 int amp, err, max, max_amp_index,
min, scale, i, j, k, l;
2074 memcpy(impulse_r, impulse_resp,
sizeof(int16_t) *
SUBFRAME_LEN);
2076 if (pitch_lag < SUBFRAME_LEN - 2) {
2082 temp_corr[i] = impulse_r[i] >> 1;
2085 temp =
dot_product(temp_corr, temp_corr, SUBFRAME_LEN);
2088 impulse_corr[0] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16;
2091 temp =
dot_product(temp_corr + i, temp_corr, SUBFRAME_LEN - i);
2092 impulse_corr[i] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16;
2098 temp =
dot_product(buf + i, impulse_r, SUBFRAME_LEN - i);
2100 ccr1[i] = temp >> -scale;
2102 ccr1[i] = av_clipl_int32(temp << scale);
2110 temp =
FFABS(ccr1[j]);
2121 for (j = max_amp_index; j >= 2; j--) {
2123 impulse_corr[0] << 1);
2124 temp =
FFABS(temp - amp);
2133 for (j = 1; j < 5; j++) {
2138 param.
amp_index = max_amp_index + j - 2;
2144 for (k = 1; k < pulse_cnt; k++) {
2150 temp = av_clipl_int32((int64_t)temp *
2153 temp =
FFABS(ccr2[l]);
2166 memset(temp_corr, 0,
sizeof(int16_t) * SUBFRAME_LEN);
2168 for (k = 0; k < pulse_cnt; k++)
2171 for (k = SUBFRAME_LEN - 1; k >= 0; k--) {
2173 for (l = 0; l <= k; l++) {
2174 int prod = av_clipl_int32((int64_t)temp_corr[l] *
2175 impulse_r[k - l] << 1);
2176 temp = av_clipl_int32(temp + prod);
2178 temp_corr[k] = temp << 2 >> 16;
2185 prod = av_clipl_int32((int64_t)buf[k] * temp_corr[k] << 1);
2186 err = av_clipl_int32(err - prod);
2187 prod = av_clipl_int32((int64_t)temp_corr[k] * temp_corr[k]);
2188 err = av_clipl_int32(err + prod);
2192 if (err < optim->min_err) {
2198 for (k = 0; k < pulse_cnt; k++) {
2214 int16_t *buf,
int pulse_cnt)
2223 for (i = 0; i < SUBFRAME_LEN >> 1; i++) {
2247 int16_t *buf,
int index)
2254 get_fcb_param(&optim, impulse_resp, buf, pulse_cnt,
SUBFRAME_LEN);
2257 get_fcb_param(&optim, impulse_resp, buf, pulse_cnt,
2263 for (i = 0; i < pulse_cnt; i++)
2266 pack_fcb_param(&p->
subframe[index], &optim, buf, pulse_cnt);
2281 int info_bits, i,
temp;
2340 const AVFrame *frame,
int *got_packet_ptr)
2350 int16_t *
in = in_orig;
2363 comp_lpc_coeff(vector, unq_lpc);
2370 memcpy(vector + LPC_ORDER + SUBFRAME_LEN, in,
2374 memcpy(in, vector + LPC_ORDER,
sizeof(int16_t) *
FRAME_LEN);
2376 perceptual_filter(p, weighted_lpc, unq_lpc, vector);
2378 memcpy(in, vector + LPC_ORDER,
sizeof(int16_t) * FRAME_LEN);
2380 memcpy(vector + PITCH_MAX, in,
sizeof(int16_t) * FRAME_LEN);
2384 p->
pitch_lag[0] = estimate_pitch(vector, PITCH_MAX);
2385 p->
pitch_lag[1] = estimate_pitch(vector, PITCH_MAX + HALF_FRAME_LEN);
2388 comp_harmonic_coeff(vector + i, p->
pitch_lag[j >> 1], hf + j);
2391 memcpy(vector + PITCH_MAX, in,
sizeof(int16_t) * FRAME_LEN);
2392 memcpy(p->
prev_weight_sig, vector + FRAME_LEN,
sizeof(int16_t) * PITCH_MAX);
2395 harmonic_filter(hf + j, vector + PITCH_MAX + i, in + i);
2400 memcpy(p->
prev_lsp, cur_lsp,
sizeof(int16_t) * LPC_ORDER);
2413 memset(zero, 0,
sizeof(int16_t) * LPC_ORDER);
2414 memset(vector, 0,
sizeof(int16_t) * PITCH_MAX);
2415 memset(flt_in, 0,
sizeof(int16_t) * SUBFRAME_LEN);
2417 flt_in[0] = 1 << 13;
2418 synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
2419 zero, zero, flt_in, vector + PITCH_MAX, 1);
2420 harmonic_filter(hf + i, vector + PITCH_MAX, impulse_resp);
2424 memcpy(fir, p->
perf_fir_mem,
sizeof(int16_t) * LPC_ORDER);
2425 memcpy(iir, p->
perf_iir_mem,
sizeof(int16_t) * LPC_ORDER);
2427 synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
2428 fir, iir, flt_in, vector + PITCH_MAX, 0);
2429 memcpy(vector, p->
harmonic_mem,
sizeof(int16_t) * PITCH_MAX);
2430 harmonic_noise_sub(hf + i, vector + PITCH_MAX, in);
2432 acb_search(p, residual, impulse_resp, in, i);
2435 sub_acb_contrib(residual, impulse_resp, in);
2437 fcb_search(p, impulse_resp, in, i);
2444 sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
2446 in[j] = av_clip_int16((in[j] << 1) + impulse_resp[j]);
2448 sizeof(int16_t) * SUBFRAME_LEN);
2451 synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
2453 in, vector + PITCH_MAX, 0);
2455 sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
2456 memcpy(p->
harmonic_mem + PITCH_MAX - SUBFRAME_LEN, vector + PITCH_MAX,
2457 sizeof(int16_t) * SUBFRAME_LEN);
2468 *got_packet_ptr = 1;
2469 avpkt->
size = pack_bitstream(p, avpkt->
data, avpkt->
size);
2479 .
init = g723_1_encode_init,
2480 .encode2 = g723_1_encode_frame,
int16_t audio[FRAME_LEN+LPC_ORDER+PITCH_MAX+4]
static void lsp2lpc(int16_t *lpc)
Convert LSP frequencies to LPC coefficients.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const char const char void * val
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
static const int16_t lsp_band0[LSP_CB_SIZE][3]
LSP VQ tables.
static const int cng_bseg[3]
ptrdiff_t const GLvoid * data
Silence Insertion Descriptor frame.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define normalize_bits_int32(num)
#define AV_LOG_WARNING
Something somehow does not look correct.
int16_t prev_weight_sig[PITCH_MAX]
#define LIBAVUTIL_VERSION_INT
static const int16_t lsp_band2[LSP_CB_SIZE][4]
memory handling functions
static av_cold int init(AVCodecContext *avctx)
G723.1 unpacked data subframe.
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, const int16_t *in, int buffer_length, int filter_length, int stop_on_overflow, int shift, int rounder)
LP synthesis filter.
static int scale_vector(int16_t *dst, const int16_t *vector, int length)
Scale vector contents based on the largest of their absolutes.
int16_t fir_mem[LPC_ORDER]
static const int cng_filt[4]
int16_t excitation[PITCH_MAX+FRAME_LEN+4]
static int normalize_bits(int num, int width)
Calculate the number of left-shifts required for normalizing the input.
static void skip_put_bits(PutBitContext *s, int n)
Skip the given number of bits.
static int autocorr_max(const int16_t *buf, int offset, int *ccr_max, int pitch_lag, int length, int dir)
Estimate maximum auto-correlation around pitch lag.
static int comp_interp_index(G723_1_Context *p, int pitch_lag, int *exc_eng, int *scale)
Classify frames as voiced/unvoiced.
static const AVOption options[]
static void gen_dirac_train(int16_t *buf, int pitch_lag)
Generate a train of dirac functions with period as pitch lag.
static const AVClass g723_1dec_class
static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag, PPFParam *ppf, enum Rate cur_rate)
Calculate pitch postfilter parameters.
int av_log2_16bit(unsigned v)
static const int16_t percept_flt_tbl[2][LPC_ORDER]
0.5^i scaled by 2^15
static void postfilter(AMRContext *p, float *lpc, float *buf_out)
Perform adaptive post-filtering to enhance the quality of the speech.
static int16_t square_root(unsigned val)
Bitexact implementation of sqrt(val/2).
enum FrameType past_frame_type
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int g723_1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
enum AVSampleFormat sample_fmt
audio sample format
Optimized fixed codebook excitation parameters.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static const int16_t lsp_band1[LSP_CB_SIZE][3]
static void residual_interp(int16_t *buf, int16_t *out, int lag, int gain, int *rseed)
Peform residual interpolation based on frame classification.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf, int16_t *dst)
Perform formant filtering.
static const uint8_t bits2[81]
bitstream reader API header.
static const int16_t cos_tab[COS_TBL_SIZE+1]
Cosine table scaled by 2^14.
int16_t prev_data[HALF_FRAME_LEN]
static void get_residual(int16_t *residual, int16_t *prev_excitation, int lag)
Get delayed contribution from the previous excitation vector.
int16_t sid_lsp[LPC_ORDER]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define iir_filter(fir_coef, iir_coef, src, dest, width)
Perform IIR filtering.
int pulse_sign[PULSE_MAX]
static const int16_t postfilter_tbl[2][LPC_ORDER]
0.65^i (Zero part) and 0.75^i (Pole part) scaled by 2^15
FrameType
G723.1 frame types.
const char * name
Name of the codec implementation.
static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
Quantize LSP frequencies by interpolation and convert them to the corresponding LPC coefficients...
int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length)
returns the dot product of 2 int16_t vectors.
G723.1 compatible decoder data tables.
int16_t prev_excitation[PITCH_MAX]
static av_cold int g723_1_decode_init(AVCodecContext *avctx)
static const uint8_t offset[127][2]
Libavcodec external API header.
static void comp_ppf_gains(int lag, PPFParam *ppf, enum Rate cur_rate, int tgt_eng, int ccr, int res_eng)
Calculate pitch postfilter optimal and scaling gains.
uint64_t channel_layout
Audio channel layout.
static int estimate_sid_gain(G723_1_Context *p)
G723_1_Subframe subframe[4]
static const int16_t fixed_cb_gain[GAIN_LEVELS]
void ff_acelp_weighted_vector_sum(int16_t *out, const int16_t *in_a, const int16_t *in_b, int16_t weight_coeff_a, int16_t weight_coeff_b, int16_t rounder, int shift, int length)
weighted sum of two vectors with rounding.
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int64_t nb_samples_notify, AVRational time_base)
int bit_rate
the average bitrate
audio channel layout utility functions
int16_t synth_mem[LPC_ORDER]
#define normalize_bits_int16(num)
static const int16_t ppf_gain_weight[2]
Postfilter gain weighting factors scaled by 2^15.
int index
postfilter backward/forward lag
static const int16_t adaptive_cb_gain85[85 *20]
static const float pred[4]
void * av_memdup(const void *p, size_t size)
Duplicate the buffer p.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static const int16_t adaptive_cb_gain170[170 *20]
int16_t opt_gain
optimal gain
int frame_size
Number of samples per channel in an audio frame.
static const int16_t binomial_window[LPC_ORDER]
Binomial window coefficients scaled by 2^15.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static void gen_acb_excitation(int16_t *vector, int16_t *prev_excitation, int pitch_lag, G723_1_Subframe *subfrm, enum Rate cur_rate)
Generate adaptive codebook excitation.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
#define MULL2(a, b)
Bitexact implementation of 2ab scaled by 1/2^16.
Describe the class of an AVClass context structure.
int16_t sc_gain
scaling gain
static const int16_t bandwidth_expand[LPC_ORDER]
0.994^i scaled by 2^15
int16_t harmonic_mem[PITCH_MAX]
static const int16_t pitch_contrib[340]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe *subfrm, enum Rate cur_rate, int pitch_lag, int index)
Generate fixed codebook excitation vector.
static int dot_product(const int16_t *a, const int16_t *b, int length)
static int sid_gain_to_lsp_index(int gain)
enum FrameType cur_frame_type
static const int cng_adaptive_cb_lag[4]
int16_t hpf_fir_mem
highpass filter fir
static int weight(int i, int blen, int offset)
int16_t prev_lsp[LPC_ORDER]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int hpf_iir_mem
and iir memories
int pf_gain
formant postfilter gain scaling unit memory
#define CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
AVCodec ff_g723_1_decoder
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Pitch postfilter parameters.
int16_t perf_iir_mem[LPC_ORDER]
and iir memories
static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, int buf_size)
Unpack the frame into parameters.
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static const int16_t dc_lsp[LPC_ORDER]
LSP DC component.
static void gain_scale(G723_1_Context *p, int16_t *buf, int energy)
Adjust gain of postfiltered signal.
static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, uint8_t *lsp_index, int bad_frame)
Perform inverse quantization of LSP frequencies.
Harmonic filter parameters.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static int cng_rand(int *state, int base)
int channels
number of audio channels
static const int16_t hamming_window[LPC_FRAME]
Hamming window coefficients scaled by 2^15.
uint8_t lsp_index[LSP_BANDS]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static enum AVSampleFormat sample_fmts[]
static void generate_noise(G723_1_Context *p)
static const int8_t pulses[4]
Number of non-zero pulses in the MP-MLQ excitation.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
int16_t perf_fir_mem[LPC_ORDER]
perceptual filter fir
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
static const uint8_t bits1[81]
int ad_cb_lag
adaptive codebook lag
static const int32_t combinatorial_table[PULSE_MAX][SUBFRAME_LEN/GRID_SIZE]
Used for the coding/decoding of the pulses positions for the MP-MLQ codebook.