libavcodec/apedec.c File Reference

Monkey's Audio lossless audio decoder. More...

#include "avcodec.h"
#include "dsputil.h"
#include "bytestream.h"
#include "libavutil/audioconvert.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  APEFilter
 Filters applied to the decoded data. More...
struct  APERice
struct  APERangecoder
struct  APEPredictor
 Filter histories. More...
struct  APEContext
 Decoder context. More...

Defines

#define MAX_CHANNELS   2
#define MAX_BYTESPERSAMPLE   3
#define APE_FRAMECODE_MONO_SILENCE   1
#define APE_FRAMECODE_STEREO_SILENCE   3
#define APE_FRAMECODE_PSEUDO_STEREO   4
#define HISTORY_SIZE   512
#define PREDICTOR_ORDER   8
#define PREDICTOR_SIZE   50
 Total size of all predictor histories.
#define YDELAYA   (18 + PREDICTOR_ORDER*4)
#define YDELAYB   (18 + PREDICTOR_ORDER*3)
#define XDELAYA   (18 + PREDICTOR_ORDER*2)
#define XDELAYB   (18 + PREDICTOR_ORDER)
#define YADAPTCOEFFSA   18
#define XADAPTCOEFFSA   14
#define YADAPTCOEFFSB   10
#define XADAPTCOEFFSB   5
#define APE_FILTER_LEVELS   3
#define OFFSET(x)   offsetof(APEContext, x)
#define PAR   (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)

Enumerations

enum  APECompressionLevel {
  COMPRESSION_LEVEL_FAST = 1000, COMPRESSION_LEVEL_NORMAL = 2000, COMPRESSION_LEVEL_HIGH = 3000, COMPRESSION_LEVEL_EXTRA_HIGH = 4000,
  COMPRESSION_LEVEL_INSANE = 5000
}
 Possible compression levels. More...

Functions

static av_cold int ape_decode_close (AVCodecContext *avctx)
static av_cold int ape_decode_init (AVCodecContext *avctx)
static void update_rice (APERice *rice, unsigned int x)
static int ape_decode_value (APEContext *ctx, APERice *rice)
static void entropy_decode (APEContext *ctx, int blockstodecode, int stereo)
static int init_entropy_decoder (APEContext *ctx)
static void init_predictor_decoder (APEContext *ctx)
static int APESIGN (int32_t x)
 Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero).
static av_always_inline int predictor_update_filter (APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB)
static void predictor_decode_stereo (APEContext *ctx, int count)
static void predictor_decode_mono (APEContext *ctx, int count)
static void do_init_filter (APEFilter *f, int16_t *buf, int order)
static void init_filter (APEContext *ctx, APEFilter *f, int16_t *buf, int order)
static void do_apply_filter (APEContext *ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits)
static void apply_filter (APEContext *ctx, APEFilter *f, int32_t *data0, int32_t *data1, int count, int order, int fracbits)
static void ape_apply_filters (APEContext *ctx, int32_t *decoded0, int32_t *decoded1, int count)
static int init_frame_decoder (APEContext *ctx)
static void ape_unpack_mono (APEContext *ctx, int count)
static void ape_unpack_stereo (APEContext *ctx, int count)
static int ape_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void ape_flush (AVCodecContext *avctx)

Variables

static const uint16_t ape_filter_orders [5][APE_FILTER_LEVELS]
 Filter orders depending on compression level.
static const uint8_t ape_filter_fracbits [5][APE_FILTER_LEVELS]
 Filter fraction bits depending on compression level.
static const int32_t initial_coeffs [4]
static const AVOption options []
static const AVClass ape_decoder_class
AVCodec ff_ape_decoder

APE range decoding functions

#define CODE_BITS   32
#define TOP_VALUE   ((unsigned int)1 << (CODE_BITS-1))
#define SHIFT_BITS   (CODE_BITS - 9)
#define EXTRA_BITS   ((CODE_BITS-2) % 8 + 1)
#define BOTTOM_VALUE   (TOP_VALUE >> 8)
#define MODEL_ELEMENTS   64
static const uint16_t counts_3970 [22]
 Fixed probabilities for symbols in Monkey Audio version 3.97.
static const uint16_t counts_diff_3970 [21]
 Probability ranges for symbols in Monkey Audio version 3.97.
static const uint16_t counts_3980 [22]
 Fixed probabilities for symbols in Monkey Audio version 3.98.
static const uint16_t counts_diff_3980 [21]
 Probability ranges for symbols in Monkey Audio version 3.98.
static void range_start_decoding (APEContext *ctx)
 Start the decoder.
static void range_dec_normalize (APEContext *ctx)
 Perform normalization.
static int range_decode_culfreq (APEContext *ctx, int tot_f)
 Calculate culmulative frequency for next symbol.
