#include "libavutil/internal.h"
#include "libavutil/samplefmt.h"
#include "tak.h"
+#include "audiodsp.h"
#include "avcodec.h"
-#include "dsputil.h"
#include "internal.h"
#include "unary.h"
typedef struct TAKDecContext {
AVCodecContext *avctx; // parent AVCodecContext
- DSPContext dsp;
+ AudioDSPContext adsp;
TAKStreamInfo ti;
GetBitContext gb; // bitstream reader initialized to start at the current frame
{
TAKDecContext *s = avctx->priv_data;
- ff_dsputil_init(&s->dsp, avctx);
+ ff_audiodsp_init(&s->adsp);
s->avctx = avctx;
for (i = 0; i < subframe_size - filter_order; i++) {
int v = 1 << (filter_quant - 1);
- v += s->dsp.scalarproduct_int16(&s->residues[i], filter,
- FFALIGN(filter_order, 16));
+ v += s->adsp.scalarproduct_int16(&s->residues[i], filter,
+ FFALIGN(filter_order, 16));
- v = (av_clip(v >> filter_quant, -8192, 8191) << dshift) - *decoded;
+ v = (av_clip_intp2(v >> filter_quant, 13) << dshift) - *decoded;
*decoded++ = v;
s->residues[filter_order + i] = v >> dshift;
}
for (i = 0; i < length2; i++) {
int v = 1 << 9;
- v += s->dsp.scalarproduct_int16(&s->residues[i], filter,
- FFALIGN(filter_order, 16));
+ v += s->adsp.scalarproduct_int16(&s->residues[i], filter,
+ FFALIGN(filter_order, 16));
- p1[i] = (av_clip(v >> 10, -8192, 8191) << dshift) - p1[i];
+ p1[i] = (av_clip_intp2(v >> 10, 13) << dshift) - p1[i];
}
emms_c();
if (avctx->err_recognition & AV_EF_CRCCHECK) {
if (ff_tak_check_crc(pkt->data, hsize)) {
av_log(avctx, AV_LOG_ERROR, "CRC error\n");
- return AVERROR_INVALIDDATA;
+ if (avctx->err_recognition & AV_EF_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
}
int buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
s->nb_samples,
AV_SAMPLE_FMT_S32P, 0);
+ if (buf_size < 0)
+ return buf_size;
av_fast_malloc(&s->decode_buffer, &s->decode_buffer_size, buf_size);
if (!s->decode_buffer)
return AVERROR(ENOMEM);
if (ff_tak_check_crc(pkt->data + hsize,
get_bits_count(gb) / 8 - hsize)) {
av_log(avctx, AV_LOG_ERROR, "CRC error\n");
- return AVERROR_INVALIDDATA;
+ if (avctx->err_recognition & AV_EF_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
}
AVCodec ff_tak_decoder = {
.name = "tak",
+ .long_name = NULL_IF_CONFIG_SMALL("TAK (Tom's lossless Audio Kompressor)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_TAK,
.priv_data_size = sizeof(TAKDecContext),
.init_static_data = tak_init_static_data,
.close = tak_decode_close,
.decode = tak_decode_frame,
- .capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("TAK (Tom's lossless Audio Kompressor)"),
+ .capabilities = AV_CODEC_CAP_DR1,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
AV_SAMPLE_FMT_S16P,
AV_SAMPLE_FMT_S32P,