#include "bytestream.h"
/**
- * @file apedec.c
+ * @file libavcodec/apedec.c
* Monkey's Audio lossless audio decoder
*/
av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n");
return -1;
}
- if (avctx->bits_per_sample != 16) {
+ if (avctx->bits_per_coded_sample != 16) {
av_log(avctx, AV_LOG_ERROR, "Only 16-bit samples are supported\n");
return -1;
}
dsputil_init(&s->dsp, avctx);
avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
return 0;
}
/**
* Calculate culmulative frequency for next symbol. Does NO update!
+ * @param ctx decoder context
* @param tot_f is the total frequency or (code_value)1<<shift
* @return the culmulative frequency
*/
/**
* Decode value with given size in bits
+ * @param ctx decoder context
* @param shift number of bits to decode
*/
static inline int range_decode_culshift(APEContext * ctx, int shift)
/**
* Update decoding state
+ * @param ctx decoder context
* @param sy_f the interval length (frequency of the symbol)
* @param lt_f the lower end (frequency sum of < symbols)
*/
/**
* Decode symbol
+ * @param ctx decoder context
* @param counts probability range start position
- * @param count_diffs probability range widths
+ * @param counts_diff probability range widths
*/
static inline int range_get_symbol(APEContext * ctx,
const uint16_t counts[],
static inline void update_rice(APERice *rice, int x)
{
+ int lim = rice->k ? (1 << (rice->k + 4)) : 0;
rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5);
- if (rice->k == 0)
- rice->k = 1;
- else if (rice->ksum < (1 << (rice->k + 4)))
+ if (rice->ksum < lim)
rice->k--;
else if (rice->ksum >= (1 << (rice->k + 5)))
rice->k++;