* Real Audio 1.0 (14.4K) encoder
* Copyright (c) 2010 Francesco Lavra <francescolavra@interfree.it>
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "ra144.h"
+static av_cold int ra144_encode_close(AVCodecContext *avctx)
+{
+ RA144Context *ractx = avctx->priv_data;
+ ff_lpc_end(&ractx->lpc_ctx);
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+
static av_cold int ra144_encode_init(AVCodecContext * avctx)
{
RA144Context *ractx;
int ret;
- if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) {
- av_log(avctx, AV_LOG_ERROR, "invalid sample format\n");
- return -1;
- }
if (avctx->channels != 1) {
av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
avctx->channels);
ractx->lpc_coef[1] = ractx->lpc_tables[1];
ractx->avctx = avctx;
ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER,
- AV_LPC_TYPE_LEVINSON);
- return ret;
-}
-
+ FF_LPC_TYPE_LEVINSON);
+ if (ret < 0)
+ goto error;
+
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
-static av_cold int ra144_encode_close(AVCodecContext *avctx)
-{
- RA144Context *ractx = avctx->priv_data;
- ff_lpc_end(&ractx->lpc_ctx);
return 0;
+error:
+ ra144_encode_close(avctx);
+ return ret;
}
ff_celp_lp_synthesis_filterf(work, coefs, exc, BLOCKSIZE, LPC_ORDER);
for (i = 0; i < BLOCKSIZE; i++)
data[i] -= best_gain * work[i];
- return (best_vect - BLOCKSIZE / 2 + 1);
+ return best_vect - BLOCKSIZE / 2 + 1;
}
int16_t block_coefs[NBLOCKS][LPC_ORDER];
int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */
unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */
+ const int16_t *samples = data;
int energy = 0;
int i, idx;
32)];
ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,
- LPC_ORDER, 16, lpc_coefs, shift, AV_LPC_TYPE_LEVINSON,
+ LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON,
0, ORDER_METHOD_EST, 12, 0);
for (i = 0; i < LPC_ORDER; i++)
block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
* The filter is unstable: use the coefficients of the previous frame.
*/
ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);
- ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx);
+ if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {
+ /* the filter is still unstable. set reflection coeffs to zero. */
+ memset(lpc_refl, 0, sizeof(lpc_refl));
+ }
}
init_put_bits(&pb, frame, buf_size);
for (i = 0; i < LPC_ORDER; i++) {
ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];
FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
for (i = 0; i < NBLOCKS * BLOCKSIZE; i++)
- ractx->curr_block[i] = *((int16_t *)data + i) >> 2;
+ ractx->curr_block[i] = samples[i] >> 2;
return FRAMESIZE;
}
-AVCodec ff_ra_144_encoder =
-{
- "real_144",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_RA_144,
- sizeof(RA144Context),
- ra144_encode_init,
- ra144_encode_frame,
- ra144_encode_close,
- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K) encoder"),
+AVCodec ff_ra_144_encoder = {
+ .name = "real_144",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_RA_144,
+ .priv_data_size = sizeof(RA144Context),
+ .init = ra144_encode_init,
+ .encode = ra144_encode_frame,
+ .close = ra144_encode_close,
+ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
+ AV_SAMPLE_FMT_NONE },
+ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
};