summaryrefslogtreecommitdiffstats
path: root/libavcodec/atrac1.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/atrac1.c')
-rw-r--r--libavcodec/atrac1.c69
1 files changed, 36 insertions, 33 deletions
diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index 52d43e2..a8c8c91 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Maxim Poliakovski
* Copyright (c) 2009 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,9 +33,8 @@
#include <stdio.h>
#include "libavutil/float_dsp.h"
-
#include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
#include "fft.h"
#include "internal.h"
#include "sinewin.h"
@@ -66,7 +65,7 @@ typedef struct AT1SUCtx {
DECLARE_ALIGNED(32, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer
DECLARE_ALIGNED(32, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter
DECLARE_ALIGNED(32, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter
- DECLARE_ALIGNED(32, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter
+ DECLARE_ALIGNED(32, float, last_qmf_delay)[256+39]; ///< delay line for the last stacked QMF filter
} AT1SUCtx;
/**
@@ -81,7 +80,7 @@ typedef struct AT1Ctx {
DECLARE_ALIGNED(32, float, high)[512];
float* bands[3];
FFTContext mdct_ctx[3];
- AVFloatDSPContext fdsp;
+ AVFloatDSPContext *fdsp;
} AT1Ctx;
/** size of the transform in samples in the long mode for each QMF band */
@@ -141,7 +140,7 @@ static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q)
at1_imdct(q, &q->spec[pos], &su->spectrum[0][ref_pos + start_pos], nbits, band_num);
/* overlap and window */
- q->fdsp.vector_fmul_window(&q->bands[band_num][start_pos], prev_buf,
+ q->fdsp->vector_fmul_window(&q->bands[band_num][start_pos], prev_buf,
&su->spectrum[0][ref_pos + start_pos], ff_sine_32, 16);
prev_buf = &su->spectrum[0][ref_pos+start_pos + 16];
@@ -165,31 +164,30 @@ static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q)
* Parse the block size mode byte
*/
-static int at1_parse_bsm(BitstreamContext *bc,
- int log2_block_cnt[AT1_QMF_BANDS])
+static int at1_parse_bsm(GetBitContext* gb, int log2_block_cnt[AT1_QMF_BANDS])
{
int log2_block_count_tmp, i;
for (i = 0; i < 2; i++) {
/* low and mid band */
- log2_block_count_tmp = bitstream_read(bc, 2);
+ log2_block_count_tmp = get_bits(gb, 2);
if (log2_block_count_tmp & 1)
return AVERROR_INVALIDDATA;
log2_block_cnt[i] = 2 - log2_block_count_tmp;
}
/* high band */
- log2_block_count_tmp = bitstream_read(bc, 2);
+ log2_block_count_tmp = get_bits(gb, 2);
if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3)
return AVERROR_INVALIDDATA;
log2_block_cnt[IDX_HIGH_BAND] = 3 - log2_block_count_tmp;
- bitstream_skip(bc, 2);
+ skip_bits(gb, 2);
return 0;
}
-static int at1_unpack_dequant(BitstreamContext *bc, AT1SUCtx *su,
+static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* su,
float spec[AT1_SU_SAMPLES])
{
int bits_used, band_num, bfu_num, i;
@@ -197,22 +195,22 @@ static int at1_unpack_dequant(BitstreamContext *bc, AT1SUCtx *su,
uint8_t idsfs[AT1_MAX_BFU]; ///< the scalefactor indexes for each BFU
/* parse the info byte (2nd byte) telling how much BFUs were coded */
- su->num_bfus = bfu_amount_tab1[bitstream_read(bc, 3)];
+ su->num_bfus = bfu_amount_tab1[get_bits(gb, 3)];
/* calc number of consumed bits:
num_BFUs * (idwl(4bits) + idsf(6bits)) + log2_block_count(8bits) + info_byte(8bits)
+ info_byte_copy(8bits) + log2_block_count_copy(8bits) */
bits_used = su->num_bfus * 10 + 32 +
- bfu_amount_tab2[bitstream_read(bc, 2)] +
- (bfu_amount_tab3[bitstream_read(bc, 3)] << 1);
+ bfu_amount_tab2[get_bits(gb, 2)] +
+ (bfu_amount_tab3[get_bits(gb, 3)] << 1);
/* get word length index (idwl) for each BFU */
for (i = 0; i < su->num_bfus; i++)
- idwls[i] = bitstream_read(bc, 4);
+ idwls[i] = get_bits(gb, 4);
/* get scalefactor index (idsf) for each BFU */
for (i = 0; i < su->num_bfus; i++)
- idsfs[i] = bitstream_read(bc, 6);
+ idsfs[i] = get_bits(gb, 6);
/* zero idwl/idsf for empty BFUs */
for (i = su->num_bfus; i < AT1_MAX_BFU; i++)
@@ -242,9 +240,9 @@ static int at1_unpack_dequant(BitstreamContext *bc, AT1SUCtx *su,
/* read in a quantized spec and convert it to
* signed int and then inverse quantization
*/
- spec[pos+i] = bitstream_read_signed(bc, word_len) * scale_factor * max_quant;
+ spec[pos+i] = get_sbits(gb, word_len) * scale_factor * max_quant;
}
- } else { /* word_len = 0 -> empty BFU, zero all specs in the emty BFU */
+ } else { /* word_len = 0 -> empty BFU, zero all specs in the empty BFU */
memset(&spec[pos], 0, num_specs * sizeof(float));
}
}
@@ -262,9 +260,9 @@ static void at1_subband_synthesis(AT1Ctx *q, AT1SUCtx* su, float *pOut)
/* combine low and middle bands */
ff_atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp);
- /* delay the signal of the high band by 23 samples */
- memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float) * 23);
- memcpy(&su->last_qmf_delay[23], q->bands[2], sizeof(float) * 256);
+ /* delay the signal of the high band by 39 samples */
+ memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float) * 39);
+ memcpy(&su->last_qmf_delay[39], q->bands[2], sizeof(float) * 256);
/* combine (low + middle) and high bands */
ff_atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp);
@@ -279,7 +277,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
int buf_size = avpkt->size;
AT1Ctx *q = avctx->priv_data;
int ch, ret;
- BitstreamContext bc;
+ GetBitContext gb;
if (buf_size < 212 * avctx->channels) {
@@ -289,22 +287,20 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
/* get output buffer */
frame->nb_samples = AT1_SU_SAMPLES;
- if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- }
for (ch = 0; ch < avctx->channels; ch++) {
AT1SUCtx* su = &q->SUs[ch];
- bitstream_init8(&bc, &buf[212 * ch], 212);
+ init_get_bits(&gb, &buf[212 * ch], 212 * 8);
/* parse block_size_mode, 1st byte */
- ret = at1_parse_bsm(&bc, su->log2_block_count);
+ ret = at1_parse_bsm(&gb, su->log2_block_count);
if (ret < 0)
return ret;
- ret = at1_unpack_dequant(&bc, su, q->spec);
+ ret = at1_unpack_dequant(&gb, su, q->spec);
if (ret < 0)
return ret;
@@ -328,6 +324,8 @@ static av_cold int atrac1_decode_end(AVCodecContext * avctx)
ff_mdct_end(&q->mdct_ctx[1]);
ff_mdct_end(&q->mdct_ctx[2]);
+ av_freep(&q->fdsp);
+
return 0;
}
@@ -345,6 +343,11 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+ if (avctx->block_align <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported block align.");
+ return AVERROR_PATCHWELCOME;
+ }
+
/* Init the mdct transforms */
if ((ret = ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15))) ||
(ret = ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15))) ||
@@ -358,7 +361,7 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx)
ff_atrac_generate_tables();
- avpriv_float_dsp_init(&q->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
+ q->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
q->bands[0] = q->low;
q->bands[1] = q->mid;
OpenPOWER on IntegriCloud