Lines Matching refs:tctx
71 static void eval_lpcenv(TwinVQContext *tctx, const float *cos_vals, float *lpc)
74 const TwinVQModeTab *mtab = tctx->mtab;
78 float cos_i = tctx->cos_tabs[0][i];
115 static inline void eval_lpcenv_or_interp(TwinVQContext *tctx,
121 const TwinVQModeTab *mtab = tctx->mtab;
122 const float *cos_tab = tctx->cos_tabs[ftype];
152 static void eval_lpcenv_2parts(TwinVQContext *tctx, enum TwinVQFrameType ftype,
156 eval_lpcenv_or_interp(tctx, ftype, lpc, buf, size / 2, step, 0);
157 eval_lpcenv_or_interp(tctx, ftype, lpc + size / 2, buf, size / 2,
172 static void dequant(TwinVQContext *tctx, const uint8_t *cb_bits, float *out,
179 for (i = 0; i < tctx->n_div[ftype]; i++) {
184 int length = tctx->length[ftype][i >= tctx->length_change[ftype]];
185 int bitstream_second_part = (i >= tctx->bits_main_spec_change[ftype]);
187 int bits = tctx->bits_main_spec[0][ftype][bitstream_second_part];
195 bits = tctx->bits_main_spec[1][ftype][bitstream_second_part];
207 out[tctx->permut[ftype][pos + j]] = sign0 * tab0[j] +
214 static void dec_gain(TwinVQContext *tctx,
217 const TwinVQModeTab *mtab = tctx->mtab;
218 const TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
220 int channels = tctx->avctx->ch_layout.nb_channels;
264 static void decode_lsp(TwinVQContext *tctx, int lpc_idx1, uint8_t *lpc_idx2,
267 const TwinVQModeTab *mtab = tctx->mtab;
304 static void dec_lpc_spectrum_inv(TwinVQContext *tctx, float *lsp,
308 int size = tctx->mtab->size / tctx->mtab->fmode[ftype].sub;
310 for (i = 0; i < tctx->mtab->n_lsp; i++)
315 eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 8);
318 eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 2);
321 eval_lpcenv(tctx, lsp, lpc);
328 static void imdct_and_window(TwinVQContext *tctx, enum TwinVQFrameType ftype,
331 FFTContext *mdct = &tctx->mdct_ctx[ftype];
332 const TwinVQModeTab *mtab = tctx->mtab;
335 float *buf1 = tctx->tmp_buf;
337 float *out = tctx->curr_frame + 2 * ch * mtab->size;
362 tctx->fdsp->vector_fmul_window(out2, prev_buf + (bsize - wsize) / 2,
376 tctx->last_block_pos[ch] = (size + first_wsize) / 2;
379 static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype,
382 const TwinVQModeTab *mtab = tctx->mtab;
383 float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0];
384 int channels = tctx->avctx->ch_layout.nb_channels;
389 imdct_and_window(tctx, ftype, wtype,
390 tctx->spectrum + i * mtab->size,
397 size2 = tctx->last_block_pos[0];
402 memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1));
408 memcpy(out2 + size1, &tctx->curr_frame[2 * mtab->size],
410 tctx->fdsp->butterflies_float(out1, out2, mtab->size);
414 static void read_and_decode_spectrum(TwinVQContext *tctx, float *out,
417 const TwinVQModeTab *mtab = tctx->mtab;
418 TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
419 int channels = tctx->avctx->ch_layout.nb_channels;
427 dequant(tctx, bits->main_coeffs, out, ftype,
431 dec_gain(tctx, ftype, gain);
434 int cb_len_p = (tctx->n_div[3] + mtab->ppc_shape_len * channels - 1) /
435 tctx->n_div[3];
436 dequant(tctx, bits->ppc_coeffs, ppc_shape,
447 tctx->dec_bark_env(tctx, bits->bark1[i][j],
449 tctx->tmp_buf, gain[sub * i + j], ftype);
451 tctx->fdsp->vector_fmul(chunk + block_size * j,
453 tctx->tmp_buf, block_size);
457 tctx->decode_ppc(tctx, bits->p_coef[i], bits->g_coef[i],
460 decode_lsp(tctx, bits->lpc_idx1[i], bits->lpc_idx2[i],
461 bits->lpc_hist_idx[i], lsp, tctx->lsp_hist[i]);
463 dec_lpc_spectrum_inv(tctx, lsp, ftype, tctx->tmp_buf);
466 tctx->fdsp->vector_fmul(chunk, chunk, tctx->tmp_buf, block_size);
483 TwinVQContext *tctx = avctx->priv_data;
484 const TwinVQModeTab *mtab = tctx->mtab;
489 if (tctx->discarded_packets >= 2) {
490 frame->nb_samples = mtab->size * tctx->frames_per_packet;
502 if ((ret = tctx->read_bitstream(avctx, tctx, buf, buf_size)) < 0)
505 for (tctx->cur_frame = 0; tctx->cur_frame < tctx->frames_per_packet;
506 tctx->cur_frame++) {
507 read_and_decode_spectrum(tctx, tctx->spectrum,
508 tctx->bits[tctx->cur_frame].ftype);
510 imdct_output(tctx, tctx->bits[tctx->cur_frame].ftype,
511 tctx->bits[tctx->cur_frame].window_type, out,
512 tctx->cur_frame * mtab->size);
514 FFSWAP(float *, tctx->curr_frame, tctx->prev_frame);
517 if (tctx->discarded_packets < 2) {
518 tctx->discarded_packets++;
534 static av_cold int init_mdct_win(TwinVQContext *tctx)
537 const TwinVQModeTab *mtab = tctx->mtab;
540 int channels = tctx->avctx->ch_layout.nb_channels;
545 int bsize = tctx->mtab->size / tctx->mtab->fmode[i].sub;
546 if ((ret = ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1,
551 if (!FF_ALLOC_TYPED_ARRAY(tctx->tmp_buf, mtab->size) ||
552 !FF_ALLOC_TYPED_ARRAY(tctx->spectrum, table_size) ||
553 !FF_ALLOC_TYPED_ARRAY(tctx->curr_frame, table_size) ||
554 !FF_ALLOC_TYPED_ARRAY(tctx->prev_frame, table_size))
560 if (!FF_ALLOC_TYPED_ARRAY(tctx->cos_tabs[i], m / 4))
563 tctx->cos_tabs[i][j] = cos((2 * j + 1) * freq);
565 tctx->cos_tabs[i][m / 4 - j] = tctx->cos_tabs[i][j];
641 static av_cold void construct_perm_table(TwinVQContext *tctx,
645 const TwinVQModeTab *mtab = tctx->mtab;
646 int16_t *tmp_perm = (int16_t *)tctx->tmp_buf;
649 size = tctx->avctx->ch_layout.nb_channels;
652 size = tctx->avctx->ch_layout.nb_channels * mtab->fmode[ftype].sub;
656 permutate_in_line(tmp_perm, tctx->n_div[ftype], size,
657 block_size, tctx->length[ftype],
658 tctx->length_change[ftype], ftype);
660 transpose_perm(tctx->permut[ftype], tmp_perm, tctx->n_div[ftype],
661 tctx->length[ftype], tctx->length_change[ftype]);
663 linear_perm(tctx->permut[ftype], tctx->permut[ftype], size,
667 static av_cold void init_bitstream_params(TwinVQContext *tctx)
669 const TwinVQModeTab *mtab = tctx->mtab;
670 int n_ch = tctx->avctx->ch_layout.nb_channels;
671 int total_fr_bits = tctx->avctx->bit_rate * mtab->size /
672 tctx->avctx->sample_rate;
698 if (tctx->codec == TWINVQ_CODEC_METASOUND && !tctx->is_6kbps) {
715 tctx->n_div[i] = (bit_size + 13) / 14;
717 rounded_up = (bit_size + tctx->n_div[i] - 1) /
718 tctx->n_div[i];
719 rounded_down = (bit_size) / tctx->n_div[i];
720 num_rounded_down = rounded_up * tctx->n_div[i] - bit_size;
721 num_rounded_up = tctx->n_div[i] - num_rounded_down;
722 tctx->bits_main_spec[0][i][0] = (rounded_up + 1) / 2;
723 tctx->bits_main_spec[1][i][0] = rounded_up / 2;
724 tctx->bits_main_spec[0][i][1] = (rounded_down + 1) / 2;
725 tctx->bits_main_spec[1][i][1] = rounded_down / 2;
726 tctx->bits_main_spec_change[i] = num_rounded_up;
728 rounded_up = (vect_size + tctx->n_div[i] - 1) /
729 tctx->n_div[i];
730 rounded_down = (vect_size) / tctx->n_div[i];
731 num_rounded_down = rounded_up * tctx->n_div[i] - vect_size;
732 num_rounded_up = tctx->n_div[i] - num_rounded_down;
733 tctx->length[i][0] = rounded_up;
734 tctx->length[i][1] = rounded_down;
735 tctx->length_change[i] = num_rounded_up;
739 construct_perm_table(tctx, frametype);
744 TwinVQContext *tctx = avctx->priv_data;
748 ff_mdct_end(&tctx->mdct_ctx[i]);
749 av_freep(&tctx->cos_tabs[i]);
752 av_freep(&tctx->curr_frame);
753 av_freep(&tctx->spectrum);
754 av_freep(&tctx->prev_frame);
755 av_freep(&tctx->tmp_buf);
756 av_freep(&tctx->fdsp);
764 TwinVQContext *tctx = avctx->priv_data;
767 tctx->avctx = avctx;
771 avctx->block_align = tctx->frame_size + 7 >> 3;
773 frames_per_packet = avctx->block_align * 8LL / tctx->frame_size;
776 avctx->block_align * (int64_t)8, tctx->frame_size);
784 tctx->frames_per_packet = frames_per_packet;
786 tctx->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
787 if (!tctx->fdsp)
789 if ((ret = init_mdct_win(tctx))) {
793 init_bitstream_params(tctx);
795 twinvq_memset_float(tctx->bark_hist[0][0], 0.1,
796 FF_ARRAY_ELEMS(tctx->bark_hist));