41 #define BITSTREAM_WRITER_LE
48 2621, 2631, 2659, 2705, 2770, 2853, 2955, 3074, 3212, 3367,
49 3541, 3731, 3939, 4164, 4405, 4663, 4937, 5226, 5531, 5851,
50 6186, 6534, 6897, 7273, 7661, 8062, 8475, 8899, 9334, 9780,
51 10235, 10699, 11172, 11653, 12141, 12636, 13138, 13645, 14157, 14673,
52 15193, 15716, 16242, 16769, 17298, 17827, 18356, 18884, 19411, 19935,
53 20457, 20975, 21489, 21999, 22503, 23002, 23494, 23978, 24455, 24924,
54 25384, 25834, 26274, 26704, 27122, 27529, 27924, 28306, 28675, 29031,
55 29373, 29700, 30012, 30310, 30592, 30857, 31107, 31340, 31557, 31756,
56 31938, 32102, 32249, 32377, 32488, 32580, 32654, 32710, 32747, 32766,
57 32766, 32747, 32710, 32654, 32580, 32488, 32377, 32249, 32102, 31938,
58 31756, 31557, 31340, 31107, 30857, 30592, 30310, 30012, 29700, 29373,
59 29031, 28675, 28306, 27924, 27529, 27122, 26704, 26274, 25834, 25384,
60 24924, 24455, 23978, 23494, 23002, 22503, 21999, 21489, 20975, 20457,
61 19935, 19411, 18884, 18356, 17827, 17298, 16769, 16242, 15716, 15193,
62 14673, 14157, 13645, 13138, 12636, 12141, 11653, 11172, 10699, 10235,
63 9780, 9334, 8899, 8475, 8062, 7661, 7273, 6897, 6534, 6186,
64 5851, 5531, 5226, 4937, 4663, 4405, 4164, 3939, 3731, 3541,
65 3367, 3212, 3074, 2955, 2853, 2770, 2705, 2659, 2631, 2621
72 32749, 32695, 32604, 32477, 32315, 32118, 31887, 31622, 31324, 30995
79 32571, 32376, 32182, 31989, 31797, 31606, 31416, 31228, 31040, 30854
87 {29491, 26542, 23888, 21499, 19349, 17414, 15673, 14106, 12695, 11425},
89 {16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32}
109 }
else if (avctx->
bit_rate == 5300) {
134 *iir = (buf[
i] << 15) + ((-*fir) << 15) +
MULL2(*iir, 0x7f00);
170 memset(autocorr + 1, 0,
LPC_ORDER *
sizeof(int16_t));
191 int16_t partial_corr;
194 memset(lpc, 0,
LPC_ORDER *
sizeof(int16_t));
199 for (j = 0; j <
i; j++)
200 temp -= lpc[j] * autocorr[
i - j - 1];
201 temp = ((autocorr[
i] << 13) +
temp) << 3;
216 memcpy(vector, lpc,
i *
sizeof(int16_t));
217 for (j = 0; j <
i; j++) {
218 temp = partial_corr * vector[
i - j - 1] << 1;
235 int16_t *autocorr_ptr = autocorr;
236 int16_t *lpc_ptr = lpc;
248 static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
254 int max,
shift, cur_val, prev_val, count, p;
263 f[0] =
f[1] = 1 << 25;
270 f[2 *
i + 3] =
f[2 *
i + 1] - ((lsp[
i] - lsp[
LPC_ORDER - 1 -
i]) << 12);
305 if ((cur_val ^ prev_val) < 0) {
306 int abs_cur =
FFABS(cur_val);
307 int abs_prev =
FFABS(prev_val);
308 int sum = abs_cur + abs_prev;
312 abs_prev = abs_prev << shift >> 8;
313 lsp[count++] = ((
i - 1) << 7) + (abs_prev >> 1) / (sum >> 16);
332 memcpy(lsp, prev_lsp,
LPC_ORDER *
sizeof(int16_t));
342 #define get_index(num, offset, size) \
344 int error, max = -1; \
348 for (i = 0; i < LSP_CB_SIZE; i++) { \
349 for (j = 0; j < size; j++){ \
350 temp[j] = (weight[j + (offset)] * ff_g723_1_lsp_band##num[i][j] + \
353 error = ff_g723_1_dot_product(lsp + (offset), temp, size) << 1; \
354 error -= ff_g723_1_dot_product(ff_g723_1_lsp_band##num[i], temp, size); \
357 lsp_index[num] = i; \
368 static void lsp_quantize(uint8_t *lsp_index, int16_t *lsp, int16_t *prev_lsp)
375 weight[0] = (1 << 20) / (lsp[1] - lsp[0]);
400 (((prev_lsp[
i] -
dc_lsp[
i]) * 12288 + (1 << 14)) >> 15);
417 int16_t *
src, int16_t *dest)
425 iir_coef[n - 1] * dest[m - n];
440 int16_t *unq_lpc, int16_t *buf)
453 flt_coef[k + 2 * l +
LPC_ORDER] = (unq_lpc[k + l] *
458 vector +
i, buf +
i);
474 int max_ccr = 0x4000;
475 int max_eng = 0x7fff;
479 int ccr, eng, orig_eng, ccr_eng,
exp;
502 ccr = ccr << temp >> 16;
516 if (
exp + 1 < max_exp)
520 if (
exp + 1 == max_exp)
524 ccr_eng = ccr * max_eng;
526 if (
diff > 0 && (
i - index < PITCH_MIN || diff > ccr_eng >> 2)) {
546 int ccr, eng, max_ccr, max_eng;
551 for (
i = 0, j = pitch_lag - 3; j <= pitch_lag + 3;
i++, j++) {
563 for (
i = 0;
i < 15;
i++)
567 for (
i = 0;
i < 15;
i++) {
577 for (
i = 0;
i <= 6;
i++) {
578 eng = energy[
i << 1];
579 ccr = energy[(
i << 1) + 1];
584 ccr = (ccr * ccr + (1 << 14)) >> 15;
585 diff = ccr * max_eng - eng * max_ccr;
593 if (hf->
index == -1) {
594 hf->
index = pitch_lag;
598 eng = energy[14] * max_eng;
599 eng = (eng >> 2) + (eng >> 3);
600 ccr = energy[(hf->
index << 1) + 1] * energy[(hf->
index << 1) + 1];
602 eng = energy[(hf->
index << 1) + 1];
607 hf->
gain = ((eng << 15) / max_eng * 0x2800 + (1 << 14)) >> 15;
609 hf->
index += pitch_lag - 3;
647 int16_t *perf_fir, int16_t *perf_iir,
648 const int16_t *
src, int16_t *dest,
int scale)
656 memcpy(buf_16, perf_fir,
sizeof(int16_t) *
LPC_ORDER);
662 temp -= qnt_lpc[j - 1] * bptr_16[
i - j];
669 int64_t fir = 0, iir = 0;
671 fir -= perf_lpc[j - 1] * bptr_16[
i - j];
672 iir += perf_lpc[j +
LPC_ORDER - 1] * dest[
i - j];
689 int16_t *impulse_resp,
const int16_t *buf,
701 int odd_frame =
index & 1;
702 int iter = 3 + odd_frame;
716 for (
i = 0;
i < iter;
i++) {
721 for (k = 0; k <= j; k++)
728 flt_buf[j][0] = ((residual[j] << 13) + (1 << 14)) >> 15;
730 temp = (flt_buf[j + 1][k - 1] << 15) +
731 residual[j] * impulse_resp[k];
749 for (k = 0; k < j; k++) {
758 for (
i = 0;
i < 20 * iter;
i++)
763 for (
i = 0;
i < 20 * iter;
i++)
768 for (
i = 0;
i < iter;
i++) {
776 for (j = 0, k = 0; j < tbl_size; j++, k += 20) {
778 for (l = 0; l < 20; l++)
779 temp += ccr_buf[20 *
i + l] * cb_tbl[k + l];
791 pitch_lag += acb_lag - 1;
812 int64_t
temp = buf[
i] << 14;
813 for (j = 0; j <=
i; j++)
814 temp -= residual[j] * impulse_resp[
i - j];
827 int16_t *buf,
int pulse_cnt,
int pitch_lag)
836 int amp, err,
max, max_amp_index,
min,
scale,
i, j, k, l;
841 memcpy(impulse_r, impulse_resp,
sizeof(int16_t) *
SUBFRAME_LEN);
849 temp_corr[
i] = impulse_r[
i] >> 1;
889 for (j = max_amp_index; j >= 2; j--) {
891 impulse_corr[0] << 1);
901 for (j = 1; j < 5; j++) {
912 for (k = 1; k < pulse_cnt; k++) {
936 for (k = 0; k < pulse_cnt; k++)
941 for (l = 0; l <= k; l++) {
943 impulse_r[k - l] << 1);
946 temp_corr[k] = temp << 2 >> 16;
960 if (err < optim->min_err) {
966 for (k = 0; k < pulse_cnt; k++) {
982 int16_t *buf,
int pulse_cnt)
991 for (
i = 0; i < SUBFRAME_LEN >> 1;
i++) {
1017 int16_t *buf,
int index)
1033 for (
i = 0;
i < pulse_cnt;
i++)
1115 int16_t *in, *start;
1179 memset(vector, 0,
sizeof(int16_t) *
PITCH_MAX);
1182 flt_in[0] = 1 << 13;
1193 fir, iir, flt_in, vector +
PITCH_MAX, 0);
1236 *got_packet_ptr = 1;