38 #define FILTER_RAW 642
49 #define RALF_MAX_PKT_SIZE 8192
75 #define MAX_ELEMS 644 // no RALF table uses more than that
81 int counts[17], prefixes[18];
86 for (i = 0; i <= 16; i++)
88 for (i = 0; i < elems; i++) {
89 cur_len = (nb ? *data & 0xF : *data >> 4) + 1;
91 max_bits =
FFMAX(max_bits, cur_len);
97 for (i = 1; i <= 16; i++)
98 prefixes[i + 1] = (prefixes[i] + counts[i]) << 1;
100 for (i = 0; i < elems; i++)
101 codes[i] = prefixes[lens[i]]++;
104 lens, 1, 1, codes, 2, 2,
NULL, 0, 0, 0);
112 for (i = 0; i < 3; i++) {
116 for (j = 0; j < 10; j++)
117 for (k = 0; k < 11; k++)
119 for (j = 0; j < 15; j++)
121 for (j = 0; j < 125; j++)
167 for (i = 0; i < 3; i++) {
185 for (j = 0; j < 10; j++) {
186 for (k = 0; k < 11; k++) {
196 for (j = 0; j < 15; j++) {
204 for (j = 0; j < 125; j++) {
221 }
else if (val == range * 2) {
232 int length,
int mode,
int bits)
245 for (i = 0; i < length; i++)
255 memset(dst, 0,
sizeof(*dst) * length);
260 int cmode = 0, coeff = 0;
266 t =
get_vlc2(gb, vlc[cmode].table, vlc[cmode].bits, 2);
269 coeff -= 12 << add_bits;
273 cmode = coeff >> add_bits;
278 }
else if (cmode > 0) {
287 if (code_params >= 15) {
288 add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);
289 if (add_bits > 9 && (code_params % 5) != 2)
293 code_vlc = set->
long_codes + code_params - 15;
301 for (i = 0; i < length; i += 2) {
307 dst[i] =
extend_code(gb, code1, range, 0) << add_bits;
308 dst[i + 1] =
extend_code(gb, code2, range, 0) << add_bits;
311 dst[i + 1] |=
get_bits(gb, add_bits);
323 int max_clip = (1 <<
bits) - 1, min_clip = -max_clip - 1;
325 for (i = 1; i < length; i++) {
329 for (j = 0; j < flen; j++)
330 acc += ctx->
filter[j] * audio[i - j - 1];
333 acc =
FFMAX(acc, min_clip);
336 acc =
FFMIN(acc, max_clip);
343 int16_t *dst0, int16_t *dst1)
347 int dmode, mode[2],
bits[2];
353 if (len <= 7) len ^= 1;
358 "Decoder's stomach is crying, it ate too many samples\n");
367 mode[0] = (dmode == 4) ? 1 : 0;
368 mode[1] = (dmode >= 2) ? 2 : 0;
370 bits[1] = (mode[1] == 2) ? 17 : 16;
372 for (ch = 0; ch < avctx->
channels; ch++) {
373 if ((ret =
decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
386 for (i = 0; i <
len; i++)
387 dst0[i] = ch0[i] + ctx->
bias[0];
390 for (i = 0; i <
len; i++) {
391 dst0[i] = ch0[i] + ctx->
bias[0];
392 dst1[i] = ch1[i] + ctx->
bias[1];
396 for (i = 0; i <
len; i++) {
397 ch0[i] += ctx->
bias[0];
399 dst1[i] = ch0[i] - (ch1[i] + ctx->
bias[1]);
403 for (i = 0; i <
len; i++) {
404 t = ch0[i] + ctx->
bias[0];
405 t2 = ch1[i] + ctx->
bias[1];
411 for (i = 0; i <
len; i++) {
412 t = ch1[i] + ctx->
bias[1];
413 t2 = ((ch0[i] + ctx->
bias[0]) << 1) | (t & 1);
414 dst0[i] = (t2 +
t) / 2;
415 dst1[i] = (t2 -
t) / 2;
433 int table_size, table_bytes, i;
434 const uint8_t *src, *block_pointer;
445 if (memcmp(ctx->
pkt, avpkt->
data, 2 + table_bytes)) {
453 avpkt->
size - 2 - table_bytes);
463 src_size = avpkt->
size;
471 samples0 = (int16_t *)ctx->
frame.
data[0];
472 samples1 = (int16_t *)ctx->
frame.
data[1];
479 table_bytes = (table_size + 7) >> 3;
480 if (src_size < table_bytes + 3) {
496 block_pointer = src + table_bytes + 2;
497 bytes_left = src_size - table_bytes - 2;
500 if (bytes_left < ctx->block_size[i]) {
507 av_log(avctx,
AV_LOG_ERROR,
"Sir, I got carsick in your office. Not decoding the rest of packet.\n");
This structure describes decoded (raw) audio or video data.
int num_blocks
number of blocks inside the frame
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVFrame * coded_frame
the picture in the bitstream
#define AV_CH_LAYOUT_STEREO
static const uint8_t bias_def[3][128]
static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
static const uint8_t filter_coeffs_def[3][10][11][24]
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
enum AVSampleFormat sample_fmt
audio sample format
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int16_t *dst0, int16_t *dst1)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
bitstream reader API header.
struct RALFContext RALFContext
static int init(AVCodecParserContext *s)
static int get_bits_left(GetBitContext *gb)
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
int filter_bits
filter precision for the current channel data
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void decode_flush(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int decode_close(AVCodecContext *avctx)
static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch, int length, int mode, int bits)
static const uint8_t long_codes_def[3][125][224]
#define RALF_MAX_PKT_SIZE
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
uint64_t channel_layout
Audio channel layout.
int32_t channel_data[2][4096]
audio channel layout utility functions
#define FILTER_COEFFS_ELEMENTS
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
#define SHORT_CODES_ELEMENTS
static const uint8_t coding_mode_def[3][72]
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
int filter_params
combined filter parameters for the current channel data
int sample_rate
samples per second
#define FILTERPARAM_ELEMENTS
main external API structure.
static void close(AVCodecParserContext *s)
static unsigned int get_bits1(GetBitContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
VLC filter_coeffs[10][11]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int block_size[1<< 12]
size of the blocks
int block_pts[1<< 12]
block start time (in milliseconds)
#define CODING_MODE_ELEMENTS
common internal api header.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
#define AVERROR_INVALIDDATA
AVSampleFormat
Audio Sample Formats.
static const uint8_t short_codes_def[3][15][88]
int filter_length
length of the filter for the current channel data
#define AVERROR_PATCHWELCOME
static av_cold int decode_init(AVCodecContext *avctx)
static int extend_code(GetBitContext *gb, int val, int range, int bits)
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
static const uint8_t filter_param_def[3][324]
int bias[2]
a constant value added to channel data after filtering
#define LONG_CODES_ELEMENTS
#define AV_CH_LAYOUT_MONO
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
int nb_samples
number of audio samples (per channel) described by this frame
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)