51 float two_cos_w = 2.0f * cos_val;
53 for (j = 0; j + 1 < order; j += 2 * 2) {
55 q *= lsp[j] - two_cos_w;
56 p *= lsp[j + 1] - two_cos_w;
58 q *= lsp[j + 2] - two_cos_w;
59 p *= lsp[j + 3] - two_cos_w;
62 p *= p * (2.0f - two_cos_w);
63 q *= q * (2.0f + two_cos_w);
77 for (i = 0; i < size_s / 2; i++) {
87 float step = (v1 - v2) / (size + 1);
89 for (i = 0; i <
size; i++) {
97 return part ? -cos_tab[size - idx - 1]
117 float *
out,
const float *
in,
118 int size,
int step,
int part)
125 for (i = 0; i <
size; i += step)
128 get_cos(i, part, cos_tab, size),
132 for (i = step; i <= size - 2 * step; i += step) {
133 if (out[i + step] + out[i - step] > 1.95 * out[i] ||
134 out[i + step] >= out[i - step]) {
135 interpolate(out + i - step + 1, out[i], out[i - step], step - 1);
139 get_cos(i - step / 2, part, cos_tab, size),
142 out[i - step], step / 2 - 1);
144 out[i - step / 2], step / 2 - 1);
148 interpolate(out + size - 2 * step + 1, out[size - step],
149 out[size - 2 * step], step - 1);
153 const float *
buf,
float *lpc,
160 interpolate(lpc + size / 2 - step + 1, lpc[size / 2],
161 lpc[size / 2 - step], step);
174 const int16_t *cb0,
const int16_t *cb1,
int cb_len)
179 for (i = 0; i < tctx->
n_div[ftype]; i++) {
183 const int16_t *tab0, *
tab1;
203 tab0 = cb0 + tmp0 * cb_len;
204 tab1 = cb1 + tmp1 * cb_len;
206 for (j = 0; j <
length; j++)
207 out[tctx->
permut[ftype][pos + j]] = sign0 * tab0[j] +
226 out[i] = (1.0 / (1 << 13)) *
231 float val = (1.0 / (1 << 23)) *
235 for (j = 0; j < sub; j++)
253 float min_dist2 = min_dist * 0.5;
254 for (i = 1; i < order; i++)
255 if (lsp[i] - lsp[i - 1] < min_dist) {
256 float avg = (lsp[i] + lsp[i - 1]) * 0.5;
258 lsp[i - 1] = avg - min_dist2;
259 lsp[i] = avg + min_dist2;
264 int lpc_hist_idx,
float *lsp,
float *hist)
271 const float *cb3 = cb2 + (1 << mtab->
lsp_bit2) * mtab->
n_lsp;
273 const int8_t funny_rounding[4] = {
282 int chunk_end = ((i + 1) * mtab->
n_lsp + funny_rounding[i]) /
284 for (; j < chunk_end; j++)
285 lsp[j] = cb[lpc_idx1 * mtab->
n_lsp + j] +
286 cb2[lpc_idx2[i] * mtab->
n_lsp + j];
291 for (i = 0; i < mtab->
n_lsp; i++) {
292 float tmp1 = 1.0 - cb3[lpc_hist_idx * mtab->
n_lsp + i];
293 float tmp2 = hist[i] * cb3[lpc_hist_idx * mtab->
n_lsp + i];
295 lsp[i] = lsp[i] * tmp1 + tmp2;
310 lsp[i] = 2 * cos(lsp[i]);
328 int wtype,
float *
in,
float *prev,
int ch)
335 int j, first_wsize, wsize;
339 int types_sizes[] = {
347 prev_buf = prev + (size - bsize) / 2;
349 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
352 if (!j && wtype == 4)
354 else if (j == mtab->
fmode[ftype].
sub - 1 && wtype == 7)
357 wsize = types_sizes[wtype_to_wsize[sub_wtype]];
359 mdct->
imdct_half(mdct, buf1 + bsize * j, in + bsize * j);
367 memcpy(out2, buf1 + bsize * j + wsize / 2,
368 (bsize - wsize / 2) *
sizeof(
float));
372 prev_buf = buf1 + bsize * j + bsize / 2;
379 int wtype,
float **out,
int offset)
389 prev_buf + 2 * i * mtab->
size,
396 size1 = mtab->
size - size2;
398 out1 = &out[0][0] +
offset;
399 memcpy(out1, prev_buf, size1 *
sizeof(*out1));
400 memcpy(out1 + size1, tctx->
curr_frame, size2 *
sizeof(*out1));
403 out2 = &out[1][0] +
offset;
404 memcpy(out2, &prev_buf[2 * mtab->
size],
405 size1 *
sizeof(*out2));
407 size2 *
sizeof(*out2));
419 int block_size = mtab->
size / sub;
440 for (i = 0; i < channels; i++) {
441 float *chunk = out + mtab->
size * i;
444 for (j = 0; j < sub; j++) {
447 tctx->
tmp_buf, gain[sub * i + j], ftype);
450 chunk + block_size * j,
463 for (j = 0; j < mtab->
fmode[ftype].
sub; j++) {
477 int *got_frame_ptr,
AVPacket *avpkt)
481 int buf_size = avpkt->
size;
495 if (buf_size < avctx->block_align) {
497 "Frame too small (%d bytes). Truncated file?\n", buf_size);
540 float norm = channels == 1 ? 2.0 : 1.0;
542 for (i = 0; i < 3; i++) {
545 -sqrt(norm / bsize) / (1 << 15))))
562 for (i = 0; i < 3; i++) {
564 double freq = 2 *
M_PI /
m;
566 (m / 4),
sizeof(*tctx->
cos_tabs[i]), alloc_fail);
568 for (j = 0; j <= m / 8; j++)
569 tctx->
cos_tabs[i][j] = cos((2 * j + 1) * freq);
570 for (j = 1; j < m / 8; j++)
592 const uint8_t line_len[2],
int length_div,
597 for (i = 0; i < line_len[0]; i++) {
600 if (num_blocks == 1 ||
610 for (j = 0; j < num_vect && (j + num_vect * i < block_size * num_blocks); j++)
611 tab[i * num_vect + j] = i * num_vect + (j + shift) % num_vect;
631 const uint8_t line_len[2],
int length_div)
636 for (i = 0; i < num_vect; i++)
637 for (j = 0; j < line_len[i >= length_div]; j++)
638 out[cont++] = in[j * num_vect + i];
641 static void linear_perm(int16_t *out, int16_t *in,
int n_blocks,
int size)
643 int block_size = size / n_blocks;
646 for (i = 0; i <
size; i++)
647 out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks;
653 int block_size,
size;
655 int16_t *tmp_perm = (int16_t *)tctx->
tmp_buf;
666 block_size, tctx->
length[ftype],
689 int bsize_no_main_cb[3], bse_bits[3], i;
692 for (i = 0; i < 3; i++)
698 bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits +
701 for (i = 0; i < 2; i++)
702 bsize_no_main_cb[i] =
703 lsp_bits_per_block + n_ch * TWINVQ_GAIN_BITS +
708 bsize_no_main_cb[1] += 2;
709 bsize_no_main_cb[2] += 2;
713 for (i = 0; i < 4; i++) {
714 int bit_size, vect_size;
715 int rounded_up, rounded_down, num_rounded_down, num_rounded_up;
720 bit_size = total_fr_bits - bsize_no_main_cb[i];
721 vect_size = n_ch * mtab->
size;
724 tctx->
n_div[i] = (bit_size + 13) / 14;
726 rounded_up = (bit_size + tctx->
n_div[i] - 1) /
728 rounded_down = (bit_size) / tctx->
n_div[i];
729 num_rounded_down = rounded_up * tctx->
n_div[i] - bit_size;
730 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
737 rounded_up = (vect_size + tctx->
n_div[i] - 1) /
739 rounded_down = (vect_size) / tctx->
n_div[i];
740 num_rounded_down = rounded_up * tctx->
n_div[i] - vect_size;
741 num_rounded_up = tctx->
n_div[i] - num_rounded_down;
742 tctx->
length[i][0] = rounded_up;
743 tctx->
length[i][1] = rounded_down;
756 for (i = 0; i < 3; i++) {