aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2012-12-07 14:56:22 +0000
committerPaul B Mahol <onemda@gmail.com>2012-12-07 15:01:02 +0000
commit1c779854b52972e48d87bf6fed0b9f6fbf7a9af3 (patch)
treeb72ce3e9546a16eb6995f4febe127c603a2ae5d7
parent7c425e4f2d677477e43cd5ce0d3a5348123b8c2f (diff)
downloadffmpeg-1c779854b52972e48d87bf6fed0b9f6fbf7a9af3.tar.gz
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>
-rw-r--r--libavcodec/takdec.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 211fc67728..85cf1093e1 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -148,9 +148,9 @@ static const struct CParam {
{ 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:
avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
break;
@@ -168,31 +168,18 @@ static int tak_set_bps(AVCodecContext *avctx, int bps)
return 0;
}
-static int get_shift(int sample_rate)
+static void set_sample_rate_params(AVCodecContext *avctx)
{
- int shift;
-
- if (sample_rate < 11025)
- shift = 3;
- else if (sample_rate < 22050)
- 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;
+ TAKDecContext *s = avctx->priv_data;
+ int shift = 3 - (avctx->sample_rate / 11025);
+ shift = FFMAX(0, shift);
+ s->uval = FFALIGN(avctx->sample_rate + 511 >> 9, 4) << shift;
+ s->subframe_scale = FFALIGN(avctx->sample_rate + 511 >> 9, 4) << 1;
}
static av_cold int tak_decode_init(AVCodecContext *avctx)
{
TAKDecContext *s = avctx->priv_data;
- int ret;
ff_tak_init_crc();
ff_dsputil_init(&s->dsp, avctx);
@@ -200,14 +187,11 @@ static av_cold int tak_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
avcodec_get_frame_defaults(&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));
- s->subframe_scale = get_scale(avctx->sample_rate, 1);
-
- if ((ret = tak_set_bps(avctx, avctx->bits_per_coded_sample)) < 0)
- return ret;
+ set_sample_rate_params(avctx);
- return 0;
+ return set_bps_params(avctx);
}
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) {
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;
}
if (s->ti.sample_rate != avctx->sample_rate) {
avctx->sample_rate = s->ti.sample_rate;
- s->uval = get_scale(avctx->sample_rate, get_shift(avctx->sample_rate));
- s->subframe_scale = get_scale(avctx->sample_rate, 1);
+ set_sample_rate_params(avctx);
}
if (s->ti.ch_layout)
avctx->channel_layout = s->ti.ch_layout;