2 * Packed Animation File audio decoder
3 * Copyright (c) 2012 Paul B Mahol
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/intreadwrite.h"
28 #define PAF_SOUND_SAMPLES 2205
29 #define PAF_SOUND_FRAME_SIZE ((256 + PAF_SOUND_SAMPLES) * 2)
31 static av_cold int paf_audio_init(AVCodecContext *avctx)
33 if (avctx->channels != 2) {
34 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
35 return AVERROR_INVALIDDATA;
38 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
39 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
44 static int paf_audio_decode(AVCodecContext *avctx, void *data,
45 int *got_frame, AVPacket *pkt)
47 AVFrame *frame = data;
48 int16_t *output_samples;
49 const uint8_t *src = pkt->data;
50 int frames, ret, i, j;
53 frames = pkt->size / PAF_SOUND_FRAME_SIZE;
55 return AVERROR_INVALIDDATA;
57 frame->nb_samples = PAF_SOUND_SAMPLES * frames;
58 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
61 output_samples = (int16_t *)frame->data[0];
62 // codebook of 256 16-bit samples and 8-bit indices to it
63 for (j = 0; j < frames; j++) {
64 for (i = 0; i < 256; i++)
65 cb[i] = sign_extend(AV_RL16(src + i * 2), 16);
68 for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++)
69 *output_samples++ = cb[*src++];
76 AVCodec ff_paf_audio_decoder = {
78 .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
79 .type = AVMEDIA_TYPE_AUDIO,
80 .id = AV_CODEC_ID_PAF_AUDIO,
81 .init = paf_audio_init,
82 .decode = paf_audio_decode,
83 .capabilities = CODEC_CAP_DR1,