static int range_decode_culshift (APEContext *ctx, int shift)
 Decode value with given size in bits.
static void range_decode_update (APEContext *ctx, int sy_f, int lt_f)
 Update decoding state.
static int range_decode_bits (APEContext *ctx, int n)
 Decode n bits (n <= 16) without modelling.
static int range_get_symbol (APEContext *ctx, const uint16_t counts[], const uint16_t counts_diff[])
 Decode symbol.


Detailed Description

Monkey's Audio lossless audio decoder.

Definition in file apedec.c.


Define Documentation

#define APE_FILTER_LEVELS   3

Definition at line 70 of file apedec.c.

Referenced by ape_apply_filters(), ape_decode_close(), ape_decode_init(), and init_frame_decoder().

#define APE_FRAMECODE_MONO_SILENCE   1

Definition at line 38 of file apedec.c.

#define APE_FRAMECODE_PSEUDO_STEREO   4

Definition at line 40 of file apedec.c.

Referenced by ape_decode_frame().

#define APE_FRAMECODE_STEREO_SILENCE   3

Definition at line 39 of file apedec.c.

Referenced by ape_unpack_mono(), and ape_unpack_stereo().

#define BOTTOM_VALUE   (TOP_VALUE >> 8)

Definition at line 255 of file apedec.c.

Referenced by range_dec_normalize().

#define CODE_BITS   32

Definition at line 251 of file apedec.c.

#define EXTRA_BITS   ((CODE_BITS-2) % 8 + 1)

Definition at line 254 of file apedec.c.

Referenced by range_start_decoding().

#define HISTORY_SIZE   512

#define MAX_BYTESPERSAMPLE   3

Definition at line 36 of file apedec.c.

#define MAX_CHANNELS   2

Definition at line 35 of file apedec.c.

#define MODEL_ELEMENTS   64

Definition at line 328 of file apedec.c.

Referenced by ape_decode_value().

#define OFFSET (  )     offsetof(APEContext, x)

Definition at line 972 of file apedec.c.

#define PAR   (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)

Definition at line 973 of file apedec.c.

#define PREDICTOR_ORDER   8

Definition at line 43 of file apedec.c.

#define PREDICTOR_SIZE   50

Total size of all predictor histories.

Definition at line 45 of file apedec.c.

Referenced by init_predictor_decoder(), predictor_decode_mono(), and predictor_decode_stereo().

#define SHIFT_BITS   (CODE_BITS - 9)

Definition at line 253 of file apedec.c.

#define TOP_VALUE   ((unsigned int)1 << (CODE_BITS-1))

Definition at line 252 of file apedec.c.

Referenced by ff_bgmc_decode_init().

#define XADAPTCOEFFSA   14

Definition at line 53 of file apedec.c.

Referenced by predictor_decode_stereo().

#define XADAPTCOEFFSB   5

Definition at line 55 of file apedec.c.

Referenced by predictor_decode_stereo().

#define XDELAYA   (18 + PREDICTOR_ORDER*2)

Definition at line 49 of file apedec.c.

Referenced by predictor_decode_stereo().

#define XDELAYB   (18 + PREDICTOR_ORDER)

Definition at line 50 of file apedec.c.

Referenced by predictor_decode_stereo().

#define YADAPTCOEFFSA   18

Definition at line 52 of file apedec.c.

Referenced by predictor_decode_mono(), and predictor_decode_stereo().

#define YADAPTCOEFFSB   10

Definition at line 54 of file apedec.c.

Referenced by predictor_decode_stereo().

#define YDELAYA   (18 + PREDICTOR_ORDER*4)

Definition at line 47 of file apedec.c.

Referenced by predictor_decode_mono(), and predictor_decode_stereo().

#define YDELAYB   (18 + PREDICTOR_ORDER*3)

Definition at line 48 of file apedec.c.

Referenced by predictor_decode_stereo().


Enumeration Type Documentation

Possible compression levels.

Enumerator:
COMPRESSION_LEVEL_FAST 
COMPRESSION_LEVEL_NORMAL 
COMPRESSION_LEVEL_HIGH 
COMPRESSION_LEVEL_EXTRA_HIGH 
COMPRESSION_LEVEL_INSANE 

Definition at line 61 of file apedec.c.


Function Documentation

static void ape_apply_filters ( APEContext ctx,
int32_t *  decoded0,
int32_t *  decoded1,
int  count 
) [static]

Definition at line 747 of file apedec.c.

Referenced by ape_unpack_mono(), and ape_unpack_stereo().

static av_cold int ape_decode_close ( AVCodecContext avctx  )  [static]

Definition at line 168 of file apedec.c.

Referenced by ape_decode_init().

