diff options
author | Vittorio Giovara <vittorio.giovara@gmail.com> | 2017-04-03 14:09:47 +0200 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:45 -0300 |
commit | 9386ca98b622e8a7bde3ede49737e91d6c2b3a01 (patch) | |
tree | a474b6e72da171c4e2ece4bfb2b70df7bba05738 | |
parent | 1191ffd50a756fc621b34eb8f84a583c35f3573a (diff) | |
download | ffmpeg-9386ca98b622e8a7bde3ede49737e91d6c2b3a01.tar.gz |
twinvq: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavcodec/twinvq.c | 20 | ||||
-rw-r--r-- | libavcodec/twinvqdec.c | 18 |
2 files changed, 20 insertions, 18 deletions
diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c index 38482e8c21..77dfa31dc2 100644 --- a/libavcodec/twinvq.c +++ b/libavcodec/twinvq.c @@ -217,17 +217,18 @@ static void dec_gain(TwinVQContext *tctx, const TwinVQModeTab *mtab = tctx->mtab; const TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame]; int i, j; + int channels = tctx->avctx->ch_layout.nb_channels; int sub = mtab->fmode[ftype].sub; float step = TWINVQ_AMP_MAX / ((1 << TWINVQ_GAIN_BITS) - 1); float sub_step = TWINVQ_SUB_AMP_MAX / ((1 << TWINVQ_SUB_GAIN_BITS) - 1); if (ftype == TWINVQ_FT_LONG) { - for (i = 0; i < tctx->avctx->channels; i++) + for (i = 0; i < channels; i++) out[i] = (1.0 / (1 << 13)) * twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i], TWINVQ_AMP_MAX, TWINVQ_MULAW_MU); } else { - for (i = 0; i < tctx->avctx->channels; i++) { + for (i = 0; i < channels; i++) { float val = (1.0 / (1 << 23)) * twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i], TWINVQ_AMP_MAX, TWINVQ_MULAW_MU); @@ -380,10 +381,11 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype, { const TwinVQModeTab *mtab = tctx->mtab; float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0]; + int channels = tctx->avctx->ch_layout.nb_channels; int size1, size2, i; float *out1, *out2; - for (i = 0; i < tctx->avctx->channels; i++) + for (i = 0; i < channels; i++) imdct_and_window(tctx, ftype, wtype, tctx->spectrum + i * mtab->size, prev_buf + 2 * i * mtab->size, @@ -399,7 +401,7 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype, memcpy(out1, prev_buf, size1 * sizeof(*out1)); memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1)); - if (tctx->avctx->channels == 2) { + if (channels == 2) { out2 = &out[1][0] + offset; memcpy(out2, &prev_buf[2 * mtab->size], size1 * sizeof(*out2)); @@ -414,7 +416,7 @@ static void read_and_decode_spectrum(TwinVQContext *tctx, float *out, { const TwinVQModeTab *mtab = tctx->mtab; TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame]; - int channels = tctx->avctx->channels; + int channels = tctx->avctx->ch_layout.nb_channels; int sub = mtab->fmode[ftype].sub; int block_size = mtab->size / sub; float gain[TWINVQ_CHANNELS_MAX * TWINVQ_SUBBLOCKS_MAX]; @@ -536,7 +538,7 @@ static av_cold int init_mdct_win(TwinVQContext *tctx) const TwinVQModeTab *mtab = tctx->mtab; int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub; int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub; - int channels = tctx->avctx->channels; + int channels = tctx->avctx->ch_layout.nb_channels; float norm = channels == 1 ? 2.0 : 1.0; int table_size = 2 * mtab->size * channels; @@ -645,10 +647,10 @@ static av_cold void construct_perm_table(TwinVQContext *tctx, int16_t *tmp_perm = (int16_t *)tctx->tmp_buf; if (ftype == TWINVQ_FT_PPC) { - size = tctx->avctx->channels; + size = tctx->avctx->ch_layout.nb_channels; block_size = mtab->ppc_shape_len; } else { - size = tctx->avctx->channels * mtab->fmode[ftype].sub; + size = tctx->avctx->ch_layout.nb_channels * mtab->fmode[ftype].sub; block_size = mtab->size / mtab->fmode[ftype].sub; } @@ -666,7 +668,7 @@ static av_cold void construct_perm_table(TwinVQContext *tctx, static av_cold void init_bitstream_params(TwinVQContext *tctx) { const TwinVQModeTab *mtab = tctx->mtab; - int n_ch = tctx->avctx->channels; + int n_ch = tctx->avctx->ch_layout.nb_channels; int total_fr_bits = tctx->avctx->bit_rate * mtab->size / tctx->avctx->sample_rate; diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c index 090a9fb0eb..0e35110150 100644 --- a/libavcodec/twinvqdec.c +++ b/libavcodec/twinvqdec.c @@ -181,7 +181,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, { const TwinVQModeTab *mtab = tctx->mtab; int isampf = tctx->avctx->sample_rate / 1000; - int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels); + int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->ch_layout.nb_channels); int min_period = ROUNDED_DIV(40 * 2 * mtab->size, isampf); int max_period = ROUNDED_DIV(40 * 2 * mtab->size * 6, isampf); int period_range = max_period - min_period; @@ -254,7 +254,7 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, { TwinVQFrameData *bits = &tctx->bits[0]; const TwinVQModeTab *mtab = tctx->mtab; - int channels = tctx->avctx->channels; + int channels = tctx->avctx->ch_layout.nb_channels; int sub; GetBitContext gb; int i, j, k, ret; @@ -319,14 +319,14 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, static av_cold int twinvq_decode_init(AVCodecContext *avctx) { - int isampf, ibps; + int isampf, ibps, channels; TwinVQContext *tctx = avctx->priv_data; if (!avctx->extradata || avctx->extradata_size < 12) { av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n"); return AVERROR_INVALIDDATA; } - avctx->channels = AV_RB32(avctx->extradata) + 1; + channels = AV_RB32(avctx->extradata) + 1; avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000; isampf = AV_RB32(avctx->extradata + 8); @@ -349,15 +349,15 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx) break; } - if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) { + if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) { av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n", - avctx->channels); + channels); return -1; } - avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO - : AV_CH_LAYOUT_STEREO; + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_default(&avctx->ch_layout, channels); - ibps = avctx->bit_rate / (1000 * avctx->channels); + ibps = avctx->bit_rate / (1000 * channels); if (ibps < 8 || ibps > 48) { av_log(avctx, AV_LOG_ERROR, "Bad bitrate per channel value %d\n", ibps); return AVERROR_INVALIDDATA; |