lavc/takdec: simplify code

Merge get_scale/get_shift into set_sample_rate_params().
Rename tak_set_bps to set_bps_params and remove 2nd argument.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2012-12-07 14:56:22 +00:00
parent 7c425e4f2d
commit 1c779854b5

View File

@ -148,9 +148,9 @@ static const struct CParam {
{ 0x1A, 0x1800000, 0x1800000, 0x6800000, 0xC000000 }, { 0x1A, 0x1800000, 0x1800000, 0x6800000, 0xC000000 },
}; };
static int tak_set_bps(AVCodecContext *avctx, int bps) static int set_bps_params(AVCodecContext *avctx)
{ {
switch (bps) { switch (avctx->bits_per_raw_sample) {
case 8: case 8:
avctx->sample_fmt = AV_SAMPLE_FMT_U8P; avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
break; break;
@ -168,31 +168,18 @@ static int tak_set_bps(AVCodecContext *avctx, int bps)
return 0; return 0;
} }
static int get_shift(int sample_rate) static void set_sample_rate_params(AVCodecContext *avctx)
{ {
int shift; TAKDecContext *s = avctx->priv_data;
int shift = 3 - (avctx->sample_rate / 11025);
if (sample_rate < 11025) shift = FFMAX(0, shift);
shift = 3; s->uval = FFALIGN(avctx->sample_rate + 511 >> 9, 4) << shift;
else if (sample_rate < 22050) s->subframe_scale = FFALIGN(avctx->sample_rate + 511 >> 9, 4) << 1;
shift = 2;
else if (sample_rate < 44100)
shift = 1;
else
shift = 0;
return shift;
}
static int get_scale(int sample_rate, int shift)
{
return FFALIGN(sample_rate + 511 >> 9, 4) << shift;
} }
static av_cold int tak_decode_init(AVCodecContext *avctx) static av_cold int tak_decode_init(AVCodecContext *avctx)
{ {
TAKDecContext *s = avctx->priv_data; TAKDecContext *s = avctx->priv_data;
int ret;
ff_tak_init_crc(); ff_tak_init_crc();
ff_dsputil_init(&s->dsp, avctx); ff_dsputil_init(&s->dsp, avctx);
@ -200,14 +187,11 @@ static av_cold int tak_decode_init(AVCodecContext *avctx)
s->avctx = avctx; s->avctx = avctx;
avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame; avctx->coded_frame = &s->frame;
avctx->bits_per_raw_sample = avctx->bits_per_coded_sample;
s->uval = get_scale(avctx->sample_rate, get_shift(avctx->sample_rate)); set_sample_rate_params(avctx);
s->subframe_scale = get_scale(avctx->sample_rate, 1);
if ((ret = tak_set_bps(avctx, avctx->bits_per_coded_sample)) < 0) return set_bps_params(avctx);
return ret;
return 0;
} }
static void decode_lpc(int32_t *coeffs, int mode, int length) static void decode_lpc(int32_t *coeffs, int mode, int length)
@ -774,13 +758,12 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
if (s->ti.bps != avctx->bits_per_raw_sample) { if (s->ti.bps != avctx->bits_per_raw_sample) {
avctx->bits_per_raw_sample = s->ti.bps; avctx->bits_per_raw_sample = s->ti.bps;
if ((ret = tak_set_bps(avctx, avctx->bits_per_raw_sample)) < 0) if ((ret = set_bps_params(avctx)) < 0)
return ret; return ret;
} }
if (s->ti.sample_rate != avctx->sample_rate) { if (s->ti.sample_rate != avctx->sample_rate) {
avctx->sample_rate = s->ti.sample_rate; avctx->sample_rate = s->ti.sample_rate;
s->uval = get_scale(avctx->sample_rate, get_shift(avctx->sample_rate)); set_sample_rate_params(avctx);
s->subframe_scale = get_scale(avctx->sample_rate, 1);
} }
if (s->ti.ch_layout) if (s->ti.ch_layout)
avctx->channel_layout = s->ti.ch_layout; avctx->channel_layout = s->ti.ch_layout;