56
60
/** Uncompress one block (20 bytes -> 160*2 bytes). */
57
static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
58
int *data_size, AVPacket *avpkt)
61
static int ra144_decode_frame(AVCodecContext * avctx, void *data,
62
int *got_frame_ptr, AVPacket *avpkt)
60
64
const uint8_t *buf = avpkt->data;
61
65
int buf_size = avpkt->size;
62
static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
63
unsigned int refl_rms[4]; // RMS of the reflection coefficients
64
uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block
65
unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame
66
static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
67
unsigned int refl_rms[NBLOCKS]; // RMS of the reflection coefficients
68
uint16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block
69
unsigned int lpc_refl[LPC_ORDER]; // LPC reflection coefficients of the frame
67
int16_t *data = vdata;
68
73
unsigned int energy;
70
75
RA144Context *ractx = avctx->priv_data;
73
if (*data_size < 2*160)
78
/* get output buffer */
79
ractx->frame.nb_samples = NBLOCKS * BLOCKSIZE;
80
if ((ret = avctx->get_buffer(avctx, &ractx->frame)) < 0) {
81
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
84
samples = (int16_t *)ractx->frame.data[0];
86
if(buf_size < FRAMESIZE) {
77
87
av_log(avctx, AV_LOG_ERROR,
78
88
"Frame too small (%d bytes). Truncated file?\n", buf_size);
82
init_get_bits(&gb, buf, 20 * 8);
92
init_get_bits(&gb, buf, FRAMESIZE * 8);
94
for (i = 0; i < LPC_ORDER; i++)
85
95
lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])];
87
97
ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);
99
109
ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]);
101
for (i=0; i < 4; i++) {
111
for (i=0; i < NBLOCKS; i++) {
102
112
do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb);
104
114
for (j=0; j < BLOCKSIZE; j++)
105
*data++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2);
115
*samples++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2);
108
118
ractx->old_energy = energy;
111
121
FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
124
*(AVFrame *)data = ractx->frame;
117
AVCodec ff_ra_144_decoder =
122
sizeof(RA144Context),
127
.long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
129
AVCodec ff_ra_144_decoder = {
131
.type = AVMEDIA_TYPE_AUDIO,
132
.id = CODEC_ID_RA_144,
133
.priv_data_size = sizeof(RA144Context),
134
.init = ra144_decode_init,
135
.decode = ra144_decode_frame,
136
.capabilities = CODEC_CAP_DR1,
137
.long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),