ADPCM Codecs
adpcm.h
1 #pragma once
2 
3 #include <assert.h>
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <climits>
9 #include "config-adpcm.h"
10 
11 // define some qulifiers used by the code base
12 
13 #define av_assert(X) assert(X)
14 
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) \
20  do { \
21  type SWAP_tmp = b; \
22  b = a; \
23  a = SWAP_tmp; \
24  } while (0)
25 #define FFALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
26 
27 #define AVERROR(X) X
28 
29 // Some define used by logging
30 #define AV_LOG_ERROR 16
31 #define AV_LOG_WARNING 24
32 #define AV_LOG_INFO 32
33 
34 #define av_log(A, B, ...) printf(__VA_ARGS__);
35 
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]))
38 
39 #define AV_NUM_DATA_POINTERS 8
40 
45 enum AVCodecID {
46  /* various ADPCM codecs */
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,
53  AV_CODEC_ID_ADPCM_MS,
54  AV_CODEC_ID_ADPCM_4XM,
55  AV_CODEC_ID_ADPCM_XA,
56  AV_CODEC_ID_ADPCM_ADX,
57  AV_CODEC_ID_ADPCM_EA,
58  AV_CODEC_ID_ADPCM_G726,
59  AV_CODEC_ID_ADPCM_CT,
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,
99 };
100 
101 namespace adpcm_ffmpeg {
102 
103 enum av_errors {
104  AV_OK = 0,
105  AVERROR_INVALIDDATA,
106  AVERROR_PATCHWELCOME,
107  AVERROR_INVALID,
108  AVERROR_MEMORY,
109 };
110 
111 
112 enum AVChannelLayout {
113  AV_CHANNEL_LAYOUT_MONO,
114  AV_CHANNEL_LAYOUT_STEREO,
115 };
116 
117 enum AVSampleFormat {
118  AV_SAMPLE_FMT_NONE = -1,
119  AV_SAMPLE_FMT_U8,
120  AV_SAMPLE_FMT_S16,
121  AV_SAMPLE_FMT_S32,
122  AV_SAMPLE_FMT_FLT,
123  AV_SAMPLE_FMT_DBL,
124 
125  AV_SAMPLE_FMT_U8P,
126  AV_SAMPLE_FMT_S16P,
127  AV_SAMPLE_FMT_S32P,
128  AV_SAMPLE_FMT_FLTP,
129  AV_SAMPLE_FMT_DBLP,
130  AV_SAMPLE_FMT_S64,
131  AV_SAMPLE_FMT_S64P,
132 
133  AV_SAMPLE_FMT_NB
135 };
136 
143 struct AVPacket {
144  uint8_t *data;
145  int size;
146 };
147 
151 struct AVFrame {
164  uint8_t *data[AV_NUM_DATA_POINTERS];
185  int16_t **extended_data;
186 };
187 
188 struct TrellisPath {
189  int nibble;
190  int prev;
191 };
192 
193 struct TrellisNode {
194  uint32_t ssd;
195  int path;
196  int sample1;
197  int sample2;
198  int step;
199 };
200 
207  int predictor;
208  int16_t step_index;
209  int step;
210  /* for encoding */
211  int prev_sample;
212 
213  /* MS version */
214  int sample1;
215  int sample2;
216  int coeff1;
217  int coeff2;
218  int idelta;
219 };
220 
222  // AVClass *class;
223  int block_size;
224 
225  ADPCMChannelStatus status[6];
226  TrellisPath *paths;
227  TrellisNode *node_buf;
228  TrellisNode **nodep_buf;
229  uint8_t *trellis_hash;
230 };
231 
237  int trellis;
243  uint8_t *extradata;
244  int extradata_size;
245  // Codec *codec;
246  enum AVCodecID codec_id;
247  void *priv_data;
248  int nb_channels;
249  // bits per sample/pixel from the demuxer
250  int bits_per_coded_sample;
251  int sample_rate;
252  int sample_fmt;
253 };
254 
256  ADPCMChannelStatus status[14];
259 };
260 
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};
263 
264 /* ff_adpcm_step_table[] and ff_adpcm_index_table[] are from the ADPCM
265  reference source */
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,
268 };
269 
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};
284 
285 /* These are for MS-ADPCM */
286 /* ff_adpcm_AdaptationTable[], ff_adpcm_AdaptCoeff1[], and
287  ff_adpcm_AdaptCoeff2[] are from libsndfile */
288 static const int16_t ff_adpcm_AdaptationTable[] = {230, 230, 230, 230, 307, 409,
289  512, 614, 768, 614, 512, 409,
290  307, 230, 230, 230};
291 
293 static const uint8_t ff_adpcm_AdaptCoeff1[] = {64, 128, 0, 48, 60, 115, 98};
294 
296 static const int8_t ff_adpcm_AdaptCoeff2[] = {0, -64, 0, 16, 0, -52, -58};
297 
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};
301 
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};
304 
305 /* These are for CD-ROM XA ADPCM */
306 static const int8_t xa_adpcm_table[5][2] = {
307  {0, 0}, {60, 0}, {115, -52}, {98, -55}, {122, -60}};
308 
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,
313  -1024, 1024, 0, 0}};
314 
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};
318 
319 /*
320  * Dumped from the binaries:
321  * - FantasticJourney.exe - 0x794D2, DGROUP:0x47A4D2
322  * - BigRaceUSA.exe - 0x9B8AA, DGROUP:0x49C4AA
323  * - Timeshock!.exe - 0x8506A, DGROUP:0x485C6A
324  */
325 static const int8_t ima_cunning_index_table[9] = {-1, -1, -1, -1, 1,
326  2, 3, 4, -1};
327 
328 /*
329  * Dumped from the binaries:
330  * - FantasticJourney.exe - 0x79458, DGROUP:0x47A458
331  * - BigRaceUSA.exe - 0x9B830, DGROUP:0x49C430
332  * - Timeshock!.exe - 0x84FF0, DGROUP:0x485BF0
333  */
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};
341 
342 static const int8_t adpcm_index_table2[4] = {
343  -1,
344  2,
345  -1,
346  2,
347 };
348 
349 static const int8_t adpcm_index_table3[8] = {
350  -1, -1, 1, 2, -1, -1, 1, 2,
351 };
352 
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,
356 };
357 
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],
363 };
364 
365 static const int16_t mtaf_stepsize[32][16] = {
366  {
367  1,
368  5,
369  9,
370  13,
371  16,
372  20,
373  24,
374  28,
375  -1,
376  -5,
377  -9,
378  -13,
379  -16,
380  -20,
381  -24,
382  -28,
383  },
384  {
385  2,
386  6,
387  11,
388  15,
389  20,
390  24,
391  29,
392  33,
393  -2,
394  -6,
395  -11,
396  -15,
397  -20,
398  -24,
399  -29,
400  -33,
401  },
402  {
403  2,
404  7,
405  13,
406  18,
407  23,
408  28,
409  34,
410  39,
411  -2,
412  -7,
413  -13,
414  -18,
415  -23,
416  -28,
417  -34,
418  -39,
419  },
420  {
421  3,
422  9,
423  15,
424  21,
425  28,
426  34,
427  40,
428  46,
429  -3,
430  -9,
431  -15,
432  -21,
433  -28,
434  -34,
435  -40,
436  -46,
437  },
438  {
439  3,
440  11,
441  18,
442  26,
443  33,
444  41,
445  48,
446  56,
447  -3,
448  -11,
449  -18,
450  -26,
451  -33,
452  -41,
453  -48,
454  -56,
455  },
456  {
457  4,
458  13,
459  22,
460  31,
461  40,
462  49,
463  58,
464  67,
465  -4,
466  -13,
467  -22,
468  -31,
469  -40,
470  -49,
471  -58,
472  -67,
473  },
474  {
475  5,
476  16,
477  26,
478  37,
479  48,
480  59,
481  69,
482  80,
483  -5,
484  -16,
485  -26,
486  -37,
487  -48,
488  -59,
489  -69,
490  -80,
491  },
492  {
493  6,
494  19,
495  31,
496  44,
497  57,
498  70,
499  82,
500  95,
501  -6,
502  -19,
503  -31,
504  -44,
505  -57,
506  -70,
507  -82,
508  -95,
509  },
510  {
511  7,
512  22,
513  38,
514  53,
515  68,
516  83,
517  99,
518  114,
519  -7,
520  -22,
521  -38,
522  -53,
523  -68,
524  -83,
525  -99,
526  -114,
527  },
528  {
529  9,
530  27,
531  45,
532  63,
533  81,
534  99,
535  117,
536  135,
537  -9,
538  -27,
539  -45,
540  -63,
541  -81,
542  -99,
543  -117,
544  -135,
545  },
546  {
547  10,
548  32,
549  53,
550  75,
551  96,
552  118,
553  139,
554  161,
555  -10,
556  -32,
557  -53,
558  -75,
559  -96,
560  -118,
561  -139,
562  -161,
563  },
564  {
565  12,
566  38,
567  64,
568  90,
569  115,
570  141,
571  167,
572  193,
573  -12,
574  -38,
575  -64,
576  -90,
577  -115,
578  -141,
579  -167,
580  -193,
581  },
582  {
583  15,
584  45,
585  76,
586  106,
587  137,
588  167,
589  198,
590  228,
591  -15,
592  -45,
593  -76,
594  -106,
595  -137,
596  -167,
597  -198,
598  -228,
599  },
600  {
601  18,
602  54,
603  91,
604  127,
605  164,
606  200,
607  237,
608  273,
609  -18,
610  -54,
611  -91,
612  -127,
613  -164,
614  -200,
615  -237,
616  -273,
617  },
618  {
619  21,
620  65,
621  108,
622  152,
623  195,
624  239,
625  282,
626  326,
627  -21,
628  -65,
629  -108,
630  -152,
631  -195,
632  -239,
633  -282,
634  -326,
635  },
636  {
637  25,
638  77,
639  129,
640  181,
641  232,
642  284,
643  336,
644  388,
645  -25,
646  -77,
647  -129,
648  -181,
649  -232,
650  -284,
651  -336,
652  -388,
653  },
654  {
655  30,
656  92,
657  153,
658  215,
659  276,
660  338,
661  399,
662  461,
663  -30,
664  -92,
665  -153,
666  -215,
667  -276,
668  -338,
669  -399,
670  -461,
671  },
672  {
673  36,
674  109,
675  183,
676  256,
677  329,
678  402,
679  476,
680  549,
681  -36,
682  -109,
683  -183,
684  -256,
685  -329,
686  -402,
687  -476,
688  -549,
689  },
690  {
691  43,
692  130,
693  218,
694  305,
695  392,
696  479,
697  567,
698  654,
699  -43,
700  -130,
701  -218,
702  -305,
703  -392,
704  -479,
705  -567,
706  -654,
707  },
708  {
709  52,
710  156,
711  260,
712  364,
713  468,
714  572,
715  676,
716  780,
717  -52,
718  -156,
719  -260,
720  -364,
721  -468,
722  -572,
723  -676,
724  -780,
725  },
726  {
727  62,
728  186,
729  310,
730  434,
731  558,
732  682,
733  806,
734  930,
735  -62,
736  -186,
737  -310,
738  -434,
739  -558,
740  -682,
741  -806,
742  -930,
743  },
744  {
745  73,
746  221,
747  368,
748  516,
749  663,
750  811,
751  958,
752  1106,
753  -73,
754  -221,
755  -368,
756  -516,
757  -663,
758  -811,
759  -958,
760  -1106,
761  },
762  {
763  87,
764  263,
765  439,
766  615,
767  790,
768  966,
769  1142,
770  1318,
771  -87,
772  -263,
773  -439,
774  -615,
775  -790,
776  -966,
777  -1142,
778  -1318,
779  },
780  {
781  104,
782  314,
783  523,
784  733,
785  942,
786  1152,
787  1361,
788  1571,
789  -104,
790  -314,
791  -523,
792  -733,
793  -942,
794  -1152,
795  -1361,
796  -1571,
797  },
798  {
799  124,
800  374,
801  623,
802  873,
803  1122,
804  1372,
805  1621,
806  1871,
807  -124,
808  -374,
809  -623,
810  -873,
811  -1122,
812  -1372,
813  -1621,
814  -1871,
815  },
816  {
817  148,
818  445,
819  743,
820  1040,
821  1337,
822  1634,
823  1932,
824  2229,
825  -148,
826  -445,
827  -743,
828  -1040,
829  -1337,
830  -1634,
831  -1932,
832  -2229,
833  },
834  {
835  177,
836  531,
837  885,
838  1239,
839  1593,
840  1947,
841  2301,
842  2655,
843  -177,
844  -531,
845  -885,
846  -1239,
847  -1593,
848  -1947,
849  -2301,
850  -2655,
851  },
852  {
853  210,
854  632,
855  1053,
856  1475,
857  1896,
858  2318,
859  2739,
860  3161,
861  -210,
862  -632,
863  -1053,
864  -1475,
865  -1896,
866  -2318,
867  -2739,
868  -3161,
869  },
870  {
871  251,
872  753,
873  1255,
874  1757,
875  2260,
876  2762,
877  3264,
878  3766,
879  -251,
880  -753,
881  -1255,
882  -1757,
883  -2260,
884  -2762,
885  -3264,
886  -3766,
887  },
888  {
889  299,
890  897,
891  1495,
892  2093,
893  2692,
894  3290,
895  3888,
896  4486,
897  -299,
898  -897,
899  -1495,
900  -2093,
901  -2692,
902  -3290,
903  -3888,
904  -4486,
905  },
906  {
907  356,
908  1068,
909  1781,
910  2493,
911  3206,
912  3918,
913  4631,
914  5343,
915  -356,
916  -1068,
917  -1781,
918  -2493,
919  -3206,
920  -3918,
921  -4631,
922  -5343,
923  },
924  {
925  424,
926  1273,
927  2121,
928  2970,
929  3819,
930  4668,
931  5516,
932  6365,
933  -424,
934  -1273,
935  -2121,
936  -2970,
937  -3819,
938  -4668,
939  -5516,
940  -6365,
941  },
942 };
943 
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};
949 
950 // padded to zero where table size is less then 16
951 static const int8_t swf_index_tables[4][16] = {
952  /*2*/ {-1, 2},
953  /*3*/ {-1, -1, 2, 4},
954  /*4*/ {-1, -1, -1, -1, 2, 4, 6, 8},
955  /*5*/ {-1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16}};
956 
957 static const int8_t zork_index_table[8] = {
958  -1, -1, -1, 1, 4, 7, 10, 12,
959 };
960 
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,
963 };
964 
965 /* end of tables */
966 
967 av_always_inline av_const int av_clip(int a, int amin, int amax) {
968  // #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >=
969  // 2
970  assert(amin <= amax);
971  // #endif
972  if (a < amin)
973  return amin;
974  else if (a > amax)
975  return amax;
976  else
977  return a;
978 }
979 
980 void *av_malloc(size_t size) { return malloc(size); }
981 
982 void av_free(void *ptr) {
983 #if HAVE_ALIGNED_MALLOC
984  _aligned_free(ptr);
985 #else
986  free(ptr);
987 #endif
988 }
989 
990 void av_freep(void *arg) {
991  void *val;
992 
993  memcpy(&val, arg, sizeof(val));
994  static void *const temp = NULL;
995  memcpy(arg, &temp, sizeof(val));
996  av_free(val);
997 }
998 
999 void *av_mallocz(size_t size) {
1000  void *ptr = av_malloc(size);
1001  if (ptr) memset(ptr, 0, size);
1002  return ptr;
1003 }
1004 
1005 int size_mult(size_t a, size_t b, size_t *r) {
1006  size_t t;
1007 
1008  t = a * b;
1009  /* Hack inspired from glibc: don't try the division if nelem and elsize
1010  * are both less than sqrt(SIZE_MAX). */
1011  if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
1012  return AVERROR(AVERROR_INVALID);
1013  *r = t;
1014  return 0;
1015 }
1016 
1017 void *av_calloc(size_t nmemb, size_t size) {
1018  size_t result;
1019  if (size_mult(nmemb, size, &result) < 0) return NULL;
1020  return av_mallocz(result);
1021 }
1022 
1023 void *av_malloc_array(size_t nmemb, size_t size) {
1024  size_t result;
1025  if (size_mult(nmemb, size, &result) < 0) return NULL;
1026  return av_malloc(result);
1027 }
1028 
1034 av_always_inline av_const uint16_t av_clip_uint16(int a) {
1035  if (a & (~0xFFFF))
1036  return (~a) >> 31;
1037  else
1038  return a;
1039 }
1040 
1046 av_always_inline av_const int16_t av_clip_int16(int a) {
1047  if ((a + 0x8000U) & ~0xFFFF)
1048  return (a >> 31) ^ 0x7FFF;
1049  else
1050  return a;
1051 }
1052 
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);
1062  else
1063  return a;
1064 }
1065 
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);
1075  else
1076  return a;
1077 }
1078 
1086 av_always_inline av_const unsigned av_mod_uintp2(unsigned a, unsigned p) {
1087  return a & ((1U << p) - 1);
1088 }
1089 
1090 #ifndef sign_extend
1091 inline av_const int sign_extend(int val, unsigned bits) {
1092  unsigned shift = 8 * sizeof(int) - bits;
1093  union {
1094  unsigned u;
1095  int s;
1096  } v = {(unsigned)val << shift};
1097  return v.s >> shift;
1098 }
1099 #endif
1100 
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;
1104  union {
1105  uint64_t u;
1106  int64_t s;
1107  } v = {(uint64_t)val << shift};
1108  return v.s >> shift;
1109 }
1110 #endif
1111 
1112 #ifndef zero_extend
1113 inline av_const unsigned zero_extend(unsigned val, unsigned bits) {
1114  return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
1115 }
1116 #endif
1117 
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)));
1120  return a;
1121 }
1122 
1123 }
Definition: adpcm.h:206
Definition: adpcm.h:255
int vqa_version
Definition: adpcm.h:257
int has_status
Definition: adpcm.h:258
Definition: adpcm.h:221
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
Definition: adpcm.h:193
Definition: adpcm.h:188