41 #define MAX_CHANNELS 2
42 #define MAX_BYTESPERSAMPLE 3
44 #define APE_FRAMECODE_MONO_SILENCE 1
45 #define APE_FRAMECODE_STEREO_SILENCE 3
46 #define APE_FRAMECODE_PSEUDO_STEREO 4
48 #define HISTORY_SIZE 512
49 #define PREDICTOR_ORDER 8
51 #define PREDICTOR_SIZE 50
53 #define YDELAYA (18 + PREDICTOR_ORDER*4)
54 #define YDELAYB (18 + PREDICTOR_ORDER*3)
55 #define XDELAYA (18 + PREDICTOR_ORDER*2)
56 #define XDELAYB (18 + PREDICTOR_ORDER)
58 #define YADAPTCOEFFSA 18
59 #define XADAPTCOEFFSA 14
60 #define YADAPTCOEFFSB 10
61 #define XADAPTCOEFFSB 5
76 #define APE_FILTER_LEVELS 3
241 "%d bits per coded sample", s->
bps);
312 #define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1))
313 #define SHIFT_BITS (CODE_BITS - 9)
314 #define EXTRA_BITS ((CODE_BITS-2) % 8 + 1)
315 #define BOTTOM_VALUE (TOP_VALUE >> 8)
388 #define MODEL_ELEMENTS 64
394 0, 14824, 28224, 39348, 47855, 53994, 58171, 60926,
395 62682, 63786, 64463, 64878, 65126, 65276, 65365, 65419,
396 65450, 65469, 65480, 65487, 65491, 65493,
403 14824, 13400, 11124, 8507, 6139, 4177, 2755, 1756,
404 1104, 677, 415, 248, 150, 89, 54, 31,
412 0, 19578, 36160, 48417, 56323, 60899, 63265, 64435,
413 64971, 65232, 65351, 65416, 65447, 65466, 65476, 65482,
414 65485, 65488, 65490, 65491, 65492, 65493,
421 19578, 16582, 12257, 7906, 4576, 2366, 1170, 536,
422 261, 119, 65, 31, 19, 10, 6, 3,
433 const uint16_t counts[],
434 const uint16_t counts_diff[])
441 symbol= cf - 65535 + 63;
448 for (symbol = 0; counts[symbol + 1] <= cf; symbol++);
458 int lim = rice->
k ? (1 << (rice->
k + 4)) : 0;
459 rice->
ksum += ((x + 1) / 2) - ((rice->
ksum + 16) >> 5);
461 if (rice->
ksum < lim)
463 else if (rice->
ksum >= (1 << (rice->
k + 5)))
482 unsigned int x, overflow;
487 while (overflow >= 16) {
496 x = (overflow << rice->
k) +
get_bits(gb, rice->
k);
501 rice->
ksum += x - (rice->
ksum + 8 >> 4);
502 if (rice->
ksum < (rice->
k ? 1 << (rice->
k + 4) : 0))
504 else if (rice->
ksum >= (1 << (rice->
k + 5)) && rice->
k < 24)
508 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
513 unsigned int x, overflow;
522 tmpk = (rice->
k < 1) ? 0 : rice->
k - 1;
530 }
else if (tmpk <= 31) {
537 x += overflow << tmpk;
542 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
547 unsigned int x, overflow;
550 pivot = rice->
ksum >> 5;
561 if (pivot < 0x10000) {
565 int base_hi = pivot, base_lo;
568 while (base_hi & ~0xFFFF) {
577 base = (base_hi << bbits) + base_lo;
580 x = base + overflow * pivot;
585 return ((x >> 1) ^ ((x & 1) - 1)) + 1;
592 int ksummax, ksummin;
595 for (i = 0; i <
FFMIN(blockstodecode, 5); i++) {
597 rice->
ksum += out[i];
602 for (; i <
FFMIN(blockstodecode, 64); i++) {
604 rice->
ksum += out[i];
609 ksummax = 1 << rice->
k + 7;
610 ksummin = rice->
k ? (1 << rice->
k + 6) : 0;
611 for (; i < blockstodecode; i++) {
613 rice->
ksum += out[i] - out[i - 64];
614 while (rice->
ksum < ksummin) {
616 ksummin = rice->
k ? ksummin >> 1 : 0;
619 while (rice->
ksum >= ksummax) {
624 ksummin = ksummin ? ksummin << 1 : 128;
628 for (i = 0; i < blockstodecode; i++)
629 out[i] = ((out[i] >> 1) ^ ((out[i] & 1) - 1)) + 1;
650 while (blockstodecode--)
658 int blocks = blockstodecode;
660 while (blockstodecode--)
670 while (blockstodecode--)
678 int blocks = blockstodecode;
680 while (blockstodecode--)
695 while (blockstodecode--) {
705 while (blockstodecode--)
714 while (blockstodecode--) {
726 ctx->
CRC = bytestream_get_be32(&ctx->
ptr);
734 ctx->
CRC &= ~0x80000000;
815 return (x < 0) - (x > 0);
831 predictionA = p->
buf[delayA] * 2 - p->
buf[delayA - 1];
834 if ((decoded ^ predictionA) > 0)
846 const int delayA,
const int delayB,
849 int32_t predictionA, predictionB, sign;
862 d1 = (p->
buf[delayA] - p->
buf[delayA - 1]) << 1;
863 d0 = p->
buf[delayA] + ((p->
buf[delayA - 2] - p->
buf[delayA - 1]) << 3);
864 d3 = p->
buf[delayB] * 2 - p->
buf[delayB - 1];
898 memset(coeffs, 0, order *
sizeof(*coeffs));
899 for (i = 0; i < order; i++)
900 delay[i] = buffer[i];
901 for (i = order; i <
length; i++) {
904 for (j = 0; j < order; j++) {
905 dotprod += delay[j] * coeffs[j];
906 coeffs[j] += ((delay[j] >> 31) | 1) * sign;
908 buffer[i] -= dotprod >>
shift;
909 for (j = 0; j < order - 1; j++)
910 delay[j] = delay[j + 1];
911 delay[order - 1] = buffer[i];
921 for (i = 0; i <
length; i++) {
924 for (j = 7; j >= 0; j--) {
925 dotprod += delay[j] * coeffs[j];
926 coeffs[j] += ((delay[j] >> 31) | 1) * sign;
928 for (j = 7; j > 0; j--)
929 delay[j] = delay[j - 1];
930 delay[0] = buffer[i];
931 buffer[i] -= dotprod >> 9;
947 int order = 128,
shift2 = 11;
962 int X = *decoded0,
Y = *decoded1;
1000 int order = 128,
shift2 = 11;
1043 d0 = p->
buf[delayA ];
1044 d1 = p->
buf[delayA ] - p->
buf[delayA - 1];
1045 d2 = p->
buf[delayA - 1] - p->
buf[delayA - 2];
1046 d3 = p->
buf[delayA - 2] - p->
buf[delayA - 3];
1075 int Y = *decoded1, X = *decoded0;
1117 const int delayA,
const int delayB,
1118 const int adaptA,
const int adaptB)
1120 int32_t predictionA, predictionB, sign;
1124 p->
buf[delayA - 1] = p->
buf[delayA] - p->
buf[delayA - 1];
1135 p->
buf[delayB - 1] = p->
buf[delayB] - p->
buf[delayB - 1];
1145 p->
lastA[
filter] = decoded + ((predictionA + (predictionB >> 1)) >> 10);
1195 int32_t predictionA, currentA,
A, sign;
1199 currentA = p->
lastA[0];
1212 currentA = A + (predictionA >> 10);
1233 *(decoded0++) = p->
filterA[0];
1236 p->
lastA[0] = currentA;
1269 res = (res + (1 << (fracbits - 1))) >> fracbits;
1274 *f->
delay++ = av_clip_int16(res);
1276 if (version < 3980) {
1278 f->
adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4;
1285 absres =
FFABS(res);
1288 (8 << ((absres > f->
avg * 3) + (absres > f->
avg * 4 / 3)));
1300 f->
avg += (absres - f->
avg) / 16;
1321 int count,
int order,
int fracbits)
1396 left = *decoded1 - (*decoded0 / 2);
1397 right = left + *decoded0;
1399 *(decoded0++) = left;
1400 *(decoded1++) = right;
1405 int *got_frame_ptr,
AVPacket *avpkt)
1415 uint64_t decoded_buffer_size;
1422 uint32_t nblocks,
offset;
1429 if (avpkt->
size < 8) {
1433 buf_size = avpkt->
size & ~3;
1434 if (buf_size != avpkt->
size) {
1436 "extra bytes at the end will be skipped.\n");
1445 memset(s->
data + (buf_size & ~3), 0, buf_size & 3);
1449 nblocks = bytestream_get_be32(&s->
ptr);
1450 offset = bytestream_get_be32(&s->
ptr);
1471 if (!nblocks || nblocks > INT_MAX / 2 /
sizeof(*s->
decoded_buffer) - 8) {
1527 for (ch = 0; ch < s->
channels; ch++) {
1529 for (i = 0; i < blockstodecode; i++)
1530 *sample8++ = (s->
decoded[ch][i] + 0x80) & 0xff;
1534 for (ch = 0; ch < s->
channels; ch++) {
1535 sample16 = (int16_t *)frame->
data[ch];
1536 for (i = 0; i < blockstodecode; i++)
1537 *sample16++ = s->
decoded[ch][i];
1541 for (ch = 0; ch < s->
channels; ch++) {
1543 for (i = 0; i < blockstodecode; i++)
1544 *sample24++ = s->
decoded[ch][i] << 8;
1562 #define OFFSET(x) offsetof(APEContext, x)
1563 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1566 {
"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" },
static int init_frame_decoder(APEContext *ctx)
static const int32_t initial_coeffs_3930[4]
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
static void decode_array_0000(APEContext *ctx, GetBitContext *gb, int32_t *out, APERice *rice, int blockstodecode)
int compression_level
compression levels
static av_always_inline int filter_3800(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int start, const int shift)
int32_t coeffsB[2][5]
adaption coefficients
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
static void range_start_decoding(APEContext *ctx)
Start the decoder.
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
static void apply_filter(APEContext *ctx, APEFilter *f, int32_t *data0, int32_t *data1, int count, int order, int fracbits)
int fileversion
codec version, very important in decoding process
static void entropy_decode_stereo_0000(APEContext *ctx, int blockstodecode)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static av_cold int init(AVCodecContext *avctx)
static int APESIGN(int32_t x)
Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero)
static void update_rice(APERice *rice, unsigned int x)
static void entropy_decode_stereo_3900(APEContext *ctx, int blockstodecode)
const char * av_default_item_name(void *ptr)
Return the context name.
static av_cold int ape_decode_init(AVCodecContext *avctx)
unsigned int buffer
buffer for input/output
static void long_filter_high_3800(int32_t *buffer, int order, int shift, int length)
static int init_entropy_decoder(APEContext *ctx)
static void ape_flush(AVCodecContext *avctx)
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...
static void entropy_decode_stereo_3930(APEContext *ctx, int blockstodecode)
static av_always_inline int predictor_update_3930(APEPredictor *p, const int decoded, const int filter, const int delayA)
#define AV_CH_LAYOUT_STEREO
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int16_t * filterbuf[APE_FILTER_LEVELS]
filter memory
static void predictor_decode_mono_3800(APEContext *ctx, int count)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#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_assert0(cond)
assert() equivalent, that is always enabled.
static int ape_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
enum AVSampleFormat sample_fmt
audio sample format
int16_t * delay
filtered values
static void do_init_filter(APEFilter *f, int16_t *buf, int order)
static const int32_t initial_coeffs_a_3800[3]
static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode)
static void entropy_decode_mono_3990(APEContext *ctx, int blockstodecode)
static void ape_unpack_mono(APEContext *ctx, int count)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
APERangecoder rc
rangecoder used to decode actual values
static const uint8_t ape_filter_fracbits[5][APE_FILTER_LEVELS]
Filter fraction bits depending on compression level.
static void ape_apply_filters(APEContext *ctx, int32_t *decoded0, int32_t *decoded1, int count)
bitstream reader API header.
#define AV_LOG_VERBOSE
Detailed information.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
void(* entropy_decode_stereo)(struct APEContext *ctx, int blockstodecode)
static const uint16_t counts_3970[22]
Fixed probabilities for symbols in Monkey Audio version 3.97.
static void range_dec_normalize(APEContext *ctx)
Perform normalization.
static int get_bits_left(GetBitContext *gb)
static const uint16_t counts_diff_3980[21]
Probability ranges for symbols in Monkey Audio version 3.98.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int ape_decode_close(AVCodecContext *avctx)
static int ape_decode_value_3900(APEContext *ctx, APERice *rice)
int32_t historybuffer[HISTORY_SIZE+PREDICTOR_SIZE]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
static int range_decode_culshift(APEContext *ctx, int shift)
Decode value with given size in bits.
#define APE_FILTER_LEVELS
static const uint8_t offset[127][2]
uint64_t channel_layout
Audio channel layout.
static int range_decode_bits(APEContext *ctx, int n)
Decode n bits (n <= 16) without modelling.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
audio channel layout utility functions
static void predictor_decode_mono_3930(APEContext *ctx, int count)
uint8_t * data
current frame data
static const uint16_t ape_filter_orders[5][APE_FILTER_LEVELS]
Filter orders depending on compression level.
static int get_rice_ook(GetBitContext *gb, int k)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static av_always_inline int filter_fast_3320(APEPredictor *p, const int decoded, const int filter, const int delayA)
static void ape_unpack_stereo(APEContext *ctx, int count)
const uint8_t * ptr
current position in frame data
static int range_decode_culfreq(APEContext *ctx, int tot_f)
Calculate cumulative frequency for next symbol.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void predictor_decode_stereo_3930(APEContext *ctx, int count)
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
uint32_t help
bytes_to_follow resp. intermediate value
static void entropy_decode_stereo_3990(APEContext *ctx, int blockstodecode)
#define APE_FRAMECODE_PSEUDO_STEREO
uint32_t range
length of interval
int samples
samples left to decode in current frame
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int fset
which filter set to use (calculated from compression level)
static int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb, APERice *rice)
APERice riceX
rice code parameters for the second channel
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
static void predictor_decode_stereo_3950(APEContext *ctx, int count)
static void predictor_decode_stereo_3800(APEContext *ctx, int count)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define APE_FRAMECODE_STEREO_SILENCE
static void init_filter(APEContext *ctx, APEFilter *f, int16_t *buf, int order)
int frameflags
frame flags
main external API structure.
static int ape_decode_value_3990(APEContext *ctx, APERice *rice)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static const uint16_t counts_3980[22]
Fixed probabilities for symbols in Monkey Audio version 3.98.
static int range_get_symbol(APEContext *ctx, const uint16_t counts[], const uint16_t counts_diff[])
Decode symbol.
Describe the class of an AVClass context structure.
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
uint32_t low
low end of interval
int32_t(* scalarproduct_and_madd_int16)(int16_t *v1, const int16_t *v2, const int16_t *v3, int len, int mul)
Calculate scalar product of v1 and v2, and v1[i] += v3[i] * mul.
int flags
global decoder flags
void(* predictor_decode_mono)(struct APEContext *ctx, int count)
APECompressionLevel
Possible compression levels.
int32_t coeffsA[2][4]
adaption coefficients
static void range_decode_update(APEContext *ctx, int sy_f, int lt_f)
Update decoding state.
static void entropy_decode_mono_3900(APEContext *ctx, int blockstodecode)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static const int32_t initial_coeffs_fast_3320[1]
static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define PREDICTOR_SIZE
Total size of all predictor histories.
void(* predictor_decode_stereo)(struct APEContext *ctx, int count)
static const uint16_t counts_diff_3970[21]
Probability ranges for symbols in Monkey Audio version 3.97.
int blocks_per_loop
maximum number of samples to decode for each call
uint8_t * data_end
frame data end
common internal api header.
APERice riceY
rice code parameters for the first channel
static const int shift2[6]
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
APEFilter filters[APE_FILTER_LEVELS][2]
filters used for reconstruction
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)
int16_t * coeffs
actual coefficients used in filtering
static void init_predictor_decoder(APEContext *ctx)
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
static const int32_t initial_coeffs_b_3800[2]
APEPredictor predictor
predictor used for final reconstruction
static const AVClass ape_decoder_class
static const int16_t coeffs[]
void(* entropy_decode_mono)(struct APEContext *ctx, int blockstodecode)
int channels
number of audio channels
static void long_filter_ehigh_3830(int32_t *buffer, int length)
static void predictor_decode_mono_3950(APEContext *ctx, int count)
Filters applied to the decoded data.
static enum AVSampleFormat sample_fmts[]
int32_t * decoded[MAX_CHANNELS]
decoded data for each channel
int data_size
frame data allocated size
static const AVOption options[]
#define AV_CH_LAYOUT_MONO
int16_t * adaptcoeffs
adaptive filter coefficients used for correcting of actual filter coefficients
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static void entropy_decode_mono_0000(APEContext *ctx, int blockstodecode)
int16_t * historybuffer
filter memory
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
static void entropy_decode_mono_3860(APEContext *ctx, int blockstodecode)