X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fatrac3.c;h=6015ef6ab6edf7f2fcde200a17da16bb09f65cad;hb=e4e3230ea54ab7c66588d713b13a81fd59e10dcc;hp=ab54c5708a9fe81d1adc5963c14af7af8899de62;hpb=6611c0b4c9bd6e8699a322c35529342568f3b503;p=ffmpeg diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index ab54c5708a9..6015ef6ab6e 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -1,7 +1,7 @@ /* * Atrac 3 compatible decoder - * Copyright (c) 2006-2007 Maxim Poliakovski - * Copyright (c) 2006-2007 Benjamin Larsson + * Copyright (c) 2006-2008 Maxim Poliakovski + * Copyright (c) 2006-2008 Benjamin Larsson * * This file is part of FFmpeg. * @@ -23,12 +23,13 @@ /** * @file atrac3.c * Atrac 3 compatible decoder. - * This decoder handles RealNetworks, RealAudio atrc data. - * Atrac 3 is identified by the codec name atrc in RealMedia files. + * This decoder handles Sony's ATRAC3 data. + * + * Container formats used to store atrac 3 data: + * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3). * * To use this decoder, a calling application must supply the extradata - * bytes provided from the RealMedia container: 10 bytes or 14 bytes - * from the WAV container. + * bytes provided in the containers above. */ #include @@ -225,14 +226,14 @@ static void IMLT(float *pInput, float *pOutput, int odd_band, float* mdct_tmp) * @param out pointer to 8 bit array of outdata */ -static int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){ +static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ int i, off; uint32_t c; - uint32_t* buf; + const uint32_t* buf; uint32_t* obuf = (uint32_t*) out; off = (int)((long)inbuffer & 3); - buf = (uint32_t*) (inbuffer - off); + buf = (const uint32_t*) (inbuffer - off); c = be2me_32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8)))); bytes += 3 + off; for (i = 0; i < bytes/4; i++) @@ -363,7 +364,7 @@ static int decodeSpectrum (GetBitContext *gb, float *pOut) float SF; numSubbands = get_bits(gb, 5); // number of coded subbands - codingMode = get_bits(gb, 1); // coding Mode: 0 - VLC/ 1-CLC + codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC /* Get the VLC selector table for the subbands, 0 means not coded. */ for (cnt = 0; cnt <= numSubbands; cnt++) @@ -468,7 +469,7 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent pComponent[component_count].numCoefs = coded_values; /* inverse quant */ - pCoef = pComponent[k].coef; + pCoef = pComponent[component_count].coef; for (cnt = 0; cnt < coded_values; cnt++) pCoef[cnt] = mantissa[cnt] * scalefactor; @@ -577,24 +578,28 @@ static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gai /** * Combine the tonal band spectrum and regular band spectrum + * Return position of the last tonal coefficient * * @param pSpectrum output spectrum buffer * @param numComponents amount of tonal components * @param pComponent tonal components for this band */ -static void addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) +static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) { - int cnt, i; + int cnt, i, lastPos = -1; float *pIn, *pOut; for (cnt = 0; cnt < numComponents; cnt++){ + lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos); pIn = pComponent[cnt].coef; pOut = &(pSpectrum[pComponent[cnt].pos]); for (i=0 ; ispectrum); /* Merge the decoded spectrum and tonal components. */ - addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); + lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); - /* Convert number of subbands into number of MLT/QMF bands */ + /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */ numBands = (subbandTab[numSubbands] - 1) >> 8; + if (lastTonal >= 0) + numBands = FFMAX((lastTonal + 256) >> 8, numBands); /* Reconstruct time domain samples. */ @@ -811,7 +818,7 @@ static int decodeFrame(ATRAC3Context *q, uint8_t* databuf) /* Fill the Weighting coeffs delay buffer */ memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int)); - q->weighting_delay[4] = get_bits(&q->gb,1); + q->weighting_delay[4] = get_bits1(&q->gb); q->weighting_delay[5] = get_bits(&q->gb,3); for (i = 0; i < 4; i++) { @@ -868,7 +875,7 @@ static int decodeFrame(ATRAC3Context *q, uint8_t* databuf) static int atrac3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) { + const uint8_t *buf, int buf_size) { ATRAC3Context *q = avctx->priv_data; int result = 0, i; uint8_t* databuf; @@ -895,13 +902,13 @@ static int atrac3_decode_frame(AVCodecContext *avctx, if (q->channels == 1) { /* mono */ for (i = 0; i<1024; i++) - samples[i] = av_clip(round(q->outSamples[i]), -32768, 32767); + samples[i] = av_clip_int16(round(q->outSamples[i])); *data_size = 1024 * sizeof(int16_t); } else { /* stereo */ for (i = 0; i < 1024; i++) { - samples[i*2] = av_clip(round(q->outSamples[i]), -32768, 32767); - samples[i*2+1] = av_clip(round(q->outSamples[1024+i]), -32768, 32767); + samples[i*2] = av_clip_int16(round(q->outSamples[i])); + samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i])); } *data_size = 2048 * sizeof(int16_t); } @@ -919,7 +926,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx, static int atrac3_decode_init(AVCodecContext *avctx) { int i; - uint8_t *edata_ptr = avctx->extradata; + const uint8_t *edata_ptr = avctx->extradata; ATRAC3Context *q = avctx->priv_data; /* Take data from the AVCodecContext (RM container). */ @@ -1047,6 +1054,10 @@ static int atrac3_decode_init(AVCodecContext *avctx) dsputil_init(&dsp, avctx); q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); + if (!q->pUnits) { + av_free(q->decoded_bytes_buffer); + return AVERROR(ENOMEM); + } return 0; } @@ -1054,11 +1065,12 @@ static int atrac3_decode_init(AVCodecContext *avctx) AVCodec atrac3_decoder = { - .name = "atrac 3", + .name = "atrac3", .type = CODEC_TYPE_AUDIO, .id = CODEC_ID_ATRAC3, .priv_data_size = sizeof(ATRAC3Context), .init = atrac3_decode_init, .close = atrac3_decode_close, .decode = atrac3_decode_frame, + .long_name = "Atrac 3 (Adaptive TRansform Acoustic Coding 3)", };