38 #include "config_components.h"
68 #define CASE_0(codec_id, ...)
69 #define CASE_1(codec_id, ...) \
73 #define CASE_2(enabled, codec_id, ...) \
74 CASE_ ## enabled(codec_id, __VA_ARGS__)
75 #define CASE_3(config, codec_id, ...) \
76 CASE_2(config, codec_id, __VA_ARGS__)
77 #define CASE(codec, ...) \
78 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
90 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
91 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
109 -1, -1, -1, -1, 1, 2, 3, 4, -1
119 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
120 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
121 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
122 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
123 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
124 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
138 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
139 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
150 { 1, 5, 9, 13, 16, 20, 24, 28,
151 -1, -5, -9, -13, -16, -20, -24, -28, },
152 { 2, 6, 11, 15, 20, 24, 29, 33,
153 -2, -6, -11, -15, -20, -24, -29, -33, },
154 { 2, 7, 13, 18, 23, 28, 34, 39,
155 -2, -7, -13, -18, -23, -28, -34, -39, },
156 { 3, 9, 15, 21, 28, 34, 40, 46,
157 -3, -9, -15, -21, -28, -34, -40, -46, },
158 { 3, 11, 18, 26, 33, 41, 48, 56,
159 -3, -11, -18, -26, -33, -41, -48, -56, },
160 { 4, 13, 22, 31, 40, 49, 58, 67,
161 -4, -13, -22, -31, -40, -49, -58, -67, },
162 { 5, 16, 26, 37, 48, 59, 69, 80,
163 -5, -16, -26, -37, -48, -59, -69, -80, },
164 { 6, 19, 31, 44, 57, 70, 82, 95,
165 -6, -19, -31, -44, -57, -70, -82, -95, },
166 { 7, 22, 38, 53, 68, 83, 99, 114,
167 -7, -22, -38, -53, -68, -83, -99, -114, },
168 { 9, 27, 45, 63, 81, 99, 117, 135,
169 -9, -27, -45, -63, -81, -99, -117, -135, },
170 { 10, 32, 53, 75, 96, 118, 139, 161,
171 -10, -32, -53, -75, -96, -118, -139, -161, },
172 { 12, 38, 64, 90, 115, 141, 167, 193,
173 -12, -38, -64, -90, -115, -141, -167, -193, },
174 { 15, 45, 76, 106, 137, 167, 198, 228,
175 -15, -45, -76, -106, -137, -167, -198, -228, },
176 { 18, 54, 91, 127, 164, 200, 237, 273,
177 -18, -54, -91, -127, -164, -200, -237, -273, },
178 { 21, 65, 108, 152, 195, 239, 282, 326,
179 -21, -65, -108, -152, -195, -239, -282, -326, },
180 { 25, 77, 129, 181, 232, 284, 336, 388,
181 -25, -77, -129, -181, -232, -284, -336, -388, },
182 { 30, 92, 153, 215, 276, 338, 399, 461,
183 -30, -92, -153, -215, -276, -338, -399, -461, },
184 { 36, 109, 183, 256, 329, 402, 476, 549,
185 -36, -109, -183, -256, -329, -402, -476, -549, },
186 { 43, 130, 218, 305, 392, 479, 567, 654,
187 -43, -130, -218, -305, -392, -479, -567, -654, },
188 { 52, 156, 260, 364, 468, 572, 676, 780,
189 -52, -156, -260, -364, -468, -572, -676, -780, },
190 { 62, 186, 310, 434, 558, 682, 806, 930,
191 -62, -186, -310, -434, -558, -682, -806, -930, },
192 { 73, 221, 368, 516, 663, 811, 958, 1106,
193 -73, -221, -368, -516, -663, -811, -958, -1106, },
194 { 87, 263, 439, 615, 790, 966, 1142, 1318,
195 -87, -263, -439, -615, -790, -966, -1142, -1318, },
196 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
197 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
198 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
199 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
200 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
201 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
202 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
203 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
204 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
205 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
206 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
207 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
208 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
209 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
210 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
211 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
212 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
213 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
217 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
218 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
219 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
220 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
221 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
228 { -1, -1, -1, -1, 2, 4, 6, 8 },
229 { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
233 -1, -1, -1, 1, 4, 7, 10, 12,
237 8, 6, 4, 2, -1, -1, -1, -1,
238 -1, -1, -1, -1, 2, 4, 6, 8,
254 unsigned int min_channels = 1;
255 unsigned int max_channels = 2;
367 if ((nibble & 8) == 0)
377 c->step =
av_clip(
c->step * 2, 127, 24576);
408 step_index =
av_clip(step_index, 0, 88);
421 c->step_index = step_index;
423 return (int16_t)
c->predictor;
434 step_index =
av_clip(step_index, 0, 88);
444 c->step_index = step_index;
446 return (int16_t)
c->predictor;
460 c->step_index =
av_clip(step_index, 0, 88);
462 return (int16_t)
c->predictor;
475 step_index =
av_clip(step_index, 0, 60);
480 c->step_index = step_index;
493 step_index =
av_clip(step_index, 0, 88);
495 sign = nibble & (1 <<
shift);
503 c->step_index = step_index;
505 return (int16_t)
c->predictor;
516 step_index =
av_clip(step_index, 0, 88);
529 c->step_index = step_index;
538 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
539 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
541 c->sample2 =
c->sample1;
544 if (
c->idelta < 16)
c->idelta = 16;
545 if (
c->idelta > INT_MAX/768) {
547 c->idelta = INT_MAX/768;
559 step_index =
av_clip(step_index, 0, 48);
569 c->step_index = step_index;
571 return c->predictor * 16;
586 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
590 c->step =
av_clip(new_step, 511, 32767);
592 return (int16_t)
c->predictor;
599 sign = nibble & (1<<(
size-1));
609 else if (
delta == 0 &&
c->step > 0)
612 return (int16_t)
c->predictor;
640 int16_t
index =
c->step_index;
647 sample += lookup_sample >> 1;
649 sample += lookup_sample >> 2;
651 sample += lookup_sample >> 3;
653 sample += lookup_sample >> 4;
655 sample += lookup_sample >> 5;
657 sample += lookup_sample >> 6;
682 out0 += sample_offset;
686 out1 += sample_offset;
689 shift = 12 - (in[4+
i*2] & 15);
709 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
722 shift = 12 - (in[5+
i*2] & 15);
740 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
767 int k0, signmask, nb_bits, count;
768 int size = buf_size*8;
776 k0 = 1 << (nb_bits-2);
777 signmask = 1 << (nb_bits-1);
803 if (
delta & signmask)
804 c->status[
i].predictor -= vpdiff;
806 c->status[
i].predictor += vpdiff;
810 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
848 int buf_size,
int *coded_samples,
int *approx_nb_samples)
853 int has_coded_samples = 0;
857 *approx_nb_samples = 0;
865 if (buf_size < 76 * ch)
870 if (buf_size < 34 * ch)
887 nb_samples = buf_size * 2 / ch;
905 return (buf_size - header_size) * 2 / ch;
911 has_coded_samples = 1;
912 *coded_samples = bytestream2_get_le32u(gb);
913 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
917 has_coded_samples = 1;
918 *coded_samples = bytestream2_get_le32(gb);
919 *coded_samples -= *coded_samples % 28;
920 nb_samples = (buf_size - 12) / 30 * 28;
923 has_coded_samples = 1;
924 *coded_samples = bytestream2_get_le32(gb);
925 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
928 nb_samples = (buf_size - ch) / ch * 2;
935 has_coded_samples = 1;
938 header_size = 4 + 9 * ch;
939 *coded_samples = bytestream2_get_le32(gb);
942 header_size = 4 + 5 * ch;
943 *coded_samples = bytestream2_get_le32(gb);
946 header_size = 4 + 5 * ch;
947 *coded_samples = bytestream2_get_be32(gb);
950 *coded_samples -= *coded_samples % 28;
951 nb_samples = (buf_size - header_size) * 2 / ch;
952 nb_samples -= nb_samples % 28;
953 *approx_nb_samples = 1;
958 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
963 if (buf_size < 4 * ch)
965 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
970 nb_samples = (buf_size - 4 * ch) * 2 / ch;
977 if (buf_size < 4 * ch)
979 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
984 nb_samples = (buf_size - 6 * ch) * 2 / ch;
989 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
995 int samples_per_byte;
1001 if (!
s->status[0].step_index) {
1007 nb_samples += buf_size * samples_per_byte / ch;
1012 int buf_bits = buf_size * 8 - 2;
1013 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1014 int block_hdr_size = 22 * ch;
1015 int block_size = block_hdr_size + nbits * ch * 4095;
1016 int nblocks = buf_bits / block_size;
1017 int bits_left = buf_bits - nblocks * block_size;
1018 nb_samples = nblocks * 4096;
1020 nb_samples += 1 + (
bits_left - block_hdr_size) / (nbits * ch);
1026 nb_samples = buf_size * 14 / (8 * ch);
1029 has_coded_samples = 1;
1032 bytestream2_get_le32(gb) :
1033 bytestream2_get_be32(gb);
1034 buf_size -= 8 + 36 * ch;
1036 nb_samples = buf_size / 8 * 14;
1037 if (buf_size % 8 > 1)
1038 nb_samples += (buf_size % 8 - 1) * 2;
1039 *approx_nb_samples = 1;
1042 nb_samples = buf_size / (9 * ch) * 16;
1045 nb_samples = (buf_size / 128) * 224 / ch;
1048 nb_samples = buf_size / (21 * ch) * 32;
1052 nb_samples = buf_size / (16 * ch) * 28;
1058 nb_samples = buf_size / ch;
1063 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1070 int *got_frame_ptr,
AVPacket *avpkt)
1072 const uint8_t *buf = avpkt->
data;
1073 int buf_size = avpkt->
size;
1077 int16_t **samples_p;
1079 int nb_samples, coded_samples, approx_nb_samples,
ret;
1083 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1084 if (nb_samples <= 0) {
1090 frame->nb_samples = nb_samples;
1094 samples_p = (int16_t **)
frame->extended_data;
1098 if (coded_samples) {
1099 if (!approx_nb_samples && coded_samples != nb_samples)
1101 frame->nb_samples = nb_samples = coded_samples;
1141 for (
int m = 0; m < 64; m += 2) {
1142 int byte = bytestream2_get_byteu(&gb);
1167 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1170 samples = &samples_p[
i][1 + n * samples_per_block];
1171 for (
int j = 0; j < block_size; j++) {
1173 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1178 for (
int m = 0; m < samples_per_block; m++) {
1186 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1189 samples = &samples_p[
i][1 + n * 8];
1190 for (
int m = 0; m < 8; m += 2) {
1191 int v = bytestream2_get_byteu(&gb);
1201 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1204 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1205 if (
c->status[
i].step_index > 88
u) {
1207 i,
c->status[
i].step_index);
1215 for (
int n = nb_samples >> 1; n > 0; n--) {
1216 int v = bytestream2_get_byteu(&gb);
1224 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1226 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1228 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1229 int v = bytestream2_get_byteu(&gb);
1235 int block_predictor;
1240 block_predictor = bytestream2_get_byteu(&gb);
1241 if (block_predictor > 6) {
1253 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1254 int byte = bytestream2_get_byteu(&gb);
1260 block_predictor = bytestream2_get_byteu(&gb);
1261 if (block_predictor > 6) {
1269 block_predictor = bytestream2_get_byteu(&gb);
1270 if (block_predictor > 6) {
1278 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1280 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1283 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1284 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1285 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1286 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1289 if (st) *
samples++ =
c->status[1].sample2;
1291 if (st) *
samples++ =
c->status[1].sample1;
1292 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1293 int byte = bytestream2_get_byteu(&gb);
1302 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1303 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1308 for (
int n = 0; n < nb_samples; n += 2) {
1309 int v = bytestream2_get_byteu(&gb);
1313 for (
int n = 0; n < nb_samples; n += 2) {
1314 int v = bytestream2_get_byteu(&gb);
1331 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1332 int v = bytestream2_get_byteu(&gb);
1340 if (decode_top_nibble_next) { \
1341 nibble = last_byte >> 4; \
1342 decode_top_nibble_next = 0; \
1344 last_byte = bytestream2_get_byteu(&gb); \
1345 nibble = last_byte & 0x0F; \
1346 decode_top_nibble_next = 1; \
1351 int decode_top_nibble_next = 0;
1356 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1357 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1358 c->status[0].step_index = bytestream2_get_byteu(&gb);
1359 c->status[1].step_index = bytestream2_get_byteu(&gb);
1360 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1362 c->status[0].step_index,
c->status[1].step_index);
1366 diff_channel =
c->status[1].predictor;
1368 while (
samples < samples_end) {
1382 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1383 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1384 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1391 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1392 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1393 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1411 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1413 int v = bytestream2_get_byteu(&gb);
1426 CASE(ADPCM_IMA_MOFLEX,
1438 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1441 for (
int n = 0; n < 256; n += 2) {
1442 int v = bytestream2_get_byteu(&gb);
1449 CASE(ADPCM_IMA_DAT4,
1454 for (
int n = 0; n < nb_samples; n += 2) {
1455 int v = bytestream2_get_byteu(&gb);
1462 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1463 int v = bytestream2_get_byteu(&gb);
1469 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1470 int v = bytestream2_get_byteu(&gb);
1476 for (
int n = nb_samples / 2; n > 0; n--) {
1478 int v = bytestream2_get_byteu(&gb);
1486 for (
int n = nb_samples / 2; n > 0; n--) {
1488 int v = bytestream2_get_byteu(&gb);
1495 CASE(ADPCM_IMA_CUNNING,
1497 int16_t *smp = samples_p[
channel];
1498 for (
int n = 0; n < nb_samples / 2; n++) {
1499 int v = bytestream2_get_byteu(&gb);
1506 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1507 int v = bytestream2_get_byteu(&gb);
1523 for (
int n = 0; n < nb_samples / 2; n++) {
1526 byte[0] = bytestream2_get_byteu(&gb);
1528 byte[1] = bytestream2_get_byteu(&gb);
1538 if (
c->vqa_version == 3) {
1540 int16_t *smp = samples_p[
channel];
1542 for (
int n = nb_samples / 2; n > 0; n--) {
1543 int v = bytestream2_get_byteu(&gb);
1549 for (
int n = nb_samples / 2; n > 0; n--) {
1551 int v = bytestream2_get_byteu(&gb);
1561 int bytes_remaining,
block = 0;
1568 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
1569 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
1570 scale = bytestream2_get_le16(&gb);
1572 out[0] = history[1];
1573 out[1] = history[0];
1575 for (
int n = 0; n < 15; n++) {
1576 unsigned byte = bytestream2_get_byte(&gb);
1582 out[2+n*2] = (nibble[0]*(
scale<<14) + (history[0]*29336) - (history[1]*13136)) >> 14;
1583 history[1] = history[0];
1584 history[0] =
out[2+n*2];
1586 out[2+n*2+1] = (nibble[1]*(
scale<<14) + (history[0]*29336) - (history[1]*13136)) >> 14;
1587 history[1] = history[0];
1588 history[0] =
out[2+n*2+1];
1595 if (bytes_remaining > 0) {
1600 int16_t *out0 = samples_p[0];
1601 int16_t *out1 = samples_p[1];
1602 int samples_per_block = 28 * (3 -
channels) * 4;
1603 int sample_offset = 0;
1604 int bytes_remaining;
1607 &
c->status[0], &
c->status[1],
1611 sample_offset += samples_per_block;
1616 if (bytes_remaining > 0) {
1620 CASE(ADPCM_IMA_EA_EACS,
1621 for (
int i = 0;
i <= st;
i++) {
1622 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1623 if (
c->status[
i].step_index > 88
u) {
1625 i,
c->status[
i].step_index);
1629 for (
int i = 0;
i <= st;
i++) {
1630 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1631 if (
FFABS((int64_t)
c->status[
i].predictor) > (1<<16))
1635 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1636 int byte = bytestream2_get_byteu(&gb);
1641 CASE(ADPCM_IMA_EA_SEAD,
1642 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1643 int byte = bytestream2_get_byteu(&gb);
1649 int previous_left_sample, previous_right_sample;
1650 int current_left_sample, current_right_sample;
1651 int next_left_sample, next_right_sample;
1652 int coeff1l, coeff2l, coeff1r, coeff2r;
1653 int shift_left, shift_right;
1661 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1662 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1663 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1664 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1666 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1667 int byte = bytestream2_get_byteu(&gb);
1673 byte = bytestream2_get_byteu(&gb);
1674 shift_left = 20 - (
byte >> 4);
1675 shift_right = 20 - (
byte & 0x0F);
1677 for (
int count2 = 0; count2 < 28; count2++) {
1678 byte = bytestream2_get_byteu(&gb);
1679 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1680 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1682 next_left_sample = (next_left_sample +
1683 (current_left_sample * coeff1l) +
1684 (previous_left_sample * coeff2l) + 0x80) >> 8;
1685 next_right_sample = (next_right_sample +
1686 (current_right_sample * coeff1r) +
1687 (previous_right_sample * coeff2r) + 0x80) >> 8;
1689 previous_left_sample = current_left_sample;
1691 previous_right_sample = current_right_sample;
1693 *
samples++ = current_left_sample;
1694 *
samples++ = current_right_sample;
1700 CASE(ADPCM_EA_MAXIS_XA,
1704 int byte = bytestream2_get_byteu(&gb);
1705 for (
int i = 0;
i < 2;
i++)
1709 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1712 byte[0] = bytestream2_get_byteu(&gb);
1713 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1714 for (
int i = 4;
i >= 0;
i-=4) {
1728 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1737 int previous_sample, current_sample, next_sample;
1746 bytestream2_get_le32(&gb)) +
1753 samplesC = samples_p[
channel];
1756 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1757 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1759 current_sample =
c->status[
channel].predictor;
1760 previous_sample =
c->status[
channel].prev_sample;
1763 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1764 int byte = bytestream2_get_byte(&gb);
1766 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1767 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1769 for (
int count2 = 0; count2 < 28; count2++)
1770 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1774 shift = 20 - (
byte & 0x0F);
1776 for (
int count2 = 0; count2 < 28; count2++) {
1780 byte = bytestream2_get_byte(&gb);
1784 next_sample += (current_sample * coeff1) +
1785 (previous_sample * coeff2);
1788 previous_sample = current_sample;
1789 current_sample = next_sample;
1790 *samplesC++ = current_sample;
1796 }
else if (count != count1) {
1798 count =
FFMAX(count, count1);
1802 c->status[
channel].predictor = current_sample;
1803 c->status[
channel].prev_sample = previous_sample;
1807 frame->nb_samples = count * 28;
1816 for (
int n = 0; n < 4; n++,
s += 32) {
1818 for (
int i = 0;
i < 2;
i++)
1827 for (
int m = 2; m < 32; m += 2) {
1829 for (
int n = 0; n < 4; n++,
s += 32) {
1831 int byte = bytestream2_get_byteu(&gb);
1844 CASE(ADPCM_IMA_ACORN,
1848 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
1855 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1856 int byte = bytestream2_get_byteu(&gb);
1874 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1875 c->status[0].step_index = bytestream2_get_byteu(&gb);
1877 if (
c->status[0].step_index > 88
u) {
1879 c->status[0].step_index);
1883 for (
int n = nb_samples >> 1; n > 0; n--) {
1884 int v = bytestream2_get_byteu(&gb);
1890 if (nb_samples & 1) {
1891 int v = bytestream2_get_byteu(&gb);
1901 CASE(ADPCM_IMA_SMJPEG,
1903 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
1904 c->status[
i].step_index = bytestream2_get_byteu(&gb);
1906 if (
c->status[
i].step_index > 88
u) {
1908 c->status[
i].step_index);
1913 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1914 int v = bytestream2_get_byteu(&gb);
1921 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1922 int v = bytestream2_get_byteu(&gb);
1927 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
1928 CONFIG_ADPCM_SBPRO_4_DECODER
1932 if (!
c->status[0].step_index) {
1934 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1936 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1937 c->status[0].step_index = 1;
1941 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1942 int byte = bytestream2_get_byteu(&gb);
1949 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
1950 int byte = bytestream2_get_byteu(&gb);
1954 (
byte >> 2) & 0x07, 3, 0);
1959 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
1960 int byte = bytestream2_get_byteu(&gb);
1964 (
byte >> 4) & 0x03, 2, 2);
1966 (
byte >> 2) & 0x03, 2, 2);
1978 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1979 int v = bytestream2_get_byteu(&gb);
1987 for (
int n = nb_samples >> 1; n > 0; n--) {
1988 int v = bytestream2_get_byteu(&gb);
1995 int samples_per_block;
1999 samples_per_block = avctx->
extradata[0] / 16;
2000 blocks = nb_samples / avctx->
extradata[0];
2002 samples_per_block = nb_samples / 16;
2006 for (
int m = 0; m < blocks; m++) {
2008 int prev1 =
c->status[
channel].sample1;
2009 int prev2 =
c->status[
channel].sample2;
2013 for (
int i = 0;
i < samples_per_block;
i++) {
2014 int byte = bytestream2_get_byteu(&gb);
2015 int scale = 1 << (
byte >> 4);
2016 int index =
byte & 0xf;
2021 for (
int n = 0; n < 16; n++) {
2027 byte = bytestream2_get_byteu(&gb);
2031 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2039 c->status[
channel].sample1 = prev1;
2040 c->status[
channel].sample2 = prev2;
2045 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2051 #define THP_GET16(g) \
2053 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2054 bytestream2_get_le16u(&(g)) : \
2055 bytestream2_get_be16u(&(g)), 16)
2066 for (
int n = 0; n < 16; n++)
2070 for (
int n = 0; n < 16; n++)
2071 table[
i][n] = THP_GET16(gb);
2073 if (!
c->has_status) {
2076 c->status[
i].sample1 = THP_GET16(gb);
2077 c->status[
i].sample2 = THP_GET16(gb);
2085 for (
int ch = 0; ch <
channels; ch++) {
2089 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2090 int byte = bytestream2_get_byteu(&gb);
2091 int index = (
byte >> 4) & 7;
2092 unsigned int exp =
byte & 0x0F;
2097 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2103 byte = bytestream2_get_byteu(&gb);
2107 sampledat = ((
c->status[ch].sample1 * factor1
2108 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2110 c->status[ch].sample2 =
c->status[ch].sample1;
2111 c->status[ch].sample1 = *
samples++;
2123 for (
int i = 0;
i < nb_samples / 28;
i++) {
2127 header = bytestream2_get_byteu(&gb);
2131 for (
int n = 0; n < 28; n++) {
2136 prev = (
c->status[
channel].sample1 * 0x3c);
2139 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2142 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2150 byte = bytestream2_get_byteu(&gb);
2156 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2159 c->status[
channel].sample1 = sampledat;
2174 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2177 filter = bytestream2_get_byteu(&gb);
2182 flag = bytestream2_get_byteu(&gb) & 0x7;
2185 for (
int n = 0; n < 28; n++) {
2191 byte = bytestream2_get_byteu(&gb);
2233 control = bytestream2_get_byteu(&gb);
2234 shift = (control >> 4) + 2;
2236 for (
int n = 0; n < 16; n++) {
2237 int sample = bytestream2_get_byteu(&gb);
2245 for (
int n = 0; n < nb_samples *
channels; n++) {
2246 int v = bytestream2_get_byteu(&gb);
2251 for (
int n = nb_samples / 2; n > 0; n--) {
2253 int v = bytestream2_get_byteu(&gb);
2288 c->status[0].step =
c->status[1].step = 511;
2329 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2330 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2331 const FFCodec ff_ ## name_ ## _decoder = { \
2333 CODEC_LONG_NAME(long_name_), \
2334 .p.type = AVMEDIA_TYPE_AUDIO, \
2336 .p.capabilities = AV_CODEC_CAP_DR1, \
2337 .p.sample_fmts = sample_fmts_, \
2338 .priv_data_size = sizeof(ADPCMDecodeContext), \
2339 .init = adpcm_decode_init, \
2340 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2341 .flush = adpcm_flush, \
2343 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2344 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2345 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2346 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2347 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2348 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2349 name, sample_fmts, long_name)