39 #include "config_components.h"
69 #define CASE_0(codec_id, ...)
70 #define CASE_1(codec_id, ...) \
74 #define CASE_2(enabled, codec_id, ...) \
75 CASE_ ## enabled(codec_id, __VA_ARGS__)
76 #define CASE_3(config, codec_id, ...) \
77 CASE_2(config, codec_id, __VA_ARGS__)
78 #define CASE(codec, ...) \
79 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
91 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
92 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
110 -1, -1, -1, -1, 1, 2, 3, 4, -1
120 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
121 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
122 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
123 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
124 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
125 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
139 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
140 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
151 { 1, 5, 9, 13, 16, 20, 24, 28,
152 -1, -5, -9, -13, -16, -20, -24, -28, },
153 { 2, 6, 11, 15, 20, 24, 29, 33,
154 -2, -6, -11, -15, -20, -24, -29, -33, },
155 { 2, 7, 13, 18, 23, 28, 34, 39,
156 -2, -7, -13, -18, -23, -28, -34, -39, },
157 { 3, 9, 15, 21, 28, 34, 40, 46,
158 -3, -9, -15, -21, -28, -34, -40, -46, },
159 { 3, 11, 18, 26, 33, 41, 48, 56,
160 -3, -11, -18, -26, -33, -41, -48, -56, },
161 { 4, 13, 22, 31, 40, 49, 58, 67,
162 -4, -13, -22, -31, -40, -49, -58, -67, },
163 { 5, 16, 26, 37, 48, 59, 69, 80,
164 -5, -16, -26, -37, -48, -59, -69, -80, },
165 { 6, 19, 31, 44, 57, 70, 82, 95,
166 -6, -19, -31, -44, -57, -70, -82, -95, },
167 { 7, 22, 38, 53, 68, 83, 99, 114,
168 -7, -22, -38, -53, -68, -83, -99, -114, },
169 { 9, 27, 45, 63, 81, 99, 117, 135,
170 -9, -27, -45, -63, -81, -99, -117, -135, },
171 { 10, 32, 53, 75, 96, 118, 139, 161,
172 -10, -32, -53, -75, -96, -118, -139, -161, },
173 { 12, 38, 64, 90, 115, 141, 167, 193,
174 -12, -38, -64, -90, -115, -141, -167, -193, },
175 { 15, 45, 76, 106, 137, 167, 198, 228,
176 -15, -45, -76, -106, -137, -167, -198, -228, },
177 { 18, 54, 91, 127, 164, 200, 237, 273,
178 -18, -54, -91, -127, -164, -200, -237, -273, },
179 { 21, 65, 108, 152, 195, 239, 282, 326,
180 -21, -65, -108, -152, -195, -239, -282, -326, },
181 { 25, 77, 129, 181, 232, 284, 336, 388,
182 -25, -77, -129, -181, -232, -284, -336, -388, },
183 { 30, 92, 153, 215, 276, 338, 399, 461,
184 -30, -92, -153, -215, -276, -338, -399, -461, },
185 { 36, 109, 183, 256, 329, 402, 476, 549,
186 -36, -109, -183, -256, -329, -402, -476, -549, },
187 { 43, 130, 218, 305, 392, 479, 567, 654,
188 -43, -130, -218, -305, -392, -479, -567, -654, },
189 { 52, 156, 260, 364, 468, 572, 676, 780,
190 -52, -156, -260, -364, -468, -572, -676, -780, },
191 { 62, 186, 310, 434, 558, 682, 806, 930,
192 -62, -186, -310, -434, -558, -682, -806, -930, },
193 { 73, 221, 368, 516, 663, 811, 958, 1106,
194 -73, -221, -368, -516, -663, -811, -958, -1106, },
195 { 87, 263, 439, 615, 790, 966, 1142, 1318,
196 -87, -263, -439, -615, -790, -966, -1142, -1318, },
197 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
198 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
199 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
200 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
201 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
202 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
203 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
204 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
205 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
206 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
207 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
208 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
209 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
210 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
211 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
212 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
213 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
214 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
218 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
219 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
220 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
221 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
222 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
229 { -1, -1, -1, -1, 2, 4, 6, 8 },
230 { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
234 -1, -1, -1, 1, 4, 7, 10, 12,
238 8, 6, 4, 2, -1, -1, -1, -1,
239 -1, -1, -1, -1, 2, 4, 6, 8,
255 unsigned int min_channels = 1;
256 unsigned int max_channels = 2;
380 if ((nibble & 8) == 0)
390 c->step =
av_clip(
c->step * 2, 127, 24576);
421 step_index =
av_clip(step_index, 0, 88);
434 c->step_index = step_index;
436 return (int16_t)
c->predictor;
447 step_index =
av_clip(step_index, 0, 88);
457 c->step_index = step_index;
459 return (int16_t)
c->predictor;
473 c->step_index =
av_clip(step_index, 0, 88);
475 return (int16_t)
c->predictor;
488 step_index =
av_clip(step_index, 0, 60);
493 c->step_index = step_index;
506 step_index =
av_clip(step_index, 0, 88);
508 sign = nibble & (1 <<
shift);
516 c->step_index = step_index;
518 return (int16_t)
c->predictor;
529 step_index =
av_clip(step_index, 0, 88);
542 c->step_index = step_index;
551 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
552 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
554 c->sample2 =
c->sample1;
557 if (
c->idelta < 16)
c->idelta = 16;
558 if (
c->idelta > INT_MAX/768) {
560 c->idelta = INT_MAX/768;
572 step_index =
av_clip(step_index, 0, 48);
582 c->step_index = step_index;
584 return c->predictor * 16;
599 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
603 c->step =
av_clip(new_step, 511, 32767);
605 return (int16_t)
c->predictor;
612 sign = nibble & (1<<(
size-1));
622 else if (
delta == 0 &&
c->step > 0)
625 return (int16_t)
c->predictor;
653 int16_t
index =
c->step_index;
660 sample += lookup_sample >> 1;
662 sample += lookup_sample >> 2;
664 sample += lookup_sample >> 3;
666 sample += lookup_sample >> 4;
668 sample += lookup_sample >> 5;
670 sample += lookup_sample >> 6;
695 out0 += sample_offset;
699 out1 += sample_offset;
702 shift = 12 - (in[4+
i*2] & 15);
722 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
735 shift = 12 - (in[5+
i*2] & 15);
753 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
780 int k0, signmask, nb_bits, count;
781 int size = buf_size*8;
789 k0 = 1 << (nb_bits-2);
790 signmask = 1 << (nb_bits-1);
816 if (
delta & signmask)
817 c->status[
i].predictor -= vpdiff;
819 c->status[
i].predictor += vpdiff;
823 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
851 int sign,
delta, add;
862 c->step = (3 *
c->step) >> 2;
866 c->step = (4 *
c->step - (
c->step >> 1)) >> 2;
870 c->step = ((
c->step >> 1) + add) >> 1;
873 add = 4 *
c->step - (
c->step >> 1);
874 c->step = 2 *
c->step;
877 add = (11 *
c->step) >> 1;
878 c->step = 3 *
c->step;
881 av_unreachable(
"There are cases for all control paths when bits is 3-bit");
894 int sign,
delta, add;
905 c->step = (3 *
c->step) >> 2;
909 c->step = (3 *
c->step) >> 2;
921 add = (11 *
c->step) >> 1;
922 c->step +=
c->step >> 2;
925 add = (15 *
c->step) >> 1;
926 c->step = 2 *
c->step;
930 add = (19 *
c->step) >> 1;
932 add = (21 *
c->step) >> 1;
933 c->step = (
c->step >> 1) + 2 *
c->step;
936 add = (25 *
c->step) >> 1;
937 c->step = 5 *
c->step;
940 av_unreachable(
"There are cases for all control paths when bits is 4-bit");
953 int sign,
delta, add;
964 c->step += (
c->step >> 2) - (
c->step >> 1);
969 c->step += (
c->step >> 3) - (
c->step >> 2);
973 c->step += (
c->step >> 4) - (
c->step >> 3);
978 c->step +=
c->step >> 3;
981 c->step +=
c->step >> 2;
984 c->step +=
c->step >> 1;
987 c->step = 2 *
c->step - (
c->step >> 3);
990 c->step = 2 *
c->step + (
c->step >> 3);
993 c->step = 2 *
c->step + (
c->step >> 1) - (
c->step >> 3);
996 c->step = 3 *
c->step - (
c->step >> 2);
1003 c->step = (7 *
c->step) >> 1;
1012 return c->predictor;
1027 int buf_size,
int *coded_samples,
int *approx_nb_samples)
1032 int has_coded_samples = 0;
1036 *approx_nb_samples = 0;
1044 if (buf_size < 76 * ch)
1049 if (buf_size < 34 * ch)
1066 nb_samples = buf_size * 2 / ch;
1083 if (header_size > 0)
1084 return (buf_size - header_size) * 2 / ch;
1090 has_coded_samples = 1;
1091 *coded_samples = bytestream2_get_le32u(gb);
1092 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
1098 has_coded_samples = 1;
1099 *coded_samples = bytestream2_get_le32(gb);
1100 *coded_samples -= *coded_samples % 28;
1101 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
1104 has_coded_samples = 1;
1105 *coded_samples = bytestream2_get_le32(gb);
1106 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
1109 nb_samples = (buf_size - ch) / ch * 2;
1116 has_coded_samples = 1;
1119 header_size = 4 + 9 * ch;
1120 *coded_samples = bytestream2_get_le32(gb);
1123 header_size = 4 + 5 * ch;
1124 *coded_samples = bytestream2_get_le32(gb);
1127 header_size = 4 + 5 * ch;
1128 *coded_samples = bytestream2_get_be32(gb);
1131 *coded_samples -= *coded_samples % 28;
1132 nb_samples = (buf_size - header_size) * 2 / ch;
1133 nb_samples -= nb_samples % 28;
1134 *approx_nb_samples = 1;
1139 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
1144 if (buf_size < 4 * ch)
1146 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
1151 nb_samples = (buf_size - 4 * ch) * 2 / ch;
1158 if (buf_size < 4 * ch)
1160 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
1162 CASE(ADPCM_IMA_XBOX,
1167 if (buf_size < 4 * ch)
1169 nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1;
1174 nb_samples = (buf_size - 6 * ch) * 2 / ch;
1179 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
1185 int samples_per_byte;
1191 if (!
s->status[0].step_index) {
1197 nb_samples += buf_size * samples_per_byte / ch;
1202 int buf_bits = buf_size * 8 - 2;
1203 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1204 int block_hdr_size = 22 * ch;
1205 int block_size = block_hdr_size + nbits * ch * 4095;
1206 int nblocks = buf_bits / block_size;
1207 int bits_left = buf_bits - nblocks * block_size;
1208 nb_samples = nblocks * 4096;
1210 nb_samples += 1 + (
bits_left - block_hdr_size) / (nbits * ch);
1216 nb_samples = buf_size * 14 / (8 * ch);
1219 has_coded_samples = 1;
1222 bytestream2_get_le32(gb) :
1223 bytestream2_get_be32(gb);
1224 buf_size -= 8 + 36 * ch;
1226 nb_samples = buf_size / 8 * 14;
1227 if (buf_size % 8 > 1)
1228 nb_samples += (buf_size % 8 - 1) * 2;
1229 *approx_nb_samples = 1;
1232 nb_samples = buf_size / (9 * ch) * 16;
1235 nb_samples = (buf_size / 128) * 224 / ch;
1238 nb_samples = buf_size / (21 * ch) * 32;
1242 nb_samples = buf_size / (16 * ch) * 28;
1248 nb_samples = buf_size / ch;
1258 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1265 int *got_frame_ptr,
AVPacket *avpkt)
1267 const uint8_t *buf = avpkt->
data;
1268 int buf_size = avpkt->
size;
1272 int16_t **samples_p;
1274 int nb_samples, coded_samples, approx_nb_samples,
ret;
1278 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1279 if (nb_samples <= 0) {
1285 frame->nb_samples = nb_samples;
1289 samples_p = (int16_t **)
frame->extended_data;
1293 if (coded_samples) {
1294 if (!approx_nb_samples && coded_samples != nb_samples)
1296 frame->nb_samples = nb_samples = coded_samples;
1336 for (
int m = 0; m < 64; m += 2) {
1337 int byte = bytestream2_get_byteu(&gb);
1362 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1365 samples = &samples_p[
i][1 + n * samples_per_block];
1366 for (
int j = 0; j < block_size; j++) {
1368 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1373 for (
int m = 0; m < samples_per_block; m++) {
1381 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1384 samples = &samples_p[
i][1 + n * 8];
1385 for (
int m = 0; m < 8; m += 2) {
1386 int v = bytestream2_get_byteu(&gb);
1394 CASE(ADPCM_IMA_XBOX,
1407 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1410 samples = &samples_p[
i][1 + n * 8];
1411 for (
int m = 0; m < 8; m += 2) {
1412 int v = bytestream2_get_byteu(&gb);
1418 frame->nb_samples--;
1422 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1425 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1426 if (
c->status[
i].step_index > 88
u) {
1428 i,
c->status[
i].step_index);
1436 for (
int n = nb_samples >> 1; n > 0; n--) {
1437 int v = bytestream2_get_byteu(&gb);
1445 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1447 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1449 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1450 int v = bytestream2_get_byteu(&gb);
1456 int block_predictor;
1461 block_predictor = bytestream2_get_byteu(&gb);
1462 if (block_predictor > 6) {
1474 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1475 int byte = bytestream2_get_byteu(&gb);
1481 block_predictor = bytestream2_get_byteu(&gb);
1482 if (block_predictor > 6) {
1490 block_predictor = bytestream2_get_byteu(&gb);
1491 if (block_predictor > 6) {
1499 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1501 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1504 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1505 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1506 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1507 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1510 if (st) *
samples++ =
c->status[1].sample2;
1512 if (st) *
samples++ =
c->status[1].sample1;
1513 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1514 int byte = bytestream2_get_byteu(&gb);
1523 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1524 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1529 for (
int n = 0; n < nb_samples; n += 2) {
1530 int v = bytestream2_get_byteu(&gb);
1534 for (
int n = 0; n < nb_samples; n += 2) {
1535 int v = bytestream2_get_byteu(&gb);
1552 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1553 int v = bytestream2_get_byteu(&gb);
1561 if (decode_top_nibble_next) { \
1562 nibble = last_byte >> 4; \
1563 decode_top_nibble_next = 0; \
1565 last_byte = bytestream2_get_byteu(&gb); \
1566 nibble = last_byte & 0x0F; \
1567 decode_top_nibble_next = 1; \
1572 int decode_top_nibble_next = 0;
1577 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1578 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1579 c->status[0].step_index = bytestream2_get_byteu(&gb);
1580 c->status[1].step_index = bytestream2_get_byteu(&gb);
1581 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1583 c->status[0].step_index,
c->status[1].step_index);
1587 diff_channel =
c->status[1].predictor;
1589 while (
samples < samples_end) {
1603 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1604 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1605 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1612 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1613 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1614 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1632 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1634 int v = bytestream2_get_byteu(&gb);
1647 CASE(ADPCM_IMA_MOFLEX,
1659 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1662 for (
int n = 0; n < 256; n += 2) {
1663 int v = bytestream2_get_byteu(&gb);
1670 CASE(ADPCM_IMA_DAT4,
1675 for (
int n = 0; n < nb_samples; n += 2) {
1676 int v = bytestream2_get_byteu(&gb);
1683 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1684 int v = bytestream2_get_byteu(&gb);
1690 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1691 int v = bytestream2_get_byteu(&gb);
1697 for (
int n = nb_samples / 2; n > 0; n--) {
1699 int v = bytestream2_get_byteu(&gb);
1707 for (
int n = nb_samples / 2; n > 0; n--) {
1709 int v = bytestream2_get_byteu(&gb);
1716 CASE(ADPCM_IMA_CUNNING,
1718 int16_t *smp = samples_p[
channel];
1719 for (
int n = 0; n < nb_samples / 2; n++) {
1720 int v = bytestream2_get_byteu(&gb);
1727 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1728 int v = bytestream2_get_byteu(&gb);
1744 for (
int n = 0; n < nb_samples / 2; n++) {
1747 byte[0] = bytestream2_get_byteu(&gb);
1749 byte[1] = bytestream2_get_byteu(&gb);
1759 if (
c->vqa_version == 3) {
1761 int16_t *smp = samples_p[
channel];
1763 for (
int n = nb_samples / 2; n > 0; n--) {
1764 int v = bytestream2_get_byteu(&gb);
1770 for (
int n = nb_samples / 2; n > 0; n--) {
1772 int v = bytestream2_get_byteu(&gb);
1782 int bytes_remaining,
block = 0;
1789 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
1790 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
1791 scale = bytestream2_get_le16(&gb);
1793 out[0] = history[1];
1794 out[1] = history[0];
1796 for (
int n = 0; n < 15; n++) {
1797 unsigned byte = bytestream2_get_byte(&gb);
1803 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1804 history[1] = history[0];
1805 history[0] =
out[2+n*2];
1807 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1808 history[1] = history[0];
1809 history[0] =
out[2+n*2+1];
1816 if (bytes_remaining > 0) {
1821 int16_t *out0 = samples_p[0];
1822 int16_t *out1 = samples_p[1];
1823 int samples_per_block = 28 * (3 -
channels) * 4;
1824 int sample_offset = 0;
1825 int bytes_remaining;
1828 &
c->status[0], &
c->status[1],
1832 sample_offset += samples_per_block;
1837 if (bytes_remaining > 0) {
1841 CASE(ADPCM_IMA_EA_EACS,
1842 for (
int i = 0;
i <= st;
i++) {
1843 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1844 if (
c->status[
i].step_index > 88
u) {
1846 i,
c->status[
i].step_index);
1850 for (
int i = 0;
i <= st;
i++) {
1851 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1856 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1857 int byte = bytestream2_get_byteu(&gb);
1862 CASE(ADPCM_IMA_EA_SEAD,
1863 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1864 int byte = bytestream2_get_byteu(&gb);
1870 int previous_left_sample, previous_right_sample;
1871 int current_left_sample, current_right_sample;
1872 int next_left_sample, next_right_sample;
1873 int coeff1l, coeff2l, coeff1r, coeff2r;
1874 int shift_left, shift_right;
1882 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1883 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1884 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1885 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1887 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1888 int byte = bytestream2_get_byteu(&gb);
1895 byte = bytestream2_get_byteu(&gb);
1896 shift_left = 20 - (
byte >> 4);
1897 shift_right = 20 - (
byte & 0x0F);
1900 shift_left = 20 - (
byte & 0x0F);
1903 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
1904 byte = bytestream2_get_byteu(&gb);
1905 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1907 next_left_sample = (next_left_sample +
1908 (current_left_sample * coeff1l) +
1909 (previous_left_sample * coeff2l) + 0x80) >> 8;
1911 previous_left_sample = current_left_sample;
1913 *
samples++ = current_left_sample;
1916 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1918 next_right_sample = (next_right_sample +
1919 (current_right_sample * coeff1r) +
1920 (previous_right_sample * coeff2r) + 0x80) >> 8;
1922 previous_right_sample = current_right_sample;
1924 *
samples++ = current_right_sample;
1926 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
1928 next_left_sample = (next_left_sample +
1929 (current_left_sample * coeff1l) +
1930 (previous_left_sample * coeff2l) + 0x80) >> 8;
1932 previous_left_sample = current_left_sample;
1935 *
samples++ = current_left_sample;
1941 CASE(ADPCM_EA_MAXIS_XA,
1945 int byte = bytestream2_get_byteu(&gb);
1946 for (
int i = 0;
i < 2;
i++)
1950 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1953 byte[0] = bytestream2_get_byteu(&gb);
1954 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1955 for (
int i = 4;
i >= 0;
i-=4) {
1969 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1978 int previous_sample, current_sample, next_sample;
1987 bytestream2_get_le32(&gb)) +
1994 samplesC = samples_p[
channel];
1997 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1998 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2000 current_sample =
c->status[
channel].predictor;
2001 previous_sample =
c->status[
channel].prev_sample;
2004 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2005 int byte = bytestream2_get_byte(&gb);
2007 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2008 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2010 for (
int count2 = 0; count2 < 28; count2++)
2011 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2015 shift = 20 - (
byte & 0x0F);
2017 for (
int count2 = 0; count2 < 28; count2++) {
2021 byte = bytestream2_get_byte(&gb);
2025 next_sample += (current_sample * coeff1) +
2026 (previous_sample * coeff2);
2029 previous_sample = current_sample;
2030 current_sample = next_sample;
2031 *samplesC++ = current_sample;
2037 }
else if (count != count1) {
2039 count =
FFMAX(count, count1);
2043 c->status[
channel].predictor = current_sample;
2044 c->status[
channel].prev_sample = previous_sample;
2048 frame->nb_samples = count * 28;
2057 for (
int n = 0; n < 4; n++,
s += 32) {
2059 for (
int i = 0;
i < 2;
i++)
2068 for (
int m = 2; m < 32; m += 2) {
2070 for (
int n = 0; n < 4; n++,
s += 32) {
2072 int byte = bytestream2_get_byteu(&gb);
2085 CASE(ADPCM_IMA_ACORN,
2089 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2096 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2097 int byte = bytestream2_get_byteu(&gb);
2115 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2116 c->status[0].step_index = bytestream2_get_byteu(&gb);
2118 if (
c->status[0].step_index > 88
u) {
2120 c->status[0].step_index);
2124 for (
int n = nb_samples >> 1; n > 0; n--) {
2125 int v = bytestream2_get_byteu(&gb);
2131 if (nb_samples & 1) {
2132 int v = bytestream2_get_byteu(&gb);
2142 CASE(ADPCM_IMA_SMJPEG,
2144 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2145 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2147 if (
c->status[
i].step_index > 88
u) {
2149 c->status[
i].step_index);
2154 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2155 int v = bytestream2_get_byteu(&gb);
2162 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2163 int v = bytestream2_get_byteu(&gb);
2168 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2169 CONFIG_ADPCM_SBPRO_4_DECODER
2173 if (!
c->status[0].step_index) {
2175 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2177 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2178 c->status[0].step_index = 1;
2182 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2183 int byte = bytestream2_get_byteu(&gb);
2190 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
2191 int byte = bytestream2_get_byteu(&gb);
2195 (
byte >> 2) & 0x07, 3, 0);
2200 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2201 int byte = bytestream2_get_byteu(&gb);
2205 (
byte >> 4) & 0x03, 2, 2);
2207 (
byte >> 2) & 0x03, 2, 2);
2219 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2220 int v = bytestream2_get_byteu(&gb);
2228 for (
int n = nb_samples >> 1; n > 0; n--) {
2229 int v = bytestream2_get_byteu(&gb);
2236 int samples_per_block;
2240 samples_per_block = avctx->
extradata[0] / 16;
2241 blocks = nb_samples / avctx->
extradata[0];
2243 samples_per_block = nb_samples / 16;
2247 for (
int m = 0; m < blocks; m++) {
2249 int prev1 =
c->status[
channel].sample1;
2250 int prev2 =
c->status[
channel].sample2;
2254 for (
int i = 0;
i < samples_per_block;
i++) {
2255 int byte = bytestream2_get_byteu(&gb);
2256 int scale = 1 << (
byte >> 4);
2257 int index =
byte & 0xf;
2262 for (
int n = 0; n < 16; n++) {
2268 byte = bytestream2_get_byteu(&gb);
2272 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2280 c->status[
channel].sample1 = prev1;
2281 c->status[
channel].sample2 = prev2;
2286 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2292 #define THP_GET16(g) \
2294 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2295 bytestream2_get_le16u(&(g)) : \
2296 bytestream2_get_be16u(&(g)), 16)
2307 for (
int n = 0; n < 16; n++)
2308 table[
i][n] = THP_GET16(tb);
2311 for (
int n = 0; n < 16; n++)
2312 table[
i][n] = THP_GET16(gb);
2314 if (!
c->has_status) {
2317 c->status[
i].sample1 = THP_GET16(gb);
2318 c->status[
i].sample2 = THP_GET16(gb);
2326 for (
int ch = 0; ch <
channels; ch++) {
2330 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2331 int byte = bytestream2_get_byteu(&gb);
2332 int index = (
byte >> 4) & 7;
2333 unsigned int exp =
byte & 0x0F;
2338 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2344 byte = bytestream2_get_byteu(&gb);
2348 sampledat = ((
c->status[ch].sample1 * factor1
2349 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2351 c->status[ch].sample2 =
c->status[ch].sample1;
2352 c->status[ch].sample1 = *
samples++;
2364 for (
int i = 0;
i < nb_samples / 28;
i++) {
2368 header = bytestream2_get_byteu(&gb);
2372 for (
int n = 0; n < 28; n++) {
2377 prev = (
c->status[
channel].sample1 * 0x3c);
2380 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2383 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2391 byte = bytestream2_get_byteu(&gb);
2397 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2400 c->status[
channel].sample1 = sampledat;
2415 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2418 filter = bytestream2_get_byteu(&gb);
2423 flag = bytestream2_get_byteu(&gb) & 0x7;
2426 for (
int n = 0; n < 28; n++) {
2432 byte = bytestream2_get_byteu(&gb);
2458 for (
int ch = 0; ch <
channels; ch++) {
2459 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2460 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2464 for (
int i = 0;
i < nb_samples;
i++)
2465 for (
int ch = 0; ch <
channels; ch++)
2497 control = bytestream2_get_byteu(&gb);
2498 shift = (control >> 4) + 2;
2500 for (
int n = 0; n < 16; n++) {
2501 int sample = bytestream2_get_byteu(&gb);
2509 for (
int n = 0; n < nb_samples *
channels; n++) {
2510 int v = bytestream2_get_byteu(&gb);
2515 for (
int n = nb_samples / 2; n > 0; n--) {
2517 int v = bytestream2_get_byteu(&gb);
2525 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");
2552 c->status[0].step =
c->status[1].step = 511;
2593 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2594 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2595 const FFCodec ff_ ## name_ ## _decoder = { \
2597 CODEC_LONG_NAME(long_name_), \
2598 .p.type = AVMEDIA_TYPE_AUDIO, \
2600 .p.capabilities = AV_CODEC_CAP_DR1, \
2601 CODEC_SAMPLEFMTS_ARRAY(sample_fmts_), \
2602 .priv_data_size = sizeof(ADPCMDecodeContext), \
2603 .init = adpcm_decode_init, \
2604 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2605 .flush = adpcm_flush, \
2607 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2608 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2609 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2610 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2611 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2612 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2613 name, sample_fmts, long_name)