static int ape_decode_frame ( AVCodecContext avctx,
void *  data,
int got_frame_ptr,
AVPacket avpkt 
) [static]

Definition at line 825 of file apedec.c.

static av_cold int ape_decode_init ( AVCodecContext avctx  )  [static]

Definition at line 183 of file apedec.c.

static int ape_decode_value ( APEContext ctx,
APERice rice 
) [inline, static]

Definition at line 407 of file apedec.c.

Referenced by entropy_decode().

static void ape_flush ( AVCodecContext avctx  )  [static]

Definition at line 966 of file apedec.c.

static void ape_unpack_mono ( APEContext ctx,
int  count 
) [static]

Definition at line 777 of file apedec.c.

Referenced by ape_decode_frame().

static void ape_unpack_stereo ( APEContext ctx,
int  count 
) [static]

Definition at line 797 of file apedec.c.

Referenced by ape_decode_frame().

static int APESIGN ( int32_t  x  )  [inline, static]

Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero).

Definition at line 543 of file apedec.c.

Referenced by do_apply_filter(), predictor_decode_mono(), and predictor_update_filter().

static void apply_filter ( APEContext ctx,
APEFilter f,
int32_t *  data0,
int32_t *  data1,
int  count,
int  order,
int  fracbits 
) [static]

Definition at line 738 of file apedec.c.

Referenced by ape_apply_filters().

static void do_apply_filter ( APEContext ctx,
int  version,
APEFilter f,
int32_t *  data,
int  count,
int  order,
int  fracbits 
) [static]

Definition at line 685 of file apedec.c.

Referenced by apply_filter().

static void do_init_filter ( APEFilter f,
int16_t buf,
int  order 
) [static]

Definition at line 667 of file apedec.c.

Referenced by init_filter().

static void entropy_decode ( APEContext ctx,
int  blockstodecode,
int  stereo 
) [static]

Definition at line 477 of file apedec.c.

Referenced by ape_unpack_mono(), and ape_unpack_stereo().

static int init_entropy_decoder ( APEContext ctx  )  [static]

Definition at line 489 of file apedec.c.

Referenced by init_frame_decoder().

static void init_filter ( APEContext ctx,
APEFilter f,
int16_t buf,
int  order 
) [static]

Definition at line 679 of file apedec.c.

Referenced by init_frame_decoder().

static int init_frame_decoder ( APEContext ctx  )  [static]

Definition at line 761 of file apedec.c.

Referenced by ape_decode_frame().

static void init_predictor_decoder ( APEContext ctx  )  [static]

Definition at line 524 of file apedec.c.

Referenced by init_frame_decoder().

static void predictor_decode_mono ( APEContext ctx,
int  count 
) [static]

Definition at line 621 of file apedec.c.

Referenced by ape_unpack_mono().

static void predictor_decode_stereo ( APEContext ctx,
int  count 
) [static]

Definition at line 594 of file apedec.c.

Referenced by ape_unpack_stereo().

static av_always_inline int predictor_update_filter ( APEPredictor p,
const int  decoded,
const int  filter,
const int  delayA,
const int  delayB,
const int  adaptA,
const int  adaptB 
) [static]

Definition at line 547 of file apedec.c.

Referenced by predictor_decode_stereo().

static void range_dec_normalize ( APEContext ctx  )  [inline, static]

Perform normalization.

Definition at line 266 of file apedec.c.

Referenced by range_decode_culfreq(), and range_decode_culshift().

static int range_decode_bits ( APEContext ctx,
int  n 
) [inline, static]

Decode n bits (n <= 16) without modelling.

Definition at line 320 of file apedec.c.

Referenced by ape_decode_value().

static int range_decode_culfreq ( APEContext ctx,
int  tot_f 
) [inline, static]

Calculate culmulative frequency for next symbol.

Does NO update!

Parameters:
ctx decoder context
tot_f is the total frequency or (code_value)1<<shift
Returns:
the culmulative frequency

Definition at line 287 of file apedec.c.

Referenced by ape_decode_value().

static int range_decode_culshift ( APEContext ctx,
int  shift 
) [inline, static]

Decode value with given size in bits.

Parameters:
ctx decoder context
shift number of bits to decode

Definition at line 299 of file apedec.c.

Referenced by range_decode_bits(), and range_get_symbol().

static void range_decode_update ( APEContext ctx,
int  sy_f,
int  lt_f 
) [inline, static]

Update decoding state.

Parameters:
ctx decoder context
sy_f the interval length (frequency of the symbol)
lt_f the lower end (frequency sum of < symbols)

Definition at line 313 of file apedec.c.

Referenced by ape_decode_value(), range_decode_bits(), and range_get_symbol().

static int range_get_symbol ( APEContext ctx,
const uint16_t  counts[],
const uint16_t  counts_diff[] 
) [inline, static]

