39 #include "config_components.h"
71 #define CASE_0(codec_id, ...)
72 #define CASE_1(codec_id, ...) \
76 #define CASE_2(enabled, codec_id, ...) \
77 CASE_ ## enabled(codec_id, __VA_ARGS__)
78 #define CASE_3(config, codec_id, ...) \
79 CASE_2(config, codec_id, __VA_ARGS__)
80 #define CASE(codec, ...) \
81 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
93 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
94 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
112 -1, -1, -1, -1, 1, 2, 3, 4, -1
122 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
123 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
124 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
125 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
126 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
127 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
141 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
142 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
153 { 1, 5, 9, 13, 16, 20, 24, 28,
154 -1, -5, -9, -13, -16, -20, -24, -28, },
155 { 2, 6, 11, 15, 20, 24, 29, 33,
156 -2, -6, -11, -15, -20, -24, -29, -33, },
157 { 2, 7, 13, 18, 23, 28, 34, 39,
158 -2, -7, -13, -18, -23, -28, -34, -39, },
159 { 3, 9, 15, 21, 28, 34, 40, 46,
160 -3, -9, -15, -21, -28, -34, -40, -46, },
161 { 3, 11, 18, 26, 33, 41, 48, 56,
162 -3, -11, -18, -26, -33, -41, -48, -56, },
163 { 4, 13, 22, 31, 40, 49, 58, 67,
164 -4, -13, -22, -31, -40, -49, -58, -67, },
165 { 5, 16, 26, 37, 48, 59, 69, 80,
166 -5, -16, -26, -37, -48, -59, -69, -80, },
167 { 6, 19, 31, 44, 57, 70, 82, 95,
168 -6, -19, -31, -44, -57, -70, -82, -95, },
169 { 7, 22, 38, 53, 68, 83, 99, 114,
170 -7, -22, -38, -53, -68, -83, -99, -114, },
171 { 9, 27, 45, 63, 81, 99, 117, 135,
172 -9, -27, -45, -63, -81, -99, -117, -135, },
173 { 10, 32, 53, 75, 96, 118, 139, 161,
174 -10, -32, -53, -75, -96, -118, -139, -161, },
175 { 12, 38, 64, 90, 115, 141, 167, 193,
176 -12, -38, -64, -90, -115, -141, -167, -193, },
177 { 15, 45, 76, 106, 137, 167, 198, 228,
178 -15, -45, -76, -106, -137, -167, -198, -228, },
179 { 18, 54, 91, 127, 164, 200, 237, 273,
180 -18, -54, -91, -127, -164, -200, -237, -273, },
181 { 21, 65, 108, 152, 195, 239, 282, 326,
182 -21, -65, -108, -152, -195, -239, -282, -326, },
183 { 25, 77, 129, 181, 232, 284, 336, 388,
184 -25, -77, -129, -181, -232, -284, -336, -388, },
185 { 30, 92, 153, 215, 276, 338, 399, 461,
186 -30, -92, -153, -215, -276, -338, -399, -461, },
187 { 36, 109, 183, 256, 329, 402, 476, 549,
188 -36, -109, -183, -256, -329, -402, -476, -549, },
189 { 43, 130, 218, 305, 392, 479, 567, 654,
190 -43, -130, -218, -305, -392, -479, -567, -654, },
191 { 52, 156, 260, 364, 468, 572, 676, 780,
192 -52, -156, -260, -364, -468, -572, -676, -780, },
193 { 62, 186, 310, 434, 558, 682, 806, 930,
194 -62, -186, -310, -434, -558, -682, -806, -930, },
195 { 73, 221, 368, 516, 663, 811, 958, 1106,
196 -73, -221, -368, -516, -663, -811, -958, -1106, },
197 { 87, 263, 439, 615, 790, 966, 1142, 1318,
198 -87, -263, -439, -615, -790, -966, -1142, -1318, },
199 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
200 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
201 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
202 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
203 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
204 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
205 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
206 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
207 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
208 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
209 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
210 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
211 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
212 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
213 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
214 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
215 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
216 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
220 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
221 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
222 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
223 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
224 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
231 { -1, -1, -1, -1, 2, 4, 6, 8 },
232 { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
236 -1, -1, -1, 1, 4, 7, 10, 12,
240 8, 6, 4, 2, -1, -1, -1, -1,
241 -1, -1, -1, -1, 2, 4, 6, 8,
257 unsigned int min_channels = 1;
258 unsigned int max_channels = 2;
382 if ((nibble & 8) == 0)
392 c->step =
av_clip(
c->step * 2, 127, 24576);
423 step_index =
av_clip(step_index, 0, 88);
436 c->step_index = step_index;
438 return (int16_t)
c->predictor;
449 step_index =
av_clip(step_index, 0, 88);
459 c->step_index = step_index;
461 return (int16_t)
c->predictor;
475 c->step_index =
av_clip(step_index, 0, 88);
477 return (int16_t)
c->predictor;
490 step_index =
av_clip(step_index, 0, 60);
495 c->step_index = step_index;
508 step_index =
av_clip(step_index, 0, 88);
510 sign = nibble & (1 <<
shift);
518 c->step_index = step_index;
520 return (int16_t)
c->predictor;
531 step_index =
av_clip(step_index, 0, 88);
544 c->step_index = step_index;
553 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
554 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
556 c->sample2 =
c->sample1;
559 if (
c->idelta < 16)
c->idelta = 16;
560 if (
c->idelta > INT_MAX/768) {
562 c->idelta = INT_MAX/768;
574 step_index =
av_clip(step_index, 0, 48);
584 c->step_index = step_index;
586 return c->predictor * 16;
601 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
605 c->step =
av_clip(new_step, 511, 32767);
607 return (int16_t)
c->predictor;
614 sign = nibble & (1<<(
size-1));
624 else if (
delta == 0 &&
c->step > 0)
627 return (int16_t)
c->predictor;
655 int16_t
index =
c->step_index;
662 sample += lookup_sample >> 1;
664 sample += lookup_sample >> 2;
666 sample += lookup_sample >> 3;
668 sample += lookup_sample >> 4;
670 sample += lookup_sample >> 5;
672 sample += lookup_sample >> 6;
697 out0 += sample_offset;
701 out1 += sample_offset;
704 shift = 12 - (in[4+
i*2] & 15);
724 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
737 shift = 12 - (in[5+
i*2] & 15);
755 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
782 int k0, signmask, nb_bits, count;
783 int size = buf_size*8;
791 k0 = 1 << (nb_bits-2);
792 signmask = 1 << (nb_bits-1);
818 if (
delta & signmask)
819 c->status[
i].predictor -= vpdiff;
821 c->status[
i].predictor += vpdiff;
825 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
853 int sign,
delta, add;
864 c->step = (3 *
c->step) >> 2;
868 c->step = (4 *
c->step - (
c->step >> 1)) >> 2;
872 c->step = ((
c->step >> 1) + add) >> 1;
875 add = 4 *
c->step - (
c->step >> 1);
876 c->step = 2 *
c->step;
879 add = (11 *
c->step) >> 1;
880 c->step = 3 *
c->step;
883 av_unreachable(
"There are cases for all control paths when bits is 3-bit");
896 int sign,
delta, add;
907 c->step = (3 *
c->step) >> 2;
911 c->step = (3 *
c->step) >> 2;
923 add = (11 *
c->step) >> 1;
924 c->step +=
c->step >> 2;
927 add = (15 *
c->step) >> 1;
928 c->step = 2 *
c->step;
932 add = (19 *
c->step) >> 1;
934 add = (21 *
c->step) >> 1;
935 c->step = (
c->step >> 1) + 2 *
c->step;
938 add = (25 *
c->step) >> 1;
939 c->step = 5 *
c->step;
942 av_unreachable(
"There are cases for all control paths when bits is 4-bit");
955 int sign,
delta, add;
966 c->step += (
c->step >> 2) - (
c->step >> 1);
971 c->step += (
c->step >> 3) - (
c->step >> 2);
975 c->step += (
c->step >> 4) - (
c->step >> 3);
980 c->step +=
c->step >> 3;
983 c->step +=
c->step >> 2;
986 c->step +=
c->step >> 1;
989 c->step = 2 *
c->step - (
c->step >> 3);
992 c->step = 2 *
c->step + (
c->step >> 3);
995 c->step = 2 *
c->step + (
c->step >> 1) - (
c->step >> 3);
998 c->step = 3 *
c->step - (
c->step >> 2);
1005 c->step = (7 *
c->step) >> 1;
1014 return c->predictor;
1029 int buf_size,
int *coded_samples,
int *approx_nb_samples)
1034 int has_coded_samples = 0;
1038 *approx_nb_samples = 0;
1046 if (buf_size < 76 * ch)
1051 if (buf_size < 34 * ch)
1068 nb_samples = buf_size * 2 / ch;
1085 if (header_size > 0)
1086 return (buf_size - header_size) * 2 / ch;
1092 has_coded_samples = 1;
1093 *coded_samples = bytestream2_get_le32u(gb);
1094 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
1100 has_coded_samples = 1;
1101 *coded_samples = bytestream2_get_le32(gb);
1102 *coded_samples -= *coded_samples % 28;
1103 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
1106 has_coded_samples = 1;
1107 *coded_samples = bytestream2_get_le32(gb);
1108 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
1111 nb_samples = (buf_size - ch) / ch * 2;
1118 has_coded_samples = 1;
1121 header_size = 4 + 9 * ch;
1122 *coded_samples = bytestream2_get_le32(gb);
1125 header_size = 4 + 5 * ch;
1126 *coded_samples = bytestream2_get_le32(gb);
1129 header_size = 4 + 5 * ch;
1130 *coded_samples = bytestream2_get_be32(gb);
1133 *coded_samples -= *coded_samples % 28;
1134 nb_samples = (buf_size - header_size) * 2 / ch;
1135 nb_samples -= nb_samples % 28;
1136 *approx_nb_samples = 1;
1141 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
1146 if (buf_size < 4 * ch)
1148 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
1153 nb_samples = (buf_size - 4 * ch) * 2 / ch;
1160 if (buf_size < 4 * ch)
1162 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
1164 CASE(ADPCM_IMA_XBOX,
1169 if (buf_size < 4 * ch)
1171 nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1;
1176 nb_samples = (buf_size - 6 * ch) * 2 / ch;
1181 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
1187 int samples_per_byte;
1193 if (!
s->status[0].step_index) {
1199 nb_samples += buf_size * samples_per_byte / ch;
1204 int buf_bits = buf_size * 8 - 2;
1205 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1206 int block_hdr_size = 22 * ch;
1207 int block_size = block_hdr_size + nbits * ch * 4095;
1208 int nblocks = buf_bits / block_size;
1209 int bits_left = buf_bits - nblocks * block_size;
1210 nb_samples = nblocks * 4096;
1212 nb_samples += 1 + (
bits_left - block_hdr_size) / (nbits * ch);
1218 nb_samples = buf_size * 14 / (8 * ch);
1221 has_coded_samples = 1;
1224 bytestream2_get_le32(gb) :
1225 bytestream2_get_be32(gb);
1226 buf_size -= 8 + 36 * ch;
1228 nb_samples = buf_size / 8 * 14;
1229 if (buf_size % 8 > 1)
1230 nb_samples += (buf_size % 8 - 1) * 2;
1231 *approx_nb_samples = 1;
1234 nb_samples = buf_size / (9 * ch) * 16;
1237 nb_samples = (buf_size / 128) * 224 / ch;
1240 nb_samples = buf_size / (21 * ch) * 32;
1244 nb_samples = buf_size / (16 * ch) * 28;
1250 nb_samples = buf_size / ch;
1260 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1267 int *got_frame_ptr,
AVPacket *avpkt)
1269 const uint8_t *buf = avpkt->
data;
1270 int buf_size = avpkt->
size;
1274 int16_t **samples_p;
1276 int nb_samples, coded_samples, approx_nb_samples,
ret;
1280 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1281 if (nb_samples <= 0) {
1287 frame->nb_samples = nb_samples;
1291 samples_p = (int16_t **)
frame->extended_data;
1295 if (coded_samples) {
1296 if (!approx_nb_samples && coded_samples != nb_samples)
1298 frame->nb_samples = nb_samples = coded_samples;
1338 for (
int m = 0; m < 64; m += 2) {
1339 int byte = bytestream2_get_byteu(&gb);
1364 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1367 samples = &samples_p[
i][1 + n * samples_per_block];
1368 for (
int j = 0; j < block_size; j++) {
1370 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1375 for (
int m = 0; m < samples_per_block; m++) {
1383 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1386 samples = &samples_p[
i][1 + n * 8];
1387 for (
int m = 0; m < 8; m += 2) {
1388 int v = bytestream2_get_byteu(&gb);
1396 CASE(ADPCM_IMA_XBOX,
1409 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1412 samples = &samples_p[
i][1 + n * 8];
1413 for (
int m = 0; m < 8; m += 2) {
1414 int v = bytestream2_get_byteu(&gb);
1420 frame->nb_samples--;
1424 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1427 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1428 if (
c->status[
i].step_index > 88
u) {
1430 i,
c->status[
i].step_index);
1438 for (
int n = nb_samples >> 1; n > 0; n--) {
1439 int v = bytestream2_get_byteu(&gb);
1447 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1449 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1451 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1452 int v = bytestream2_get_byteu(&gb);
1458 int block_predictor;
1463 block_predictor = bytestream2_get_byteu(&gb);
1464 if (block_predictor > 6) {
1476 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1477 int byte = bytestream2_get_byteu(&gb);
1483 block_predictor = bytestream2_get_byteu(&gb);
1484 if (block_predictor > 6) {
1492 block_predictor = bytestream2_get_byteu(&gb);
1493 if (block_predictor > 6) {
1501 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1503 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1506 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1507 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1508 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1509 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1512 if (st) *
samples++ =
c->status[1].sample2;
1514 if (st) *
samples++ =
c->status[1].sample1;
1515 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1516 int byte = bytestream2_get_byteu(&gb);
1525 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1526 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1531 for (
int n = 0; n < nb_samples; n += 2) {
1532 int v = bytestream2_get_byteu(&gb);
1536 for (
int n = 0; n < nb_samples; n += 2) {
1537 int v = bytestream2_get_byteu(&gb);
1554 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1555 int v = bytestream2_get_byteu(&gb);
1563 if (decode_top_nibble_next) { \
1564 nibble = last_byte >> 4; \
1565 decode_top_nibble_next = 0; \
1567 last_byte = bytestream2_get_byteu(&gb); \
1568 nibble = last_byte & 0x0F; \
1569 decode_top_nibble_next = 1; \
1574 int decode_top_nibble_next = 0;
1579 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1580 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1581 c->status[0].step_index = bytestream2_get_byteu(&gb);
1582 c->status[1].step_index = bytestream2_get_byteu(&gb);
1583 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1585 c->status[0].step_index,
c->status[1].step_index);
1589 diff_channel =
c->status[1].predictor;
1591 while (
samples < samples_end) {
1605 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1606 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1607 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1614 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1615 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1616 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1634 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1636 int v = bytestream2_get_byteu(&gb);
1649 CASE(ADPCM_IMA_MOFLEX,
1661 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1664 for (
int n = 0; n < 256; n += 2) {
1665 int v = bytestream2_get_byteu(&gb);
1672 CASE(ADPCM_IMA_DAT4,
1677 for (
int n = 0; n < nb_samples; n += 2) {
1678 int v = bytestream2_get_byteu(&gb);
1685 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1686 int v = bytestream2_get_byteu(&gb);
1692 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1693 int v = bytestream2_get_byteu(&gb);
1699 for (
int n = nb_samples / 2; n > 0; n--) {
1701 int v = bytestream2_get_byteu(&gb);
1709 for (
int n = nb_samples / 2; n > 0; n--) {
1711 int v = bytestream2_get_byteu(&gb);
1718 CASE(ADPCM_IMA_CUNNING,
1720 int16_t *smp = samples_p[
channel];
1721 for (
int n = 0; n < nb_samples / 2; n++) {
1722 int v = bytestream2_get_byteu(&gb);
1729 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1730 int v = bytestream2_get_byteu(&gb);
1746 for (
int n = 0; n < nb_samples / 2; n++) {
1749 byte[0] = bytestream2_get_byteu(&gb);
1751 byte[1] = bytestream2_get_byteu(&gb);
1761 if (
c->vqa_version == 3) {
1763 int16_t *smp = samples_p[
channel];
1765 for (
int n = nb_samples / 2; n > 0; n--) {
1766 int v = bytestream2_get_byteu(&gb);
1772 for (
int n = nb_samples / 2; n > 0; n--) {
1774 int v = bytestream2_get_byteu(&gb);
1784 int bytes_remaining,
block = 0;
1791 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
1792 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
1793 scale = bytestream2_get_le16(&gb);
1795 out[0] = history[1];
1796 out[1] = history[0];
1798 for (
int n = 0; n < 15; n++) {
1799 unsigned byte = bytestream2_get_byte(&gb);
1805 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1806 history[1] = history[0];
1807 history[0] =
out[2+n*2];
1809 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1810 history[1] = history[0];
1811 history[0] =
out[2+n*2+1];
1818 if (bytes_remaining > 0) {
1823 int16_t *out0 = samples_p[0];
1824 int16_t *out1 = samples_p[1];
1825 int samples_per_block = 28 * (3 -
channels) * 4;
1826 int sample_offset = 0;
1827 int bytes_remaining;
1830 &
c->status[0], &
c->status[1],
1834 sample_offset += samples_per_block;
1839 if (bytes_remaining > 0) {
1843 CASE(ADPCM_IMA_EA_EACS,
1844 for (
int i = 0;
i <= st;
i++) {
1845 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1846 if (
c->status[
i].step_index > 88
u) {
1848 i,
c->status[
i].step_index);
1852 for (
int i = 0;
i <= st;
i++) {
1853 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1858 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1859 int byte = bytestream2_get_byteu(&gb);
1864 CASE(ADPCM_IMA_EA_SEAD,
1865 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1866 int byte = bytestream2_get_byteu(&gb);
1872 int previous_left_sample, previous_right_sample;
1873 int current_left_sample, current_right_sample;
1874 int next_left_sample, next_right_sample;
1875 int coeff1l, coeff2l, coeff1r, coeff2r;
1876 int shift_left, shift_right;
1884 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1885 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1886 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1887 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1889 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1890 int byte = bytestream2_get_byteu(&gb);
1897 byte = bytestream2_get_byteu(&gb);
1898 shift_left = 20 - (
byte >> 4);
1899 shift_right = 20 - (
byte & 0x0F);
1902 shift_left = 20 - (
byte & 0x0F);
1905 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
1906 byte = bytestream2_get_byteu(&gb);
1907 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1909 next_left_sample = (next_left_sample +
1910 (current_left_sample * coeff1l) +
1911 (previous_left_sample * coeff2l) + 0x80) >> 8;
1913 previous_left_sample = current_left_sample;
1915 *
samples++ = current_left_sample;
1918 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1920 next_right_sample = (next_right_sample +
1921 (current_right_sample * coeff1r) +
1922 (previous_right_sample * coeff2r) + 0x80) >> 8;
1924 previous_right_sample = current_right_sample;
1926 *
samples++ = current_right_sample;
1928 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
1930 next_left_sample = (next_left_sample +
1931 (current_left_sample * coeff1l) +
1932 (previous_left_sample * coeff2l) + 0x80) >> 8;
1934 previous_left_sample = current_left_sample;
1937 *
samples++ = current_left_sample;
1943 CASE(ADPCM_EA_MAXIS_XA,
1947 int byte = bytestream2_get_byteu(&gb);
1948 for (
int i = 0;
i < 2;
i++)
1952 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1955 byte[0] = bytestream2_get_byteu(&gb);
1956 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1957 for (
int i = 4;
i >= 0;
i-=4) {
1971 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1980 int previous_sample, current_sample, next_sample;
1989 bytestream2_get_le32(&gb)) +
1996 samplesC = samples_p[
channel];
1999 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2000 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2002 current_sample =
c->status[
channel].predictor;
2003 previous_sample =
c->status[
channel].prev_sample;
2006 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2007 int byte = bytestream2_get_byte(&gb);
2009 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2010 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2012 for (
int count2 = 0; count2 < 28; count2++)
2013 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2017 shift = 20 - (
byte & 0x0F);
2019 for (
int count2 = 0; count2 < 28; count2++) {
2023 byte = bytestream2_get_byte(&gb);
2027 next_sample += (current_sample * coeff1) +
2028 (previous_sample * coeff2);
2031 previous_sample = current_sample;
2032 current_sample = next_sample;
2033 *samplesC++ = current_sample;
2039 }
else if (count != count1) {
2041 count =
FFMAX(count, count1);
2045 c->status[
channel].predictor = current_sample;
2046 c->status[
channel].prev_sample = previous_sample;
2050 frame->nb_samples = count * 28;
2059 for (
int n = 0; n < 4; n++,
s += 32) {
2061 for (
int i = 0;
i < 2;
i++)
2070 for (
int m = 2; m < 32; m += 2) {
2072 for (
int n = 0; n < 4; n++,
s += 32) {
2074 int byte = bytestream2_get_byteu(&gb);
2087 CASE(ADPCM_IMA_ACORN,
2091 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2098 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2099 int byte = bytestream2_get_byteu(&gb);
2117 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2118 c->status[0].step_index = bytestream2_get_byteu(&gb);
2120 if (
c->status[0].step_index > 88
u) {
2122 c->status[0].step_index);
2126 for (
int n = nb_samples >> 1; n > 0; n--) {
2127 int v = bytestream2_get_byteu(&gb);
2133 if (nb_samples & 1) {
2134 int v = bytestream2_get_byteu(&gb);
2144 CASE(ADPCM_IMA_SMJPEG,
2146 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2147 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2149 if (
c->status[
i].step_index > 88
u) {
2151 c->status[
i].step_index);
2156 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2157 int v = bytestream2_get_byteu(&gb);
2164 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2165 int v = bytestream2_get_byteu(&gb);
2170 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2171 CONFIG_ADPCM_SBPRO_4_DECODER
2175 if (!
c->status[0].step_index) {
2177 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2179 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2180 c->status[0].step_index = 1;
2184 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2185 int byte = bytestream2_get_byteu(&gb);
2192 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
2193 int byte = bytestream2_get_byteu(&gb);
2197 (
byte >> 2) & 0x07, 3, 0);
2202 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2203 int byte = bytestream2_get_byteu(&gb);
2207 (
byte >> 4) & 0x03, 2, 2);
2209 (
byte >> 2) & 0x03, 2, 2);
2221 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2222 int v = bytestream2_get_byteu(&gb);
2230 for (
int n = nb_samples >> 1; n > 0; n--) {
2231 int v = bytestream2_get_byteu(&gb);
2238 int samples_per_block;
2242 samples_per_block = avctx->
extradata[0] / 16;
2243 blocks = nb_samples / avctx->
extradata[0];
2245 samples_per_block = nb_samples / 16;
2249 for (
int m = 0; m < blocks; m++) {
2251 int prev1 =
c->status[
channel].sample1;
2252 int prev2 =
c->status[
channel].sample2;
2256 for (
int i = 0;
i < samples_per_block;
i++) {
2257 int byte = bytestream2_get_byteu(&gb);
2258 int scale = 1 << (
byte >> 4);
2259 int index =
byte & 0xf;
2264 for (
int n = 0; n < 16; n++) {
2270 byte = bytestream2_get_byteu(&gb);
2274 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2282 c->status[
channel].sample1 = prev1;
2283 c->status[
channel].sample2 = prev2;
2288 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2294 #define THP_GET16(g) \
2296 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2297 bytestream2_get_le16u(&(g)) : \
2298 bytestream2_get_be16u(&(g)), 16)
2309 for (
int n = 0; n < 16; n++)
2310 table[
i][n] = THP_GET16(tb);
2313 for (
int n = 0; n < 16; n++)
2314 table[
i][n] = THP_GET16(gb);
2316 if (!
c->has_status) {
2319 c->status[
i].sample1 = THP_GET16(gb);
2320 c->status[
i].sample2 = THP_GET16(gb);
2328 for (
int ch = 0; ch <
channels; ch++) {
2332 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2333 int byte = bytestream2_get_byteu(&gb);
2334 int index = (
byte >> 4) & 7;
2335 unsigned int exp =
byte & 0x0F;
2340 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2346 byte = bytestream2_get_byteu(&gb);
2350 sampledat = ((
c->status[ch].sample1 * factor1
2351 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2353 c->status[ch].sample2 =
c->status[ch].sample1;
2354 c->status[ch].sample1 = *
samples++;
2366 for (
int i = 0;
i < nb_samples / 28;
i++) {
2370 header = bytestream2_get_byteu(&gb);
2374 for (
int n = 0; n < 28; n++) {
2379 prev = (
c->status[
channel].sample1 * 0x3c);
2382 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2385 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2393 byte = bytestream2_get_byteu(&gb);
2399 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2402 c->status[
channel].sample1 = sampledat;
2417 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2420 filter = bytestream2_get_byteu(&gb);
2425 flag = bytestream2_get_byteu(&gb) & 0x7;
2428 for (
int n = 0; n < 28; n++) {
2434 byte = bytestream2_get_byteu(&gb);
2460 for (
int ch = 0; ch <
channels; ch++) {
2461 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2462 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2466 for (
int i = 0;
i < nb_samples;
i++)
2467 for (
int ch = 0; ch <
channels; ch++)
2499 control = bytestream2_get_byteu(&gb);
2500 shift = (control >> 4) + 2;
2502 for (
int n = 0; n < 16; n++) {
2503 int sample = bytestream2_get_byteu(&gb);
2511 for (
int n = 0; n < nb_samples *
channels; n++) {
2512 int v = bytestream2_get_byteu(&gb);
2517 for (
int n = nb_samples / 2; n > 0; n--) {
2519 int v = bytestream2_get_byteu(&gb);
2527 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");
2554 c->status[0].step =
c->status[1].step = 511;
2595 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2596 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2597 const FFCodec ff_ ## name_ ## _decoder = { \
2599 CODEC_LONG_NAME(long_name_), \
2600 .p.type = AVMEDIA_TYPE_AUDIO, \
2602 .p.capabilities = AV_CODEC_CAP_DR1, \
2603 CODEC_SAMPLEFMTS_ARRAY(sample_fmts_), \
2604 .priv_data_size = sizeof(ADPCMDecodeContext), \
2605 .init = adpcm_decode_init, \
2606 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2607 .flush = adpcm_flush, \
2609 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2610 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2611 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2612 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2613 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2614 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2615 name, sample_fmts, long_name)