10#include "config-adpcm.h"
14#define av_assert(X) assert(X)
16#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
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
33#define av_log(A, B, ...) printf(__VA_ARGS__);
35#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
37#define AV_NUM_DATA_POINTERS 8
45 AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
46 AV_CODEC_ID_ADPCM_IMA_WAV,
47 AV_CODEC_ID_ADPCM_IMA_DK3,
48 AV_CODEC_ID_ADPCM_IMA_DK4,
49 AV_CODEC_ID_ADPCM_IMA_WS,
50 AV_CODEC_ID_ADPCM_IMA_SMJPEG,
52 AV_CODEC_ID_ADPCM_4XM,
56 AV_CODEC_ID_ADPCM_SWF,
57 AV_CODEC_ID_ADPCM_YAMAHA,
58 AV_CODEC_ID_ADPCM_SBPRO_4,
59 AV_CODEC_ID_ADPCM_SBPRO_3,
60 AV_CODEC_ID_ADPCM_SBPRO_2,
61 AV_CODEC_ID_ADPCM_THP,
62 AV_CODEC_ID_ADPCM_IMA_AMV,
63 AV_CODEC_ID_ADPCM_EA_R1,
64 AV_CODEC_ID_ADPCM_EA_R3,
65 AV_CODEC_ID_ADPCM_EA_R2,
66 AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
67 AV_CODEC_ID_ADPCM_IMA_EA_EACS,
68 AV_CODEC_ID_ADPCM_EA_XAS,
69 AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
70 AV_CODEC_ID_ADPCM_IMA_ISS,
71 AV_CODEC_ID_ADPCM_G722,
72 AV_CODEC_ID_ADPCM_IMA_APC,
73 AV_CODEC_ID_ADPCM_AFC,
74 AV_CODEC_ID_ADPCM_IMA_OKI,
75 AV_CODEC_ID_ADPCM_DTK,
76 AV_CODEC_ID_ADPCM_IMA_RAD,
77 AV_CODEC_ID_ADPCM_THP_LE,
78 AV_CODEC_ID_ADPCM_PSX,
79 AV_CODEC_ID_ADPCM_AICA,
80 AV_CODEC_ID_ADPCM_IMA_DAT4,
81 AV_CODEC_ID_ADPCM_MTAF,
82 AV_CODEC_ID_ADPCM_AGM,
83 AV_CODEC_ID_ADPCM_ARGO,
84 AV_CODEC_ID_ADPCM_IMA_SSI,
85 AV_CODEC_ID_ADPCM_ZORK,
86 AV_CODEC_ID_ADPCM_IMA_APM,
87 AV_CODEC_ID_ADPCM_IMA_ALP,
88 AV_CODEC_ID_ADPCM_IMA_MTF,
89 AV_CODEC_ID_ADPCM_IMA_CUNNING,
90 AV_CODEC_ID_ADPCM_IMA_MOFLEX,
91 AV_CODEC_ID_ADPCM_IMA_ACORN,
92 AV_CODEC_ID_ADPCM_XMD,
95namespace adpcm_ffmpeg {
100 AVERROR_PATCHWELCOME,
143 uint8_t *
data[AV_NUM_DATA_POINTERS];
208 uint8_t *trellis_hash;
225 enum AVCodecID codec_id;
229 int bits_per_coded_sample;
240static const uint8_t ff_adpcm_ima_block_sizes[4] = {4, 12, 4, 20};
241static const uint8_t ff_adpcm_ima_block_samples[4] = {16, 32, 8, 32};
245static const int8_t ff_adpcm_index_table[16] = {
246 -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8,
253static const int16_t ff_adpcm_step_table[89] = {
254 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
255 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
256 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
257 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
258 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
259 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
260 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
261 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
262 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767};
267static const int16_t ff_adpcm_AdaptationTable[] = {230, 230, 230, 230, 307, 409,
268 512, 614, 768, 614, 512, 409,
272static const uint8_t ff_adpcm_AdaptCoeff1[] = {64, 128, 0, 48, 60, 115, 98};
275static const int8_t ff_adpcm_AdaptCoeff2[] = {0, -64, 0, 16, 0, -52, -58};
277static const int16_t ff_adpcm_yamaha_indexscale[] = {
278 230, 230, 230, 230, 307, 409, 512, 614,
279 230, 230, 230, 230, 307, 409, 512, 614};
281static const int8_t ff_adpcm_yamaha_difflookup[] = {
282 1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15};
285static const int8_t xa_adpcm_table[5][2] = {
286 {0, 0}, {60, 0}, {115, -52}, {98, -55}, {122, -60}};
288static const int16_t afc_coeffs[2][16] = {
289 {0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024,
290 -1024, -1024, -2048},
291 {0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048,
294static const int16_t ea_adpcm_table[] = {0, 240, 460, 392, 0, 0, -208,
295 -220, 0, 1, 3, 4, 7, 8,
296 10, 11, 0, -1, -3, -4};
304static const int8_t ima_cunning_index_table[9] = {-1, -1, -1, -1, 1,
313static const int16_t ima_cunning_step_table[61] = {
314 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6,
315 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40,
316 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256,
317 320, 384, 448, 512, 640, 768, 896, 1024, 1280, 1536, 1792,
318 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 10240, 12288,
319 14336, 16384, 20480, 24576, 28672, 0};
321static const int8_t adpcm_index_table2[4] = {
328static const int8_t adpcm_index_table3[8] = {
329 -1, -1, 1, 2, -1, -1, 1, 2,
332static const int8_t adpcm_index_table5[32] = {
333 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
334 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
337static const int8_t *
const adpcm_index_tables[4] = {
338 &adpcm_index_table2[0],
339 &adpcm_index_table3[0],
340 &ff_adpcm_index_table[0],
341 &adpcm_index_table5[0],
344static const int16_t mtaf_stepsize[32][16] = {
923static const int16_t oki_step_table[49] = {
924 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50,
925 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173,
926 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598,
927 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552};
930static const int8_t swf_index_tables[4][16] = {
933 {-1, -1, -1, -1, 2, 4, 6, 8},
934 {-1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16}};
936static const int8_t zork_index_table[8] = {
937 -1, -1, -1, 1, 4, 7, 10, 12,
940static const int8_t mtf_index_table[16] = {
941 8, 6, 4, 2, -1, -1, -1, -1, -1, -1, -1, -1, 2, 4, 6, 8,
946inline int av_clip(
int a,
int amin,
int amax) {
949 assert(amin <= amax);
963inline bool allocArray(T *&ptr,
size_t n) {
965 return ptr !=
nullptr;
970inline void freeArray(T *&ptr) {
981inline int16_t av_clip_int16(
int a) {
982 if ((a + 0x8000U) & ~0xFFFF)
983 return (a >> 31) ^ 0x7FFF;
994inline int av_clip_intp2(
int a,
int p) {
995 if (((
unsigned)a + (1 << p)) & ~((2 << p) - 1))
996 return (a >> 31) ^ ((1 << p) - 1);
1007inline unsigned av_clip_uintp2(
int a,
int p) {
1008 if (a & ~((1 << p) - 1))
1009 return (~a) >> 31 & ((1 << p) - 1);
1021inline unsigned av_mod_uintp2(
unsigned a,
unsigned p) {
1022 return a & ((1U << p) - 1);
1026inline int sign_extend(
int val,
unsigned bits) {
1027 unsigned shift = 8 *
sizeof(int) - bits;
1031 } v = {(unsigned)val << shift};
1032 return v.s >> shift;
int vqa_version
Definition adpcm.h:236
int has_status
Definition adpcm.h:237
C API context for encoder and decoder.
Definition adpcm.h:215
int frame_size
Number of samples per channel in an audio frame.
Definition adpcm.h:218
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition adpcm.h:221
This structure provides the uncompressed PCM data.
Definition adpcm.h:130
int16_t ** extended_data
Definition adpcm.h:164
int nb_samples
Definition adpcm.h:148
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition adpcm.h:143
This structure stores compressed data. It is typically exported by demuxers and then passed as input ...
Definition adpcm.h:122