Decode symbol.

Parameters:
ctx decoder context
counts probability range start position
counts_diff probability range widths

Definition at line 372 of file apedec.c.

Referenced by ape_decode_value().

static void range_start_decoding ( APEContext ctx  )  [inline, static]

Start the decoder.

Definition at line 258 of file apedec.c.

Referenced by init_entropy_decoder().

static void update_rice ( APERice rice,
unsigned int  x 
) [inline, static]

Definition at line 396 of file apedec.c.

Referenced by ape_decode_value().


Variable Documentation

const AVClass ape_decoder_class [static]

Initial value:

 {
    .class_name = "APE decoder",
    .item_name  = av_default_item_name,
    .option     = options,
    .version    = LIBAVUTIL_VERSION_INT,
}

Definition at line 980 of file apedec.c.

const uint8_t ape_filter_fracbits[5][APE_FILTER_LEVELS] [static]

Initial value:

 {
    {  0,  0,  0 },
    { 11,  0,  0 },
    { 11,  0,  0 },
    { 10, 13,  0 },
    { 11, 13, 15 }
}
Filter fraction bits depending on compression level.

Definition at line 82 of file apedec.c.

Referenced by ape_apply_filters().

const uint16_t ape_filter_orders[5][APE_FILTER_LEVELS] [static]

Initial value:

 {
    {  0,   0,    0 },
    { 16,   0,    0 },
    { 64,   0,    0 },
    { 32, 256,    0 },
    { 16, 256, 1280 }
}
Filter orders depending on compression level.

Definition at line 73 of file apedec.c.

Referenced by ape_apply_filters(), ape_decode_init(), and init_frame_decoder().

const uint16_t counts_3970[22] [static]

Initial value:

 {
        0, 14824, 28224, 39348, 47855, 53994, 58171, 60926,
    62682, 63786, 64463, 64878, 65126, 65276, 65365, 65419,
    65450, 65469, 65480, 65487, 65491, 65493,
}
Fixed probabilities for symbols in Monkey Audio version 3.97.

Definition at line 333 of file apedec.c.

Referenced by ape_decode_value().

const uint16_t counts_3980[22] [static]

Initial value:

 {
        0, 19578, 36160, 48417, 56323, 60899, 63265, 64435,
    64971, 65232, 65351, 65416, 65447, 65466, 65476, 65482,
    65485, 65488, 65490, 65491, 65492, 65493,
}
Fixed probabilities for symbols in Monkey Audio version 3.98.

Definition at line 351 of file apedec.c.

Referenced by ape_decode_value().

const uint16_t counts_diff_3970[21] [static]

Initial value:

 {
    14824, 13400, 11124, 8507, 6139, 4177, 2755, 1756,
    1104, 677, 415, 248, 150, 89, 54, 31,
    19, 11, 7, 4, 2,
}
Probability ranges for symbols in Monkey Audio version 3.97.

Definition at line 342 of file apedec.c.

Referenced by ape_decode_value().

const uint16_t counts_diff_3980[21] [static]

Initial value:

 {
    19578, 16582, 12257, 7906, 4576, 2366, 1170, 536,
    261, 119, 65, 31, 19, 10, 6, 3,
    3, 2, 1, 1, 1,
}
Probability ranges for symbols in Monkey Audio version 3.98.

Definition at line 360 of file apedec.c.

Referenced by ape_decode_value().

Initial value:

 {
    .name           = "ape",
    .type           = AVMEDIA_TYPE_AUDIO,
    .id             = AV_CODEC_ID_APE,
    .priv_data_size = sizeof(APEContext),
    .init           = ape_decode_init,
    .close          = ape_decode_close,
    .decode         = ape_decode_frame,
    .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY | CODEC_CAP_DR1,
    .flush          = ape_flush,
    .long_name      = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
    .priv_class     = &ape_decoder_class,
}

Definition at line 987 of file apedec.c.

const int32_t initial_coeffs[4] [static]

Initial value:

 {
    360, 317, -109, 98
}

Definition at line 520 of file apedec.c.

Referenced by init_predictor_decoder().

const AVOption options[] [static]

Initial value:

 {
    { "max_samples", "maximum number of samples decoded per call",             OFFSET(blocks_per_loop), AV_OPT_TYPE_INT,   { .i64 = 4608 },    1,       INT_MAX, PAR, "max_samples" },
    { "all",         "no maximum. decode all samples for each packet at once", 0,                       AV_OPT_TYPE_CONST, { .i64 = INT_MAX }, INT_MIN, INT_MAX, PAR, "max_samples" },
    { NULL},
}

Definition at line 974 of file apedec.c.


Generated on Fri Oct 26 02:50:04 2012 for FFmpeg by  doxygen 1.5.8