~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/atrac1.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "get_bits.h"
37
37
#include "dsputil.h"
38
38
#include "fft.h"
39
 
#include "fmtconvert.h"
 
39
#include "internal.h"
40
40
#include "sinewin.h"
41
41
 
42
42
#include "atrac.h"
80
80
    DECLARE_ALIGNED(32, float,  mid)[256];
81
81
    DECLARE_ALIGNED(32, float, high)[512];
82
82
    float*              bands[3];
83
 
    float              *out_samples[AT1_MAX_CHANNELS];
84
83
    FFTContext          mdct_ctx[3];
85
 
    int                 channels;
86
84
    DSPContext          dsp;
87
 
    FmtConvertContext   fmt_conv;
88
85
} AT1Ctx;
89
86
 
90
87
/** size of the transform in samples in the long mode for each QMF band */
262
259
    float iqmf_temp[512 + 46];
263
260
 
264
261
    /* combine low and middle bands */
265
 
    atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp);
 
262
    ff_atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp);
266
263
 
267
264
    /* delay the signal of the high band by 23 samples */
268
265
    memcpy( su->last_qmf_delay,    &su->last_qmf_delay[256], sizeof(float) *  23);
269
266
    memcpy(&su->last_qmf_delay[23], q->bands[2],             sizeof(float) * 256);
270
267
 
271
268
    /* combine (low + middle) and high bands */
272
 
    atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp);
 
269
    ff_atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp);
273
270
}
274
271
 
275
272
 
281
278
    AT1Ctx *q          = avctx->priv_data;
282
279
    int ch, ret;
283
280
    GetBitContext gb;
284
 
    float *samples;
285
 
 
286
 
 
287
 
    if (buf_size < 212 * q->channels) {
 
281
 
 
282
 
 
283
    if (buf_size < 212 * avctx->channels) {
288
284
        av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n");
289
285
        return AVERROR_INVALIDDATA;
290
286
    }
291
287
 
292
288
    /* get output buffer */
293
289
    q->frame.nb_samples = AT1_SU_SAMPLES;
294
 
    if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) {
 
290
    if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) {
295
291
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
296
292
        return ret;
297
293
    }
298
 
    samples = (float *)q->frame.data[0];
299
294
 
300
 
    for (ch = 0; ch < q->channels; ch++) {
 
295
    for (ch = 0; ch < avctx->channels; ch++) {
301
296
        AT1SUCtx* su = &q->SUs[ch];
302
297
 
303
298
        init_get_bits(&gb, &buf[212 * ch], 212 * 8);
314
309
        ret = at1_imdct_block(su, q);
315
310
        if (ret < 0)
316
311
            return ret;
317
 
        at1_subband_synthesis(q, su, q->channels == 1 ? samples : q->out_samples[ch]);
318
 
    }
319
 
 
320
 
    /* interleave */
321
 
    if (q->channels == 2) {
322
 
        q->fmt_conv.float_interleave(samples, (const float **)q->out_samples,
323
 
                                     AT1_SU_SAMPLES, 2);
 
312
        at1_subband_synthesis(q, su, (float *)q->frame.extended_data[ch]);
324
313
    }
325
314
 
326
315
    *got_frame_ptr   = 1;
334
323
{
335
324
    AT1Ctx *q = avctx->priv_data;
336
325
 
337
 
    av_freep(&q->out_samples[0]);
338
 
 
339
326
    ff_mdct_end(&q->mdct_ctx[0]);
340
327
    ff_mdct_end(&q->mdct_ctx[1]);
341
328
    ff_mdct_end(&q->mdct_ctx[2]);
349
336
    AT1Ctx *q = avctx->priv_data;
350
337
    int ret;
351
338
 
352
 
    avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
339
    avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
353
340
 
354
341
    if (avctx->channels < 1 || avctx->channels > AT1_MAX_CHANNELS) {
355
342
        av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n",
356
343
               avctx->channels);
357
344
        return AVERROR(EINVAL);
358
345
    }
359
 
    q->channels = avctx->channels;
360
 
 
361
 
    if (avctx->channels == 2) {
362
 
        q->out_samples[0] = av_malloc(2 * AT1_SU_SAMPLES * sizeof(*q->out_samples[0]));
363
 
        q->out_samples[1] = q->out_samples[0] + AT1_SU_SAMPLES;
364
 
        if (!q->out_samples[0]) {
365
 
            av_freep(&q->out_samples[0]);
366
 
            return AVERROR(ENOMEM);
367
 
        }
368
 
    }
369
346
 
370
347
    /* Init the mdct transforms */
371
348
    if ((ret = ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15))) ||
378
355
 
379
356
    ff_init_ff_sine_windows(5);
380
357
 
381
 
    atrac_generate_tables();
 
358
    ff_atrac_generate_tables();
382
359
 
383
 
    dsputil_init(&q->dsp, avctx);
384
 
    ff_fmt_convert_init(&q->fmt_conv, avctx);
 
360
    ff_dsputil_init(&q->dsp, avctx);
385
361
 
386
362
    q->bands[0] = q->low;
387
363
    q->bands[1] = q->mid;
401
377
 
402
378
 
403
379
AVCodec ff_atrac1_decoder = {
404
 
    .name = "atrac1",
405
 
    .type = AVMEDIA_TYPE_AUDIO,
406
 
    .id = CODEC_ID_ATRAC1,
 
380
    .name           = "atrac1",
 
381
    .type           = AVMEDIA_TYPE_AUDIO,
 
382
    .id             = AV_CODEC_ID_ATRAC1,
407
383
    .priv_data_size = sizeof(AT1Ctx),
408
 
    .init = atrac1_decode_init,
409
 
    .close = atrac1_decode_end,
410
 
    .decode = atrac1_decode_frame,
411
 
    .capabilities = CODEC_CAP_DR1,
412
 
    .long_name = NULL_IF_CONFIG_SMALL("Atrac 1 (Adaptive TRansform Acoustic Coding)"),
 
384
    .init           = atrac1_decode_init,
 
385
    .close          = atrac1_decode_end,
 
386
    .decode         = atrac1_decode_frame,
 
387
    .capabilities   = CODEC_CAP_DR1,
 
388
    .long_name      = NULL_IF_CONFIG_SMALL("Atrac 1 (Adaptive TRansform Acoustic Coding)"),
 
389
    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
 
390
                                                      AV_SAMPLE_FMT_NONE },
413
391
};