* implementors. The original code is available from http://code.google.com/p/nelly2pcm/
*/
-#include "nellymoser.h"
+#include "libavutil/channel_layout.h"
#include "libavutil/lfg.h"
#include "libavutil/random_seed.h"
-#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "dsputil.h"
#include "fft.h"
#include "fmtconvert.h"
+#include "internal.h"
+#include "nellymoser.h"
#include "sinewin.h"
#define BITSTREAM_READER_LE
typedef struct NellyMoserDecodeContext {
AVCodecContext* avctx;
AVFrame frame;
- float *float_buf;
AVLFG random_state;
GetBitContext gb;
float scale_bias;
DSPContext dsp;
FFTContext imdct_ctx;
- FmtConvertContext fmt_conv;
DECLARE_ALIGNED(32, float, imdct_buf)[2][NELLY_BUF_LEN];
float *imdct_out;
float *imdct_prev;
ff_dsputil_init(&s->dsp, avctx);
- if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) {
- s->scale_bias = 1.0/(32768*8);
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
- } else {
- s->scale_bias = 1.0/(1*8);
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- ff_fmt_convert_init(&s->fmt_conv, avctx);
- s->float_buf = av_mallocz(NELLY_SAMPLES * sizeof(*s->float_buf));
- if (!s->float_buf) {
- av_log(avctx, AV_LOG_ERROR, "error allocating float buffer\n");
- return AVERROR(ENOMEM);
- }
- }
+ s->scale_bias = 1.0/(32768*8);
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
/* Generate overlap window */
if (!ff_sine_128[127])
ff_init_ff_sine_windows(7);
+ avctx->channels = 1;
avctx->channel_layout = AV_CH_LAYOUT_MONO;
avcodec_get_frame_defaults(&s->frame);
int buf_size = avpkt->size;
NellyMoserDecodeContext *s = avctx->priv_data;
int blocks, i, ret;
- int16_t *samples_s16;
float *samples_flt;
blocks = buf_size / NELLY_BLOCK_LEN;
/* get output buffer */
s->frame.nb_samples = NELLY_SAMPLES * blocks;
- if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
+ if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
- samples_s16 = (int16_t *)s->frame.data[0];
samples_flt = (float *)s->frame.data[0];
for (i=0 ; i<blocks ; i++) {
- if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {
- nelly_decode_block(s, buf, samples_flt);
- samples_flt += NELLY_SAMPLES;
- } else {
- nelly_decode_block(s, buf, s->float_buf);
- s->fmt_conv.float_to_int16(samples_s16, s->float_buf, NELLY_SAMPLES);
- samples_s16 += NELLY_SAMPLES;
- }
+ nelly_decode_block(s, buf, samples_flt);
+ samples_flt += NELLY_SAMPLES;
buf += NELLY_BLOCK_LEN;
}
static av_cold int decode_end(AVCodecContext * avctx) {
NellyMoserDecodeContext *s = avctx->priv_data;
- av_freep(&s->float_buf);
ff_mdct_end(&s->imdct_ctx);
return 0;
AVCodec ff_nellymoser_decoder = {
.name = "nellymoser",
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_NELLYMOSER,
+ .id = AV_CODEC_ID_NELLYMOSER,
.priv_data_size = sizeof(NellyMoserDecodeContext),
.init = decode_init,
.close = decode_end,
.decode = decode_tag,
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE,
- .long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"),
+ .long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"),
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
- AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE },
};