46#define MAX_BYTESPERSAMPLE 3
48#define APE_FRAMECODE_MONO_SILENCE 1
49#define APE_FRAMECODE_STEREO_SILENCE 3
50#define APE_FRAMECODE_PSEUDO_STEREO 4
52#define HISTORY_SIZE 512
53#define PREDICTOR_ORDER 8
55#define PREDICTOR_SIZE 50
57#define YDELAYA (18 + PREDICTOR_ORDER*4)
58#define YDELAYB (18 + PREDICTOR_ORDER*3)
59#define XDELAYA (18 + PREDICTOR_ORDER*2)
60#define XDELAYB (18 + PREDICTOR_ORDER)
62#define YADAPTCOEFFSA 18
63#define XADAPTCOEFFSA 14
64#define YADAPTCOEFFSB 10
65#define XADAPTCOEFFSB 5
80#define APE_FILTER_LEVELS 3
234 s->decoded_size =
s->data_size = 0;
266 s->interim_mode = -1;
270 "%d bits per coded sample",
s->bps);
280 s->compression_level,
s->flags);
282 !
s->compression_level ||
285 s->compression_level);
288 s->fset =
s->compression_level / 1000 - 1;
296 if (
s->fileversion < 3860) {
299 }
else if (
s->fileversion < 3900) {
302 }
else if (
s->fileversion < 3930) {
305 }
else if (
s->fileversion < 3990) {
313 if (
s->fileversion < 3930) {
316 }
else if (
s->fileversion < 3950) {
339#define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1))
340#define SHIFT_BITS (CODE_BITS - 9)
341#define EXTRA_BITS ((CODE_BITS-2) % 8 + 1)
342#define BOTTOM_VALUE (TOP_VALUE >> 8)
347 ctx->rc.buffer = bytestream_get_byte(&
ctx->ptr);
356 ctx->rc.buffer <<= 8;
357 if(
ctx->ptr <
ctx->data_end) {
358 ctx->rc.buffer += *
ctx->ptr;
363 ctx->rc.low = (
ctx->rc.low << 8) | ((
ctx->rc.buffer >> 1) & 0xFF);
377 ctx->rc.help =
ctx->rc.range / tot_f;
378 return ctx->rc.low /
ctx->rc.help;
390 return ctx->rc.low /
ctx->rc.help;
402 ctx->rc.low -=
ctx->rc.help * lt_f;
403 ctx->rc.range =
ctx->rc.help * sy_f;
415#define MODEL_ELEMENTS 64
421 0, 14824, 28224, 39348, 47855, 53994, 58171, 60926,
422 62682, 63786, 64463, 64878, 65126, 65276, 65365, 65419,
423 65450, 65469, 65480, 65487, 65491, 65493,
430 14824, 13400, 11124, 8507, 6139, 4177, 2755, 1756,
431 1104, 677, 415, 248, 150, 89, 54, 31,
439 0, 19578, 36160, 48417, 56323, 60899, 63265, 64435,
440 64971, 65232, 65351, 65416, 65447, 65466, 65476, 65482,
441 65485, 65488, 65490, 65491, 65492, 65493,
448 19578, 16582, 12257, 7906, 4576, 2366, 1170, 536,
449 261, 119, 65, 31, 19, 10, 6, 3,
460 const uint16_t counts[],
461 const uint16_t counts_diff[])
468 symbol= cf - 65535 + 63;
475 for (symbol = 0; counts[symbol + 1] <= cf; symbol++);
485 int lim = rice->
k ? (1 << (rice->
k + 4)) : 0;
486 rice->
ksum += ((x + 1) / 2) - ((rice->
ksum + 16) >> 5);
488 if (rice->
ksum < lim)
490 else if (rice->
ksum >= (1 << (rice->
k + 5)) && rice->
k < 24)
509 unsigned int x, overflow;
513 if (
ctx->fileversion > 3880) {
514 while (overflow >= 16) {
529 rice->
ksum += x - (rice->
ksum + 8 >> 4);
530 if (rice->
ksum < (rice->
k ? 1 << (rice->
k + 4) : 0))
532 else if (rice->
ksum >= (1 << (rice->
k + 5)) && rice->
k < 24)
536 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
541 unsigned int x, overflow;
550 tmpk = (rice->
k < 1) ? 0 : rice->
k - 1;
558 }
else if (tmpk <= 31) {
565 x += overflow << tmpk;
570 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
575 unsigned int x, overflow, pivot;
587 if (pivot < 0x10000) {
591 int base_hi = pivot, base_lo;
594 while (base_hi & ~0xFFFF) {
603 base = (base_hi << bbits) + base_lo;
606 x =
base + overflow * pivot;
611 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
623 unsigned ksummax, ksummin;
626 for (
i = 0;
i <
FFMIN(blockstodecode, 5);
i++) {
631 if (blockstodecode <= 5)
637 for (;
i <
FFMIN(blockstodecode, 64);
i++) {
645 if (blockstodecode <= 64)
649 ksummax = 1 << rice->
k + 7;
650 ksummin = rice->
k ? (1 << rice->
k + 6) : 0;
651 for (;
i < blockstodecode;
i++) {
658 while (rice->
ksum < ksummin) {
660 ksummin = rice->
k ? ksummin >> 1 : 0;
663 while (rice->
ksum >= ksummax) {
668 ksummin = ksummin ? ksummin << 1 : 128;
673 for (
i = 0;
i < blockstodecode;
i++)
695 while (blockstodecode--)
703 int blocks = blockstodecode;
705 while (blockstodecode--)
715 while (blockstodecode--)
723 int blocks = blockstodecode;
725 while (blockstodecode--)
740 while (blockstodecode--) {
750 while (blockstodecode--)
759 while (blockstodecode--) {
768 if (
ctx->fileversion >= 3900) {
769 if (
ctx->data_end -
ctx->ptr < 6)
771 ctx->CRC = bytestream_get_be32(&
ctx->ptr);
778 ctx->CRC_state = UINT32_MAX;
779 if ((
ctx->fileversion > 3820) && (
ctx->CRC & 0x80000000)) {
780 ctx->CRC &= ~0x80000000;
782 if (
ctx->data_end -
ctx->ptr < 6)
784 ctx->frameflags = bytestream_get_be32(&
ctx->ptr);
789 ctx->riceX.ksum = (1 <<
ctx->riceX.k) * 16;
791 ctx->riceY.ksum = (1 <<
ctx->riceY.k) * 16;
793 if (
ctx->fileversion >= 3900) {
829 memset(p->historybuffer, 0,
PREDICTOR_SIZE *
sizeof(*p->historybuffer));
831 p->buf = p->historybuffer;
835 if (
ctx->fileversion < 3930) {
853 memset(p->coeffsB, 0,
sizeof(p->coeffsB));
855 if (
ctx->fileversion < 3930) {
862 p->filterA[0] = p->filterA[1] = 0;
863 p->filterB[0] = p->filterB[1] = 0;
864 p->lastA[0] = p->lastA[1] = 0;
875 return (x < 0) - (x > 0);
884 p->buf[delayA] = p->lastA[
filter];
885 if (p->sample_pos < 3) {
891 predictionA = p->buf[delayA] * 2U - p->buf[delayA - 1];
894 if ((
decoded ^ predictionA) > 0)
901 return p->filterA[
filter];
906 const int delayA,
const int delayB,
907 const int start,
const int shift)
909 int32_t predictionA, predictionB, sign;
912 p->buf[delayA] = p->lastA[
filter];
913 p->buf[delayB] = p->filterB[
filter];
914 if (p->sample_pos < start) {
918 p->filterA[
filter] = predictionA;
922 d1 = (p->buf[delayA] - (unsigned)p->buf[delayA - 1]) * 2;
923 d0 = p->buf[delayA] + ((p->buf[delayA - 2] - (unsigned)p->buf[delayA - 1]) * 8);
924 d3 = p->buf[delayB] * 2U - p->buf[delayB - 1];
927 predictionA = d0 * p->coeffsA[
filter][0] +
928 d1 * p->coeffsA[
filter][1] +
929 d2 * p->coeffsA[
filter][2];
932 p->coeffsA[
filter][0] += (((d0 >> 30) & 2) - 1) * sign;
933 p->coeffsA[
filter][1] += (((d1 >> 28) & 8) - 4) * sign;
934 p->coeffsA[
filter][2] += (((d2 >> 28) & 8) - 4) * sign;
936 predictionB = d3 * p->coeffsB[
filter][0] -
937 d4 * p->coeffsB[
filter][1];
940 p->coeffsB[
filter][0] += (((d3 >> 29) & 4) - 2) * sign;
941 p->coeffsB[
filter][1] -= (((d4 >> 30) & 2) - 1) * sign;
944 p->filterA[
filter] = p->filterB[
filter] + (unsigned)((
int)(p->filterA[
filter] * 31U) >> 5);
946 return p->filterA[
filter];
953 int32_t coeffs[256], delay[256+256], *delayp = delay;
958 memset(coeffs, 0, order *
sizeof(*coeffs));
959 for (
i = 0;
i < order;
i++)
961 for (
i = order;
i < length;
i++) {
965 for (j = 0; j < order; j++) {
966 dotprod += delayp[j] * (unsigned)coeffs[j];
967 coeffs[j] += (delayp[j] >> 31) | 1;
969 }
else if (sign == -1) {
970 for (j = 0; j < order; j++) {
971 dotprod += delayp[j] * (unsigned)coeffs[j];
972 coeffs[j] -= (delayp[j] >> 31) | 1;
975 for (j = 0; j < order; j++) {
976 dotprod += delayp[j] * (unsigned)coeffs[j];
982 if (delayp - delay == 256) {
983 memcpy(delay, delayp,
sizeof(*delay)*256);
994 uint32_t coeffs[8] = { 0 };
996 for (
i = 0;
i < length;
i++) {
999 for (j = 7; j >= 0; j--) {
1000 dotprod += delay[j] * coeffs[j];
1001 coeffs[j] += ((delay[j] >> 31) | 1) * sign;
1003 for (j = 7; j > 0; j--)
1004 delay[j] = delay[j - 1];
1006 buffer[
i] -= (unsigned)(dotprod >> 9);
1015 int start = 4,
shift = 10;
1022 int order = 128,
shift2 = 11;
1024 if (
ctx->fileversion >= 3830) {
1037 int X = *decoded0,
Y = *decoded1;
1058 memmove(p->historybuffer, p->buf,
1060 p->buf = p->historybuffer;
1069 int start = 4,
shift = 10;
1075 int order = 128,
shift2 = 11;
1077 if (
ctx->fileversion >= 3830) {
1103 memmove(p->historybuffer, p->buf,
1105 p->buf = p->historybuffer;
1115 uint32_t d0, d1, d2, d3;
1117 p->buf[delayA] = p->lastA[
filter];
1118 d0 = p->buf[delayA ];
1119 d1 = p->buf[delayA ] - (unsigned)p->buf[delayA - 1];
1120 d2 = p->buf[delayA - 1] - (unsigned)p->buf[delayA - 2];
1121 d3 = p->buf[delayA - 2] - (unsigned)p->buf[delayA - 3];
1123 predictionA = d0 * p->coeffsA[
filter][0] +
1124 d1 * p->coeffsA[
filter][1] +
1125 d2 * p->coeffsA[
filter][2] +
1126 d3 * p->coeffsA[
filter][3];
1132 p->coeffsA[
filter][0] += (((
int32_t)d0 < 0) * 2 - 1) * sign;
1133 p->coeffsA[
filter][1] += (((
int32_t)d1 < 0) * 2 - 1) * sign;
1134 p->coeffsA[
filter][2] += (((
int32_t)d2 < 0) * 2 - 1) * sign;
1135 p->coeffsA[
filter][3] += (((
int32_t)d3 < 0) * 2 - 1) * sign;
1137 return p->filterA[
filter];
1150 int Y = *decoded1,
X = *decoded0;
1161 memmove(p->historybuffer, p->buf,
1163 p->buf = p->historybuffer;
1183 memmove(p->historybuffer, p->buf,
1185 p->buf = p->historybuffer;
1192 const int delayA,
const int delayB,
1193 const int adaptA,
const int adaptB,
1196 int64_t predictionA, predictionB;
1199 p->buf[delayA] = p->lastA[
filter];
1200 p->buf[adaptA] =
APESIGN(p->buf[delayA]);
1201 p->buf[delayA - 1] = p->buf[delayA] - (uint64_t)p->buf[delayA - 1];
1202 p->buf[adaptA - 1] =
APESIGN(p->buf[delayA - 1]);
1204 predictionA = p->buf[delayA ] * p->coeffsA[
filter][0] +
1205 p->buf[delayA - 1] * p->coeffsA[
filter][1] +
1206 p->buf[delayA - 2] * p->coeffsA[
filter][2] +
1207 p->buf[delayA - 3] * p->coeffsA[
filter][3];
1211 p->buf[adaptB] =
APESIGN(p->buf[delayB]);
1212 p->buf[delayB - 1] = p->buf[delayB] - (uint64_t)p->buf[delayB - 1];
1213 p->buf[adaptB - 1] =
APESIGN(p->buf[delayB - 1]);
1216 predictionB = p->buf[delayB ] * p->coeffsB[
filter][0] +
1217 p->buf[delayB - 1] * p->coeffsB[
filter][1] +
1218 p->buf[delayB - 2] * p->coeffsB[
filter][2] +
1219 p->buf[delayB - 3] * p->coeffsB[
filter][3] +
1220 p->buf[delayB - 4] * p->coeffsB[
filter][4];
1223 predictionA = (
int32_t)predictionA;
1224 predictionB = (
int32_t)predictionB;
1232 p->coeffsA[
filter][0] += p->buf[adaptA ] * sign;
1233 p->coeffsA[
filter][1] += p->buf[adaptA - 1] * sign;
1234 p->coeffsA[
filter][2] += p->buf[adaptA - 2] * sign;
1235 p->coeffsA[
filter][3] += p->buf[adaptA - 3] * sign;
1236 p->coeffsB[
filter][0] += p->buf[adaptB ] * sign;
1237 p->coeffsB[
filter][1] += p->buf[adaptB - 1] * sign;
1238 p->coeffsB[
filter][2] += p->buf[adaptB - 2] * sign;
1239 p->coeffsB[
filter][3] += p->buf[adaptB - 3] * sign;
1240 p->coeffsB[
filter][4] += p->buf[adaptB - 4] * sign;
1242 return p->filterA[
filter];
1253 if (
ctx->interim_mode == -1) {
1254 p_interim = *p_default;
1256 memcpy(
ctx->interim[0],
ctx->decoded[0],
sizeof(*
ctx->interim[0])*count);
1257 memcpy(
ctx->interim[1],
ctx->decoded[1],
sizeof(*
ctx->interim[1])*count);
1260 for (
int pass = 0; pass < num_passes; pass++) {
1267 decoded0 =
ctx->interim[0];
1268 decoded1 =
ctx->interim[1];
1271 decoded0 =
ctx->decoded[0];
1272 decoded1 =
ctx->decoded[1];
1274 p->buf = p->historybuffer;
1287 if (num_passes > 1) {
1303 memmove(p->historybuffer, p->buf,
1305 p->buf = p->historybuffer;
1309 if (num_passes > 1 &&
ctx->interim_mode > 0) {
1310 memcpy(
ctx->decoded[0],
ctx->interim[0],
sizeof(*
ctx->interim[0])*lcount);
1311 memcpy(
ctx->decoded[1],
ctx->interim[1],
sizeof(*
ctx->interim[1])*lcount);
1312 *p_default = p_interim;
1321 int32_t predictionA, currentA,
A, sign;
1325 currentA = p->lastA[0];
1333 predictionA = p->buf[
YDELAYA ] * p->coeffsA[0][0] +
1334 p->buf[
YDELAYA - 1] * p->coeffsA[0][1] +
1335 p->buf[
YDELAYA - 2] * p->coeffsA[0][2] +
1336 p->buf[
YDELAYA - 3] * p->coeffsA[0][3];
1338 currentA =
A + (uint64_t)(predictionA >> 10);
1353 memmove(p->historybuffer, p->buf,
1355 p->buf = p->historybuffer;
1358 p->filterA[0] = currentA + (uint64_t)((
int64_t)(p->filterA[0] * 31U) >> 5);
1359 *(decoded0++) = p->filterA[0];
1362 p->lastA[0] = currentA;
1368 f->historybuffer = buf + order;
1369 f->delay =
f->historybuffer + order * 2;
1370 f->adaptcoeffs =
f->historybuffer + order;
1372 memset(
f->historybuffer, 0, (order * 2) *
sizeof(*
f->historybuffer));
1373 memset(
f->coeffs, 0, order *
sizeof(*
f->coeffs));
1384 int32_t *
data,
int count,
int order,
int fracbits)
1391 res =
ctx->adsp.scalarproduct_and_madd_int16(
f->coeffs,
1393 f->adaptcoeffs - order,
1395 res = (
int64_t)(res + (1LL << (fracbits - 1))) >> fracbits;
1396 res += (unsigned)*
data;
1404 f->adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4;
1405 f->adaptcoeffs[-4] >>= 1;
1406 f->adaptcoeffs[-8] >>= 1;
1414 (8 << ((absres >
f->avg * 3LL) + (absres > (
f->avg +
f->avg / 3))));
1424 *
f->adaptcoeffs = 0;
1426 f->avg += (int)(absres - (
unsigned)
f->avg) / 16;
1428 f->adaptcoeffs[-1] >>= 1;
1429 f->adaptcoeffs[-2] >>= 1;
1430 f->adaptcoeffs[-8] >>= 1;
1437 memmove(
f->historybuffer,
f->delay - (order * 2),
1438 (order * 2) *
sizeof(*
f->historybuffer));
1439 f->delay =
f->historybuffer + order * 2;
1440 f->adaptcoeffs =
f->historybuffer + order;
1447 int count,
int order,
int fracbits)
1492 ctx->entropy_decode_mono(
ctx, count);
1497 ctx->predictor_decode_mono(
ctx, count);
1500 if (
ctx->channels == 2) {
1501 memcpy(
ctx->decoded[1],
ctx->decoded[0], count *
sizeof(*
ctx->decoded[1]));
1507 unsigned left, right;
1517 ctx->entropy_decode_stereo(
ctx, count);
1522 ctx->predictor_decode_stereo(
ctx, count);
1526 left = *decoded1 - (unsigned)(*decoded0 / 2);
1527 right =
left + *decoded0;
1529 *(decoded0++) =
left;
1530 *(decoded1++) = right;
1535 int *got_frame_ptr,
AVPacket *avpkt)
1537 const uint8_t *buf = avpkt->
data;
1544 uint64_t decoded_buffer_size;
1551 uint32_t nblocks,
offset;
1558 if (avpkt->
size < 8) {
1562 buf_size = avpkt->
size & ~3;
1563 if (buf_size != avpkt->
size) {
1565 "extra bytes at the end will be skipped.\n");
1567 if (
s->fileversion < 3950)
1572 s->bdsp.bswap_buf((uint32_t *)
s->data, (
const uint32_t *) buf,
1574 memset(
s->data + (buf_size & ~3), 0, buf_size & 3);
1576 s->data_end =
s->data + buf_size;
1578 nblocks = bytestream_get_be32(&
s->ptr);
1579 offset = bytestream_get_be32(&
s->ptr);
1580 if (
s->fileversion >= 3900) {
1587 if (
s->data_end -
s->ptr <
offset) {
1595 if (
s->fileversion > 3800)
1601 if (!nblocks || nblocks > INT_MAX / 2 /
sizeof(*
s->decoded_buffer) - 8) {
1612 s->samples = nblocks;
1620 blockstodecode =
FFMIN(
s->blocks_per_loop,
s->samples);
1623 if (
s->fileversion < 3930)
1624 blockstodecode =
s->samples;
1627 decoded_buffer_size = 2LL *
FFALIGN(blockstodecode, 8) *
sizeof(*
s->decoded_buffer);
1631 frame->nb_samples = blockstodecode;
1638 if (!
s->decoded_buffer)
1640 memset(
s->decoded_buffer, 0, decoded_buffer_size);
1641 s->decoded[0] =
s->decoded_buffer;
1642 s->decoded[1] =
s->decoded_buffer +
FFALIGN(blockstodecode, 8);
1644 if (
s->interim_mode < 0) {
1646 if (!
s->interim_buffer)
1648 memset(
s->interim_buffer, 0, decoded_buffer_size);
1649 s->interim[0] =
s->interim_buffer;
1650 s->interim[1] =
s->interim_buffer +
FFALIGN(blockstodecode, 8);
1653 s->interim_size = 0;
1654 memset(
s->interim, 0,
sizeof(
s->interim));
1672 for (ch = 0; ch <
s->channels; ch++) {
1673 sample8 = (uint8_t *)
frame->data[ch];
1674 for (
i = 0;
i < blockstodecode;
i++)
1675 *sample8++ = (
s->decoded[ch][
i] + 0x80U) & 0xff;
1679 for (ch = 0; ch <
s->channels; ch++) {
1680 sample16 = (int16_t *)
frame->data[ch];
1681 for (
i = 0;
i < blockstodecode;
i++)
1682 *sample16++ =
s->decoded[ch][
i];
1686 for (ch = 0; ch <
s->channels; ch++) {
1688 for (
i = 0;
i < blockstodecode;
i++)
1689 *sample24++ =
s->decoded[ch][
i] * 256U;
1694 s->samples -= blockstodecode;
1697 s->fileversion >= 3900) {
1698 uint32_t crc =
s->CRC_state;
1700 int stride =
s->bps == 24 ? 4 : (
s->bps>>3);
1702 int bytes =
s->bps >> 3;
1704 for (
i = 0;
i < blockstodecode;
i++) {
1705 for (ch = 0; ch <
s->channels; ch++) {
1709 for(
int j = 0; j<
stride; j++)
1710 smp[j] = smp_native[
stride-j-1];
1718 if (!
s->samples && (~crc >> 1) ^
s->CRC) {
1720 "frames may have been affected as well.\n");
1730 return !
s->samples ? avpkt->
size : 0;
1739#define OFFSET(x) offsetof(APEContext, x)
1740#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1743 {
"all",
"no maximum. decode all samples for each packet at once", 0,
AV_OPT_TYPE_CONST, { .i64 = INT_MAX }, INT_MIN, INT_MAX,
PAR, .unit =
"max_samples" },
1748 .class_name =
"APE decoder",
const FFCodec ff_ape_decoder
static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode)
static void entropy_decode_stereo_3930(APEContext *ctx, int blockstodecode)
static const uint8_t ape_filter_fracbits[5][APE_FILTER_LEVELS]
Filter fraction bits depending on compression level.
static void range_dec_normalize(APEContext *ctx)
Perform normalization.
static av_cold int ape_decode_close(AVCodecContext *avctx)
static void entropy_decode_mono_3860(APEContext *ctx, int blockstodecode)
static int APESIGN(int32_t x)
Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero)
static const int32_t initial_coeffs_fast_3320[1]
static void entropy_decode_mono_3900(APEContext *ctx, int blockstodecode)
static av_always_inline int filter_fast_3320(APEPredictor *p, const int decoded, const int filter, const int delayA)
static int ape_decode_value_3900(APEContext *ctx, APERice *rice)
static int ape_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits)
static const uint16_t ape_filter_orders[5][APE_FILTER_LEVELS]
Filter orders depending on compression level.
static void range_decode_update(APEContext *ctx, int sy_f, int lt_f)
Update decoding state.
static void predictor_decode_stereo_3950(APEContext *ctx, int count)
static void do_init_filter(APEFilter *f, int16_t *buf, int order)
static int get_k(int ksum)
#define APE_FRAMECODE_STEREO_SILENCE
static int range_decode_culfreq(APEContext *ctx, int tot_f)
Calculate cumulative frequency for next symbol.
static void update_rice(APERice *rice, unsigned int x)
APECompressionLevel
Possible compression levels.
@ COMPRESSION_LEVEL_EXTRA_HIGH
@ COMPRESSION_LEVEL_INSANE
@ COMPRESSION_LEVEL_NORMAL
static int ape_decode_value_3990(APEContext *ctx, APERice *rice)
static av_always_inline int filter_3800(APEPredictor *p, const unsigned decoded, const int filter, const int delayA, const int delayB, const int start, const int shift)
static const int32_t initial_coeffs_b_3800[2]
static void ape_apply_filters(APEContext *ctx, int32_t *decoded0, int32_t *decoded1, int count)
static void ape_unpack_mono(APEContext *ctx, int count)
static void long_filter_high_3800(int32_t *buffer, int order, int shift, int length)
static void predictor_decode_mono_3930(APEContext *ctx, int count)
static int init_entropy_decoder(APEContext *ctx)
#define PREDICTOR_SIZE
Total size of all predictor histories.
static const int64_t initial_coeffs_3930_64bit[4]
static int range_decode_culshift(APEContext *ctx, int shift)
Decode value with given size in bits.
static const int32_t initial_coeffs_a_3800[3]
static void init_filter(APEContext *ctx, APEFilter *f, int16_t *buf, int order)
static void entropy_decode_stereo_0000(APEContext *ctx, int blockstodecode)
static void long_filter_ehigh_3830(int32_t *buffer, int length)
static av_cold int ape_decode_init(AVCodecContext *avctx)
static int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb, APERice *rice)
static const int32_t initial_coeffs_3930[4]
static void entropy_decode_mono_0000(APEContext *ctx, int blockstodecode)
static void entropy_decode_stereo_3900(APEContext *ctx, int blockstodecode)
static void predictor_decode_stereo_3800(APEContext *ctx, int count)
static int range_get_symbol(APEContext *ctx, const uint16_t counts[], const uint16_t counts_diff[])
Decode symbol.
#define APE_FILTER_LEVELS
static void entropy_decode_mono_3990(APEContext *ctx, int blockstodecode)
static void entropy_decode_stereo_3990(APEContext *ctx, int blockstodecode)
static void predictor_decode_stereo_3930(APEContext *ctx, int count)
static av_always_inline int predictor_update_3930(APEPredictor *p, const int decoded, const int filter, const int delayA)
static int get_rice_ook(GetBitContext *gb, int k)
static av_always_inline int predictor_update_filter(APEPredictor64 *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB, int interim_mode)
static const AVClass ape_decoder_class
static void predictor_decode_mono_3800(APEContext *ctx, int count)
static void decode_array_0000(APEContext *ctx, GetBitContext *gb, int32_t *out, APERice *rice, int blockstodecode)
static av_cold void ape_flush(AVCodecContext *avctx)
static const uint16_t counts_3970[22]
Fixed probabilities for symbols in Monkey Audio version 3.97.
static void ape_unpack_stereo(APEContext *ctx, int count)
static void range_start_decoding(APEContext *ctx)
Start the decoder.
static const uint16_t counts_diff_3970[21]
Probability ranges for symbols in Monkey Audio version 3.97.
static const uint16_t counts_diff_3980[21]
Probability ranges for symbols in Monkey Audio version 3.98.
static const uint16_t counts_3980[22]
Fixed probabilities for symbols in Monkey Audio version 3.98.
static void init_predictor_decoder(APEContext *ctx)
static void apply_filter(APEContext *ctx, APEFilter *f, int32_t *data0, int32_t *data1, int count, int order, int fracbits)
static int range_decode_bits(APEContext *ctx, int n)
Decode n bits (n <= 16) without modelling.
static int init_frame_decoder(APEContext *ctx)
static void predictor_decode_mono_3950(APEContext *ctx, int count)
#define APE_FRAMECODE_PSEUDO_STEREO
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFNABS(a)
Negative Absolute value.
#define FFABSU(a)
Unsigned Absolute value.
Public header for CRC hash function implementation.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_EXPLODE
abort decoding on minor error detection
int(* init)(AVBSFContext *ctx)
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
#define LIBAVUTIL_VERSION_INT
static int shift(int a, int b)
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
static const uint8_t shift2[6]
Macro definitions for various function/variable attributes.
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
Memory handling functions.
void(* entropy_decode_stereo)(struct APEContext *ctx, int blockstodecode)
int32_t * decoded[MAX_CHANNELS]
decoded data for each channel
int16_t * filterbuf[APE_FILTER_LEVELS]
filter memory
int samples
samples left to decode in current frame
const uint8_t * ptr
current position in frame data
void(* predictor_decode_mono)(struct APEContext *ctx, int count)
int32_t * interim[MAX_CHANNELS]
decoded data for each channel
int flags
global decoder flags
int data_size
frame data allocated size
APEPredictor64 predictor64
64bit predictor used for final reconstruction
void(* predictor_decode_stereo)(struct APEContext *ctx, int count)
APERice riceY
rice code parameters for the first channel
uint8_t * data_end
frame data end
int fileversion
codec version, very important in decoding process
APEFilter filters[APE_FILTER_LEVELS][2]
filters used for reconstruction
uint32_t CRC_state
accumulated CRC
APEPredictor predictor
predictor used for final reconstruction
uint32_t CRC
signalled frame CRC
APERangecoder rc
rangecoder used to decode actual values
APERice riceX
rice code parameters for the second channel
int compression_level
compression levels
int blocks_per_loop
maximum number of samples to decode for each call
void(* entropy_decode_mono)(struct APEContext *ctx, int blockstodecode)
uint8_t * data
current frame data
int fset
which filter set to use (calculated from compression level)
int frameflags
frame flags
Filters applied to the decoded data.
int16_t * historybuffer
filter memory
int16_t * delay
filtered values
int16_t * coeffs
actual coefficients used in filtering
int16_t * adaptcoeffs
adaptive filter coefficients used for correcting of actual filter coefficients
uint64_t coeffsB[2][5]
adaption coefficients
uint64_t coeffsA[2][4]
adaption coefficients
int64_t historybuffer[HISTORY_SIZE+PREDICTOR_SIZE]
int32_t historybuffer[HISTORY_SIZE+PREDICTOR_SIZE]
uint32_t coeffsA[2][4]
adaption coefficients
uint32_t coeffsB[2][5]
adaption coefficients
uint32_t low
low end of interval
unsigned int buffer
buffer for input/output
uint32_t range
length of interval
uint32_t help
bytes_to_follow resp. intermediate value
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
#define avpriv_request_sample(...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static double a0(void *priv, double x, double y)
static double a1(void *priv, double x, double y)