39 #define FILTER_RAW 642
50 #define RALF_MAX_PKT_SIZE 8192
80 int counts[17], prefixes[18];
85 for (
i = 0;
i <= 16;
i++)
87 for (
i = 0;
i < elems;
i++) {
88 cur_len = (nb ? *
data & 0xF : *
data >> 4) + 1;
90 max_bits =
FFMAX(max_bits, cur_len);
96 for (
i = 1;
i <= 16;
i++)
97 prefixes[
i + 1] = (prefixes[
i] + counts[
i]) << 1;
99 for (
i = 0;
i < elems;
i++)
100 codes[
i] = prefixes[lens[
i]]++;
103 lens, 1, 1, codes, 2, 2,
NULL, 0, 0, 0);
111 for (
i = 0;
i < 3;
i++) {
115 for (j = 0; j < 10; j++)
116 for (k = 0; k < 11; k++)
118 for (j = 0; j < 15; j++)
120 for (j = 0; j < 125; j++)
139 if (
ctx->version != 0x103) {
157 if (
ctx->max_frame_size > (1 << 20) || !
ctx->max_frame_size) {
159 ctx->max_frame_size);
163 for (
i = 0;
i < 3;
i++) {
181 for (j = 0; j < 10; j++) {
182 for (k = 0; k < 11; k++) {
192 for (j = 0; j < 15; j++) {
200 for (j = 0; j < 125; j++) {
217 }
else if (
val == range * 2) {
234 int *dst =
ctx->channel_data[ch];
236 ctx->filter_params =
get_vlc2(gb,
set->filter_params.table, 9, 2);
237 if (
ctx->filter_params > 1) {
238 ctx->filter_bits = (
ctx->filter_params - 2) >> 6;
239 ctx->filter_length =
ctx->filter_params - (
ctx->filter_bits << 6) - 1;
243 for (
i = 0;
i < length;
i++)
253 memset(dst, 0,
sizeof(*dst) * length);
257 if (
ctx->filter_params > 1) {
258 int cmode = 0,
coeff = 0;
259 VLC *vlc =
set->filter_coeffs[
ctx->filter_bits] + 5;
261 add_bits =
ctx->filter_bits;
263 for (
i = 0;
i <
ctx->filter_length;
i++) {
267 coeff -= 12U << add_bits;
271 cmode =
coeff >> add_bits;
276 }
else if (cmode > 0) {
284 code_params =
get_vlc2(gb,
set->coding_mode.table,
set->coding_mode.bits, 2);
285 if (code_params >= 15) {
286 add_bits =
av_clip((code_params / 5 - 3) / 2, 0, 10);
287 if (add_bits > 9 && (code_params % 5) != 2)
299 for (
i = 0;
i < length;
i += 2) {
305 dst[
i] =
extend_code(gb, code1, range, 0) * (1U << add_bits);
306 dst[
i + 1] =
extend_code(gb, code2, range, 0) * (1U << add_bits);
319 int *audio =
ctx->channel_data[ch];
320 int bias = 1 << (
ctx->filter_bits - 1);
321 int max_clip = (1 <<
bits) - 1, min_clip = -max_clip - 1;
323 for (
i = 1;
i < length;
i++) {
327 for (j = 0; j < flen; j++)
328 acc += (
unsigned)
ctx->filter[j] * audio[
i - j - 1];
330 acc = (
acc + bias - 1) >>
ctx->filter_bits;
333 acc = ((unsigned)
acc + bias) >>
ctx->filter_bits;
341 int16_t *dst0, int16_t *dst1)
355 if (
ctx->sample_offset +
len >
ctx->max_frame_size) {
357 "Decoder's stomach is crying, it ate too many samples\n");
366 mode[0] = (dmode == 4) ? 1 : 0;
367 mode[1] = (dmode >= 2) ? 2 : 0;
371 for (ch = 0; ch < avctx->
channels; ch++) {
375 ctx->filter_bits += 3;
381 ch0 =
ctx->channel_data[0];
382 ch1 =
ctx->channel_data[1];
386 dst0[
i] = ch0[
i] +
ctx->bias[0];
390 dst0[
i] = ch0[
i] +
ctx->bias[0];
391 dst1[
i] = ch1[
i] +
ctx->bias[1];
395 for (
i = 0;
i <
len;
i++) {
396 ch0[
i] +=
ctx->bias[0];
398 dst1[
i] = ch0[
i] - (ch1[
i] +
ctx->bias[1]);
402 for (
i = 0;
i <
len;
i++) {
403 t = ch0[
i] +
ctx->bias[0];
404 t2 = ch1[
i] +
ctx->bias[1];
410 for (
i = 0;
i <
len;
i++) {
411 t = ch1[
i] +
ctx->bias[1];
412 t2 = ((ch0[
i] +
ctx->bias[0]) * 2) | (t & 1);
413 dst0[
i] = (
int)(
t2 + t) / 2;
414 dst1[
i] = (
int)(
t2 - t) / 2;
419 ctx->sample_offset +=
len;
433 int table_size, table_bytes,
i;
445 if (memcmp(
ctx->pkt, avpkt->
data, 2 + table_bytes)) {
453 avpkt->
size - 2 - table_bytes);
463 src_size = avpkt->
size;
477 table_bytes = (table_size + 7) >> 3;
478 if (src_size < table_bytes + 3) {
491 ctx->block_pts[
ctx->num_blocks] = 0;
496 block_pointer =
src + table_bytes + 2;
497 bytes_left = src_size - table_bytes - 2;
498 ctx->sample_offset = 0;
499 for (
i = 0;
i <
ctx->num_blocks;
i++) {
500 if (bytes_left < ctx->block_size[
i]) {
506 samples1 +
ctx->sample_offset) < 0) {
507 av_log(avctx,
AV_LOG_ERROR,
"Sir, I got carsick in your office. Not decoding the rest of packet.\n");
510 block_pointer +=
ctx->block_size[
i];
511 bytes_left -=
ctx->block_size[
i];
515 *got_frame_ptr =
ctx->sample_offset > 0;
static void flush(AVCodecContext *avctx)
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
Macro definitions for various function/variable attributes.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
int ff_init_vlc_sparse(VLC *vlc_arg, 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)
void ff_free_vlc(VLC *vlc)
audio channel layout utility functions
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
mode
Use these values in ebur128_init (or'ed).
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint16_t table[]
static int extend_code(GetBitContext *gb, int val, int range, int bits)
static av_cold int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
static av_cold int decode_close(AVCodecContext *avctx)
static av_cold int decode_init(AVCodecContext *avctx)
#define RALF_MAX_PKT_SIZE
static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch, int length, int mode, int bits)
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int16_t *dst0, int16_t *dst1)
static void decode_flush(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
static const uint8_t filter_coeffs_def[3][10][11][24]
static const uint8_t long_codes_def[3][125][224]
static const uint8_t filter_param_def[3][324]
#define CODING_MODE_ELEMENTS
#define SHORT_CODES_ELEMENTS
static const uint8_t bias_def[3][128]
#define FILTER_COEFFS_ELEMENTS
#define LONG_CODES_ELEMENTS
static const uint8_t short_codes_def[3][15][88]
static const uint8_t coding_mode_def[3][72]
#define FILTERPARAM_ELEMENTS
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int block_size[1<< 12]
size of the blocks
int num_blocks
number of blocks inside the frame
int filter_length
length of the filter for the current channel data
unsigned bias[2]
a constant value added to channel data after filtering
int32_t channel_data[2][4096]
int block_pts[1<< 12]
block start time (in milliseconds)
int filter_params
combined filter parameters for the current channel data
int filter_bits
filter precision for the current channel data
VLC filter_coeffs[10][11]
VLC_TYPE(* table)[2]
code, bits
#define avpriv_request_sample(...)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static const double coeff[2][5]