---
libavcodec/atrac3.c | 35 +++++++++++++++++++++++------------
1 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index f809f9a..27919c9 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -107,7 +107,7 @@ typedef struct {
//@}
//@{
/** data buffers */
- float outSamples[2048];
+ float *outSamples[2];
uint8_t* decoded_bytes_buffer;
float tempBuf[1070];
//@}
@@ -720,7 +720,7 @@ static int decodeChannelSoundUnit (ATRAC3Context *q,
GetBitContext *gb, channel_
*/
static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf,
- float *out_samples)
+ float **out_samples)
{
int result, i;
float *p1, *p2, *p3, *p4;
@@ -732,7 +732,7 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t*
databuf,
/* decode Sound Unit 1 */
init_get_bits(&q->gb,databuf,q->bits_per_frame);
- result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, out_samples, 0,
JOINT_STEREO);
+ result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, out_samples[0],
0, JOINT_STEREO);
if (result != 0)
return (result);
@@ -773,14 +773,14 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t*
databuf,
}
/* Decode Sound Unit 2. */
- result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1],
&out_samples[1024], 1, JOINT_STEREO);
+ result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1],
out_samples[1], 1, JOINT_STEREO);
if (result != 0)
return (result);
/* Reconstruct the channel coefficients. */
- reverseMatrixing(out_samples, &out_samples[1024],
q->matrix_coeff_index_prev, q->matrix_coeff_index_now);
+ reverseMatrixing(out_samples[0], out_samples[1],
q->matrix_coeff_index_prev, q->matrix_coeff_index_now);
- channelWeighting(out_samples, &out_samples[1024], q->weighting_delay);
+ channelWeighting(out_samples[0], out_samples[1], q->weighting_delay);
} else {
/* normal stereo mode or mono */
@@ -790,22 +790,21 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t*
databuf,
/* Set the bitstream reader at the start of a channel sound unit.
*/
init_get_bits(&q->gb,
databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels);
- result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i],
&out_samples[i*1024], i, q->codingMode);
+ result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i],
out_samples[i], i, q->codingMode);
if (result != 0)
return (result);
}
}
/* Apply the iQMF synthesis filter. */
- p1 = out_samples;
for (i=0 ; i<q->channels ; i++) {
+ p1 = out_samples[i];
p2= p1+256;
p3= p2+256;
p4= p3+256;
atrac_iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf);
atrac_iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf);
atrac_iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf);
- p1 +=1024;
}
return 0;
@@ -843,7 +842,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx,
databuf = buf;
}
- result = decodeFrame(q, databuf, q->channels == 2 ? q->outSamples :
samples);
+ result = decodeFrame(q, databuf, q->channels == 2 ? q->outSamples :
&samples);
if (result != 0) {
av_log(NULL,AV_LOG_ERROR,"Frame decoding error!\n");
@@ -853,8 +852,8 @@ static int atrac3_decode_frame(AVCodecContext *avctx,
/* interleave */
if (q->channels == 2) {
for (i = 0; i < 1024; i++) {
- samples[i*2] = q->outSamples[i];
- samples[i*2+1] = q->outSamples[1024+i];
+ samples[i*2] = q->outSamples[0][i];
+ samples[i*2+1] = q->outSamples[1][i];
}
}
*data_size = 1024 * q->channels *
av_get_bytes_per_sample(avctx->sample_fmt);
@@ -1010,6 +1009,18 @@ static av_cold int atrac3_decode_init(AVCodecContext
*avctx)
return AVERROR(ENOMEM);
}
+ if (avctx->channels > 1) {
+ q->outSamples[0] = av_mallocz(1024 * sizeof(*q->outSamples[0]));
+ q->outSamples[1] = av_mallocz(1024 * sizeof(*q->outSamples[1]));
+ if (!q->outSamples[0] || !q->outSamples[1]) {
+ av_freep(&q->outSamples[0]);
+ av_freep(&q->outSamples[1]);
+ av_freep(&q->decoded_bytes_buffer);
+ av_freep(&q->pUnits);
+ return AVERROR(ENOMEM);
+ }
+ }
+
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
return 0;
}
--
1.7.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel