9 #include "config-adpcm.h"
13 #define av_assert(X) assert(X)
15 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
16 #define FFSIGN(a) ((a) > 0 ? 1 : -1)
17 #define FFMAX(a, b) ((a) > (b) ? (a) : (b))
18 #define FFMIN(a, b) ((a) > (b) ? (b) : (a))
19 #define FFSWAP(type, a, b) \
25 #define FFALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
30 #define AV_LOG_ERROR 16
31 #define AV_LOG_WARNING 24
32 #define AV_LOG_INFO 32
34 #define av_log(A, B, ...) printf(__VA_ARGS__);
36 #define FF_ALLOC_TYPED_ARRAY(T, p, nelem) (p = (T) av_malloc_array(nelem, sizeof(*p)))
37 #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
39 #define AV_NUM_DATA_POINTERS 8
47 AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
48 AV_CODEC_ID_ADPCM_IMA_WAV,
49 AV_CODEC_ID_ADPCM_IMA_DK3,
50 AV_CODEC_ID_ADPCM_IMA_DK4,
51 AV_CODEC_ID_ADPCM_IMA_WS,
52 AV_CODEC_ID_ADPCM_IMA_SMJPEG,
54 AV_CODEC_ID_ADPCM_4XM,
56 AV_CODEC_ID_ADPCM_ADX,
58 AV_CODEC_ID_ADPCM_G726,
60 AV_CODEC_ID_ADPCM_SWF,
61 AV_CODEC_ID_ADPCM_YAMAHA,
62 AV_CODEC_ID_ADPCM_SBPRO_4,
63 AV_CODEC_ID_ADPCM_SBPRO_3,
64 AV_CODEC_ID_ADPCM_SBPRO_2,
65 AV_CODEC_ID_ADPCM_THP,
66 AV_CODEC_ID_ADPCM_IMA_AMV,
67 AV_CODEC_ID_ADPCM_EA_R1,
68 AV_CODEC_ID_ADPCM_EA_R3,
69 AV_CODEC_ID_ADPCM_EA_R2,
70 AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
71 AV_CODEC_ID_ADPCM_IMA_EA_EACS,
72 AV_CODEC_ID_ADPCM_EA_XAS,
73 AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
74 AV_CODEC_ID_ADPCM_IMA_ISS,
75 AV_CODEC_ID_ADPCM_G722,
76 AV_CODEC_ID_ADPCM_IMA_APC,
77 AV_CODEC_ID_ADPCM_VIMA,
78 AV_CODEC_ID_ADPCM_AFC,
79 AV_CODEC_ID_ADPCM_IMA_OKI,
80 AV_CODEC_ID_ADPCM_DTK,
81 AV_CODEC_ID_ADPCM_IMA_RAD,
82 AV_CODEC_ID_ADPCM_G726LE,
83 AV_CODEC_ID_ADPCM_THP_LE,
84 AV_CODEC_ID_ADPCM_PSX,
85 AV_CODEC_ID_ADPCM_AICA,
86 AV_CODEC_ID_ADPCM_IMA_DAT4,
87 AV_CODEC_ID_ADPCM_MTAF,
88 AV_CODEC_ID_ADPCM_AGM,
89 AV_CODEC_ID_ADPCM_ARGO,
90 AV_CODEC_ID_ADPCM_IMA_SSI,
91 AV_CODEC_ID_ADPCM_ZORK,
92 AV_CODEC_ID_ADPCM_IMA_APM,
93 AV_CODEC_ID_ADPCM_IMA_ALP,
94 AV_CODEC_ID_ADPCM_IMA_MTF,
95 AV_CODEC_ID_ADPCM_IMA_CUNNING,
96 AV_CODEC_ID_ADPCM_IMA_MOFLEX,
97 AV_CODEC_ID_ADPCM_IMA_ACORN,
98 AV_CODEC_ID_ADPCM_XMD,
101 namespace adpcm_ffmpeg {
106 AVERROR_PATCHWELCOME,
112 enum AVChannelLayout {
113 AV_CHANNEL_LAYOUT_MONO,
114 AV_CHANNEL_LAYOUT_STEREO,
117 enum AVSampleFormat {
118 AV_SAMPLE_FMT_NONE = -1,
164 uint8_t *
data[AV_NUM_DATA_POINTERS];
229 uint8_t *trellis_hash;
246 enum AVCodecID codec_id;
250 int bits_per_coded_sample;
261 static const uint8_t ff_adpcm_ima_block_sizes[4] = {4, 12, 4, 20};
262 static const uint8_t ff_adpcm_ima_block_samples[4] = {16, 32, 8, 32};
266 static const int8_t ff_adpcm_index_table[16] = {
267 -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8,
274 static const int16_t ff_adpcm_step_table[89] = {
275 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
276 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
277 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
278 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
279 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
280 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
281 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
282 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
283 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767};
288 static const int16_t ff_adpcm_AdaptationTable[] = {230, 230, 230, 230, 307, 409,
289 512, 614, 768, 614, 512, 409,
293 static const uint8_t ff_adpcm_AdaptCoeff1[] = {64, 128, 0, 48, 60, 115, 98};
296 static const int8_t ff_adpcm_AdaptCoeff2[] = {0, -64, 0, 16, 0, -52, -58};
298 static const int16_t ff_adpcm_yamaha_indexscale[] = {
299 230, 230, 230, 230, 307, 409, 512, 614,
300 230, 230, 230, 230, 307, 409, 512, 614};
302 static const int8_t ff_adpcm_yamaha_difflookup[] = {
303 1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15};
306 static const int8_t xa_adpcm_table[5][2] = {
307 {0, 0}, {60, 0}, {115, -52}, {98, -55}, {122, -60}};
309 static const int16_t afc_coeffs[2][16] = {
310 {0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024,
311 -1024, -1024, -2048},
312 {0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048,
315 static const int16_t ea_adpcm_table[] = {0, 240, 460, 392, 0, 0, -208,
316 -220, 0, 1, 3, 4, 7, 8,
317 10, 11, 0, -1, -3, -4};
325 static const int8_t ima_cunning_index_table[9] = {-1, -1, -1, -1, 1,
334 static const int16_t ima_cunning_step_table[61] = {
335 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6,
336 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40,
337 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256,
338 320, 384, 448, 512, 640, 768, 896, 1024, 1280, 1536, 1792,
339 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 10240, 12288,
340 14336, 16384, 20480, 24576, 28672, 0};
342 static const int8_t adpcm_index_table2[4] = {
349 static const int8_t adpcm_index_table3[8] = {
350 -1, -1, 1, 2, -1, -1, 1, 2,
353 static const int8_t adpcm_index_table5[32] = {
354 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
355 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
358 static const int8_t *
const adpcm_index_tables[4] = {
359 &adpcm_index_table2[0],
360 &adpcm_index_table3[0],
361 &ff_adpcm_index_table[0],
362 &adpcm_index_table5[0],
365 static const int16_t mtaf_stepsize[32][16] = {
944 static const int16_t oki_step_table[49] = {
945 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50,
946 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173,
947 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598,
948 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552};
951 static const int8_t swf_index_tables[4][16] = {
954 {-1, -1, -1, -1, 2, 4, 6, 8},
955 {-1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16}};
957 static const int8_t zork_index_table[8] = {
958 -1, -1, -1, 1, 4, 7, 10, 12,
961 static const int8_t mtf_index_table[16] = {
962 8, 6, 4, 2, -1, -1, -1, -1, -1, -1, -1, -1, 2, 4, 6, 8,
967 av_always_inline av_const
int av_clip(
int a,
int amin,
int amax) {
970 assert(amin <= amax);
980 void *av_malloc(
size_t size) {
return malloc(size); }
982 void av_free(
void *ptr) {
983 #if HAVE_ALIGNED_MALLOC
990 void av_freep(
void *arg) {
993 memcpy(&val, arg,
sizeof(val));
994 static void *
const temp = NULL;
995 memcpy(arg, &temp,
sizeof(val));
999 void *av_mallocz(
size_t size) {
1000 void *ptr = av_malloc(size);
1001 if (ptr) memset(ptr, 0, size);
1005 int size_mult(
size_t a,
size_t b,
size_t *r) {
1011 if ((a | b) >= ((
size_t)1 << (
sizeof(
size_t) * 4)) && a && t / a != b)
1012 return AVERROR(AVERROR_INVALID);
1017 void *av_calloc(
size_t nmemb,
size_t size) {
1019 if (size_mult(nmemb, size, &result) < 0)
return NULL;
1020 return av_mallocz(result);
1023 void *av_malloc_array(
size_t nmemb,
size_t size) {
1025 if (size_mult(nmemb, size, &result) < 0)
return NULL;
1026 return av_malloc(result);
1034 av_always_inline av_const uint16_t av_clip_uint16(
int a) {
1046 av_always_inline av_const int16_t av_clip_int16(
int a) {
1047 if ((a + 0x8000U) & ~0xFFFF)
1048 return (a >> 31) ^ 0x7FFF;
1059 av_always_inline av_const
int av_clip_intp2(
int a,
int p) {
1060 if (((
unsigned)a + (1 << p)) & ~((2 << p) - 1))
1061 return (a >> 31) ^ ((1 << p) - 1);
1072 av_always_inline av_const
unsigned av_clip_uintp2(
int a,
int p) {
1073 if (a & ~((1 << p) - 1))
1074 return (~a) >> 31 & ((1 << p) - 1);
1086 av_always_inline av_const
unsigned av_mod_uintp2(
unsigned a,
unsigned p) {
1087 return a & ((1U << p) - 1);
1091 inline av_const
int sign_extend(
int val,
unsigned bits) {
1092 unsigned shift = 8 *
sizeof(int) - bits;
1096 } v = {(unsigned)val << shift};
1097 return v.s >> shift;
1101 #ifndef sign_extend64
1102 inline av_const int64_t sign_extend64(int64_t val,
unsigned bits) {
1103 unsigned shift = 8 *
sizeof(int64_t) - bits;
1107 } v = {(uint64_t)val << shift};
1108 return v.s >> shift;
1113 inline av_const
unsigned zero_extend(
unsigned val,
unsigned bits) {
1114 return (val << ((8 *
sizeof(
int)) - bits)) >> ((8 *
sizeof(int)) - bits);
1118 inline uint32_t NEG_USR32(uint32_t a, int8_t s) {
1119 __asm__(
"shrl %1, %0\n\t" :
"+r"(a) :
"ic"((uint8_t)(-s)));
int vqa_version
Definition: adpcm.h:257
int has_status
Definition: adpcm.h:258
C API context for encoder and decoder.
Definition: adpcm.h:236
int frame_size
Number of samples per channel in an audio frame.
Definition: adpcm.h:239
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: adpcm.h:242
This structure provides the uncompressed PCM data.
Definition: adpcm.h:151
int16_t ** extended_data
Definition: adpcm.h:185
int nb_samples
Definition: adpcm.h:169
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: adpcm.h:164
This structure stores compressed data. It is typically exported by demuxers and then passed as input ...
Definition: adpcm.h:143