64 #define CASE_0(codec_id, ...)
65 #define CASE_1(codec_id, ...) \
69 #define CASE_2(enabled, codec_id, ...) \
70 CASE_ ## enabled(codec_id, __VA_ARGS__)
71 #define CASE_3(config, codec_id, ...) \
72 CASE_2(config, codec_id, __VA_ARGS__)
73 #define CASE(codec, ...) \
74 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
86 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
87 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
105 -1, -1, -1, -1, 1, 2, 3, 4, -1
115 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
116 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
117 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
118 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
119 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
120 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
134 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
135 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
146 { 1, 5, 9, 13, 16, 20, 24, 28,
147 -1, -5, -9, -13, -16, -20, -24, -28, },
148 { 2, 6, 11, 15, 20, 24, 29, 33,
149 -2, -6, -11, -15, -20, -24, -29, -33, },
150 { 2, 7, 13, 18, 23, 28, 34, 39,
151 -2, -7, -13, -18, -23, -28, -34, -39, },
152 { 3, 9, 15, 21, 28, 34, 40, 46,
153 -3, -9, -15, -21, -28, -34, -40, -46, },
154 { 3, 11, 18, 26, 33, 41, 48, 56,
155 -3, -11, -18, -26, -33, -41, -48, -56, },
156 { 4, 13, 22, 31, 40, 49, 58, 67,
157 -4, -13, -22, -31, -40, -49, -58, -67, },
158 { 5, 16, 26, 37, 48, 59, 69, 80,
159 -5, -16, -26, -37, -48, -59, -69, -80, },
160 { 6, 19, 31, 44, 57, 70, 82, 95,
161 -6, -19, -31, -44, -57, -70, -82, -95, },
162 { 7, 22, 38, 53, 68, 83, 99, 114,
163 -7, -22, -38, -53, -68, -83, -99, -114, },
164 { 9, 27, 45, 63, 81, 99, 117, 135,
165 -9, -27, -45, -63, -81, -99, -117, -135, },
166 { 10, 32, 53, 75, 96, 118, 139, 161,
167 -10, -32, -53, -75, -96, -118, -139, -161, },
168 { 12, 38, 64, 90, 115, 141, 167, 193,
169 -12, -38, -64, -90, -115, -141, -167, -193, },
170 { 15, 45, 76, 106, 137, 167, 198, 228,
171 -15, -45, -76, -106, -137, -167, -198, -228, },
172 { 18, 54, 91, 127, 164, 200, 237, 273,
173 -18, -54, -91, -127, -164, -200, -237, -273, },
174 { 21, 65, 108, 152, 195, 239, 282, 326,
175 -21, -65, -108, -152, -195, -239, -282, -326, },
176 { 25, 77, 129, 181, 232, 284, 336, 388,
177 -25, -77, -129, -181, -232, -284, -336, -388, },
178 { 30, 92, 153, 215, 276, 338, 399, 461,
179 -30, -92, -153, -215, -276, -338, -399, -461, },
180 { 36, 109, 183, 256, 329, 402, 476, 549,
181 -36, -109, -183, -256, -329, -402, -476, -549, },
182 { 43, 130, 218, 305, 392, 479, 567, 654,
183 -43, -130, -218, -305, -392, -479, -567, -654, },
184 { 52, 156, 260, 364, 468, 572, 676, 780,
185 -52, -156, -260, -364, -468, -572, -676, -780, },
186 { 62, 186, 310, 434, 558, 682, 806, 930,
187 -62, -186, -310, -434, -558, -682, -806, -930, },
188 { 73, 221, 368, 516, 663, 811, 958, 1106,
189 -73, -221, -368, -516, -663, -811, -958, -1106, },
190 { 87, 263, 439, 615, 790, 966, 1142, 1318,
191 -87, -263, -439, -615, -790, -966, -1142, -1318, },
192 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
193 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
194 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
195 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
196 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
197 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
198 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
199 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
200 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
201 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
202 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
203 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
204 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
205 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
206 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
207 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
208 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
209 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
213 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
214 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
215 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
216 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
217 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
224 { -1, -1, -1, -1, 2, 4, 6, 8 },
225 { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
229 -1, -1, -1, 1, 4, 7, 10, 12,
233 8, 6, 4, 2, -1, -1, -1, -1,
234 -1, -1, -1, -1, 2, 4, 6, 8,
250 unsigned int min_channels = 1;
251 unsigned int max_channels = 2;
359 if ((nibble & 8) == 0)
369 c->step =
av_clip(
c->step * 2, 127, 24576);
400 step_index =
av_clip(step_index, 0, 88);
413 c->step_index = step_index;
415 return (int16_t)
c->predictor;
426 step_index =
av_clip(step_index, 0, 88);
436 c->step_index = step_index;
438 return (int16_t)
c->predictor;
452 c->step_index =
av_clip(step_index, 0, 88);
454 return (int16_t)
c->predictor;
467 step_index =
av_clip(step_index, 0, 60);
472 c->step_index = step_index;
485 step_index =
av_clip(step_index, 0, 88);
487 sign = nibble & (1 <<
shift);
495 c->step_index = step_index;
497 return (int16_t)
c->predictor;
508 step_index =
av_clip(step_index, 0, 88);
521 c->step_index = step_index;
530 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
531 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
533 c->sample2 =
c->sample1;
536 if (
c->idelta < 16)
c->idelta = 16;
537 if (
c->idelta > INT_MAX/768) {
539 c->idelta = INT_MAX/768;
551 step_index =
av_clip(step_index, 0, 48);
561 c->step_index = step_index;
563 return c->predictor * 16;
578 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
582 c->step =
av_clip(new_step, 511, 32767);
584 return (int16_t)
c->predictor;
591 sign = nibble & (1<<(
size-1));
601 else if (
delta == 0 &&
c->step > 0)
604 return (int16_t)
c->predictor;
632 int16_t
index =
c->step_index;
639 sample += lookup_sample >> 1;
641 sample += lookup_sample >> 2;
643 sample += lookup_sample >> 3;
645 sample += lookup_sample >> 4;
647 sample += lookup_sample >> 5;
649 sample += lookup_sample >> 6;
674 out0 += sample_offset;
678 out1 += sample_offset;
681 shift = 12 - (in[4+
i*2] & 15);
701 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
714 shift = 12 - (in[5+
i*2] & 15);
732 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
758 int k0, signmask, nb_bits, count;
759 int size = buf_size*8;
767 k0 = 1 << (nb_bits-2);
768 signmask = 1 << (nb_bits-1);
794 if (
delta & signmask)
795 c->status[
i].predictor -= vpdiff;
797 c->status[
i].predictor += vpdiff;
801 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
839 int buf_size,
int *coded_samples,
int *approx_nb_samples)
844 int has_coded_samples = 0;
848 *approx_nb_samples = 0;
856 if (buf_size < 76 * ch)
861 if (buf_size < 34 * ch)
878 nb_samples = buf_size * 2 / ch;
896 return (buf_size - header_size) * 2 / ch;
902 has_coded_samples = 1;
903 *coded_samples = bytestream2_get_le32u(gb);
904 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
908 has_coded_samples = 1;
909 *coded_samples = bytestream2_get_le32(gb);
910 *coded_samples -= *coded_samples % 28;
911 nb_samples = (buf_size - 12) / 30 * 28;
914 has_coded_samples = 1;
915 *coded_samples = bytestream2_get_le32(gb);
916 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
919 nb_samples = (buf_size - ch) / ch * 2;
926 has_coded_samples = 1;
929 header_size = 4 + 9 * ch;
930 *coded_samples = bytestream2_get_le32(gb);
933 header_size = 4 + 5 * ch;
934 *coded_samples = bytestream2_get_le32(gb);
937 header_size = 4 + 5 * ch;
938 *coded_samples = bytestream2_get_be32(gb);
941 *coded_samples -= *coded_samples % 28;
942 nb_samples = (buf_size - header_size) * 2 / ch;
943 nb_samples -= nb_samples % 28;
944 *approx_nb_samples = 1;
949 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
954 if (buf_size < 4 * ch)
956 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
961 nb_samples = (buf_size - 4 * ch) * 2 / ch;
968 if (buf_size < 4 * ch)
970 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
975 nb_samples = (buf_size - 6 * ch) * 2 / ch;
980 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
986 int samples_per_byte;
992 if (!
s->status[0].step_index) {
998 nb_samples += buf_size * samples_per_byte / ch;
1003 int buf_bits = buf_size * 8 - 2;
1004 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1005 int block_hdr_size = 22 * ch;
1006 int block_size = block_hdr_size + nbits * ch * 4095;
1007 int nblocks = buf_bits / block_size;
1008 int bits_left = buf_bits - nblocks * block_size;
1009 nb_samples = nblocks * 4096;
1010 if (bits_left >= block_hdr_size)
1011 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
1017 nb_samples = buf_size * 14 / (8 * ch);
1020 has_coded_samples = 1;
1023 bytestream2_get_le32(gb) :
1024 bytestream2_get_be32(gb);
1025 buf_size -= 8 + 36 * ch;
1027 nb_samples = buf_size / 8 * 14;
1028 if (buf_size % 8 > 1)
1029 nb_samples += (buf_size % 8 - 1) * 2;
1030 *approx_nb_samples = 1;
1033 nb_samples = buf_size / (9 * ch) * 16;
1036 nb_samples = (buf_size / 128) * 224 / ch;
1040 nb_samples = buf_size / (16 * ch) * 28;
1046 nb_samples = buf_size / ch;
1051 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1058 int *got_frame_ptr,
AVPacket *avpkt)
1061 const uint8_t *buf = avpkt->
data;
1062 int buf_size = avpkt->
size;
1065 int16_t **samples_p;
1067 int nb_samples, coded_samples, approx_nb_samples,
ret;
1071 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1072 if (nb_samples <= 0) {
1078 frame->nb_samples = nb_samples;
1082 samples_p = (int16_t **)
frame->extended_data;
1086 if (coded_samples) {
1087 if (!approx_nb_samples && coded_samples != nb_samples)
1089 frame->nb_samples = nb_samples = coded_samples;
1129 for (
int m = 0; m < 64; m += 2) {
1130 int byte = bytestream2_get_byteu(&gb);
1155 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1158 samples = &samples_p[
i][1 + n * samples_per_block];
1159 for (
int j = 0; j < block_size; j++) {
1161 (j % 4) + (j / 4) * (avctx->
channels * 4) +
i * 4];
1166 for (
int m = 0; m < samples_per_block; m++) {
1174 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1177 samples = &samples_p[
i][1 + n * 8];
1178 for (
int m = 0; m < 8; m += 2) {
1179 int v = bytestream2_get_byteu(&gb);
1189 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1192 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1193 if (
c->status[
i].step_index > 88
u) {
1195 i,
c->status[
i].step_index);
1203 for (
int n = nb_samples >> 1; n > 0; n--) {
1204 int v = bytestream2_get_byteu(&gb);
1212 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1214 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1216 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1217 int v = bytestream2_get_byteu(&gb);
1223 int block_predictor;
1228 block_predictor = bytestream2_get_byteu(&gb);
1229 if (block_predictor > 6) {
1241 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1242 int byte = bytestream2_get_byteu(&gb);
1248 block_predictor = bytestream2_get_byteu(&gb);
1249 if (block_predictor > 6) {
1257 block_predictor = bytestream2_get_byteu(&gb);
1258 if (block_predictor > 6) {
1266 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1268 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1271 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1272 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1273 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1274 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1277 if (st) *
samples++ =
c->status[1].sample2;
1279 if (st) *
samples++ =
c->status[1].sample1;
1280 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1281 int byte = bytestream2_get_byteu(&gb);
1290 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1291 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1296 for (
int n = 0; n < nb_samples; n += 2) {
1297 int v = bytestream2_get_byteu(&gb);
1301 for (
int n = 0; n < nb_samples; n += 2) {
1302 int v = bytestream2_get_byteu(&gb);
1319 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1320 int v = bytestream2_get_byteu(&gb);
1328 if (decode_top_nibble_next) { \
1329 nibble = last_byte >> 4; \
1330 decode_top_nibble_next = 0; \
1332 last_byte = bytestream2_get_byteu(&gb); \
1333 nibble = last_byte & 0x0F; \
1334 decode_top_nibble_next = 1; \
1339 int decode_top_nibble_next = 0;
1344 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1345 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1346 c->status[0].step_index = bytestream2_get_byteu(&gb);
1347 c->status[1].step_index = bytestream2_get_byteu(&gb);
1348 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1350 c->status[0].step_index,
c->status[1].step_index);
1354 diff_channel =
c->status[1].predictor;
1356 while (
samples < samples_end) {
1370 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1371 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1372 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1379 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1380 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1381 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1399 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1401 int v = bytestream2_get_byteu(&gb);
1414 CASE(ADPCM_IMA_MOFLEX,
1426 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1429 for (
int n = 0; n < 256; n += 2) {
1430 int v = bytestream2_get_byteu(&gb);
1437 CASE(ADPCM_IMA_DAT4,
1442 for (
int n = 0; n < nb_samples; n += 2) {
1443 int v = bytestream2_get_byteu(&gb);
1450 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1451 int v = bytestream2_get_byteu(&gb);
1457 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1458 int v = bytestream2_get_byteu(&gb);
1464 for (
int n = nb_samples / 2; n > 0; n--) {
1466 int v = bytestream2_get_byteu(&gb);
1474 for (
int n = nb_samples / 2; n > 0; n--) {
1476 int v = bytestream2_get_byteu(&gb);
1483 CASE(ADPCM_IMA_CUNNING,
1485 int16_t *smp = samples_p[
channel];
1486 for (
int n = 0; n < nb_samples / 2; n++) {
1487 int v = bytestream2_get_byteu(&gb);
1494 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1495 int v = bytestream2_get_byteu(&gb);
1511 for (
int n = 0; n < nb_samples / 2; n++) {
1514 byte[0] = bytestream2_get_byteu(&gb);
1516 byte[1] = bytestream2_get_byteu(&gb);
1526 if (
c->vqa_version == 3) {
1528 int16_t *smp = samples_p[
channel];
1530 for (
int n = nb_samples / 2; n > 0; n--) {
1531 int v = bytestream2_get_byteu(&gb);
1537 for (
int n = nb_samples / 2; n > 0; n--) {
1539 int v = bytestream2_get_byteu(&gb);
1549 int16_t *out0 = samples_p[0];
1550 int16_t *out1 = samples_p[1];
1551 int samples_per_block = 28 * (3 - avctx->
channels) * 4;
1552 int sample_offset = 0;
1553 int bytes_remaining;
1556 &
c->status[0], &
c->status[1],
1557 avctx->
channels, sample_offset)) < 0)
1560 sample_offset += samples_per_block;
1565 if (bytes_remaining > 0) {
1569 CASE(ADPCM_IMA_EA_EACS,
1570 for (
int i = 0;
i <= st;
i++) {
1571 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1572 if (
c->status[
i].step_index > 88
u) {
1574 i,
c->status[
i].step_index);
1578 for (
int i = 0;
i <= st;
i++) {
1579 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1580 if (
FFABS((int64_t)
c->status[
i].predictor) > (1<<16))
1584 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1585 int byte = bytestream2_get_byteu(&gb);
1590 CASE(ADPCM_IMA_EA_SEAD,
1591 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1592 int byte = bytestream2_get_byteu(&gb);
1598 int previous_left_sample, previous_right_sample;
1599 int current_left_sample, current_right_sample;
1600 int next_left_sample, next_right_sample;
1601 int coeff1l, coeff2l, coeff1r, coeff2r;
1602 int shift_left, shift_right;
1610 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1611 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1612 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1613 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1615 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1616 int byte = bytestream2_get_byteu(&gb);
1622 byte = bytestream2_get_byteu(&gb);
1623 shift_left = 20 - (
byte >> 4);
1624 shift_right = 20 - (
byte & 0x0F);
1626 for (
int count2 = 0; count2 < 28; count2++) {
1627 byte = bytestream2_get_byteu(&gb);
1628 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1629 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1631 next_left_sample = (next_left_sample +
1632 (current_left_sample * coeff1l) +
1633 (previous_left_sample * coeff2l) + 0x80) >> 8;
1634 next_right_sample = (next_right_sample +
1635 (current_right_sample * coeff1r) +
1636 (previous_right_sample * coeff2r) + 0x80) >> 8;
1638 previous_left_sample = current_left_sample;
1640 previous_right_sample = current_right_sample;
1642 *
samples++ = current_left_sample;
1643 *
samples++ = current_right_sample;
1649 CASE(ADPCM_EA_MAXIS_XA,
1653 int byte = bytestream2_get_byteu(&gb);
1654 for (
int i = 0;
i < 2;
i++)
1658 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1661 byte[0] = bytestream2_get_byteu(&gb);
1662 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1663 for (
int i = 4;
i >= 0;
i-=4) {
1677 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1686 int previous_sample, current_sample, next_sample;
1695 bytestream2_get_le32(&gb)) +
1702 samplesC = samples_p[
channel];
1705 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1706 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1708 current_sample =
c->status[
channel].predictor;
1709 previous_sample =
c->status[
channel].prev_sample;
1712 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1713 int byte = bytestream2_get_byte(&gb);
1715 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1716 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1718 for (
int count2 = 0; count2 < 28; count2++)
1719 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1723 shift = 20 - (
byte & 0x0F);
1725 for (
int count2 = 0; count2 < 28; count2++) {
1729 byte = bytestream2_get_byte(&gb);
1733 next_sample += (current_sample * coeff1) +
1734 (previous_sample * coeff2);
1737 previous_sample = current_sample;
1738 current_sample = next_sample;
1739 *samplesC++ = current_sample;
1745 }
else if (count != count1) {
1747 count =
FFMAX(count, count1);
1751 c->status[
channel].predictor = current_sample;
1752 c->status[
channel].prev_sample = previous_sample;
1756 frame->nb_samples = count * 28;
1765 for (
int n = 0; n < 4; n++,
s += 32) {
1767 for (
int i = 0;
i < 2;
i++)
1776 for (
int m = 2; m < 32; m += 2) {
1778 for (
int n = 0; n < 4; n++,
s += 32) {
1780 int byte = bytestream2_get_byteu(&gb);
1793 CASE(ADPCM_IMA_ACORN,
1797 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
1804 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1805 int byte = bytestream2_get_byteu(&gb);
1823 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1824 c->status[0].step_index = bytestream2_get_byteu(&gb);
1826 if (
c->status[0].step_index > 88
u) {
1828 c->status[0].step_index);
1832 for (
int n = nb_samples >> 1; n > 0; n--) {
1833 int v = bytestream2_get_byteu(&gb);
1839 if (nb_samples & 1) {
1840 int v = bytestream2_get_byteu(&gb);
1850 CASE(ADPCM_IMA_SMJPEG,
1852 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
1853 c->status[
i].step_index = bytestream2_get_byteu(&gb);
1855 if (
c->status[
i].step_index > 88
u) {
1857 c->status[
i].step_index);
1862 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1863 int v = bytestream2_get_byteu(&gb);
1870 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1871 int v = bytestream2_get_byteu(&gb);
1876 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
1877 CONFIG_ADPCM_SBPRO_4_DECODER
1881 if (!
c->status[0].step_index) {
1883 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1885 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1886 c->status[0].step_index = 1;
1890 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1891 int byte = bytestream2_get_byteu(&gb);
1898 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
1899 int byte = bytestream2_get_byteu(&gb);
1903 (
byte >> 2) & 0x07, 3, 0);
1908 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
1909 int byte = bytestream2_get_byteu(&gb);
1913 (
byte >> 4) & 0x03, 2, 2);
1915 (
byte >> 2) & 0x03, 2, 2);
1927 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1928 int v = bytestream2_get_byteu(&gb);
1936 for (
int n = nb_samples >> 1; n > 0; n--) {
1937 int v = bytestream2_get_byteu(&gb);
1944 int samples_per_block;
1948 samples_per_block = avctx->
extradata[0] / 16;
1949 blocks = nb_samples / avctx->
extradata[0];
1951 samples_per_block = nb_samples / 16;
1955 for (
int m = 0; m < blocks; m++) {
1957 int prev1 =
c->status[
channel].sample1;
1958 int prev2 =
c->status[
channel].sample2;
1962 for (
int i = 0;
i < samples_per_block;
i++) {
1963 int byte = bytestream2_get_byteu(&gb);
1964 int scale = 1 << (
byte >> 4);
1965 int index =
byte & 0xf;
1970 for (
int n = 0; n < 16; n++) {
1976 byte = bytestream2_get_byteu(&gb);
1980 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
1988 c->status[
channel].sample1 = prev1;
1989 c->status[
channel].sample2 = prev2;
1994 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2000 #define THP_GET16(g) \
2002 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2003 bytestream2_get_le16u(&(g)) : \
2004 bytestream2_get_be16u(&(g)), 16)
2015 for (
int n = 0; n < 16; n++)
2019 for (
int n = 0; n < 16; n++)
2020 table[
i][n] = THP_GET16(gb);
2022 if (!
c->has_status) {
2025 c->status[
i].sample1 = THP_GET16(gb);
2026 c->status[
i].sample2 = THP_GET16(gb);
2034 for (
int ch = 0; ch < avctx->
channels; ch++) {
2038 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2039 int byte = bytestream2_get_byteu(&gb);
2040 int index = (
byte >> 4) & 7;
2041 unsigned int exp =
byte & 0x0F;
2046 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2052 byte = bytestream2_get_byteu(&gb);
2056 sampledat = ((
c->status[ch].sample1 * factor1
2057 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2059 c->status[ch].sample2 =
c->status[ch].sample1;
2060 c->status[ch].sample1 = *
samples++;
2072 for (
int i = 0;
i < nb_samples / 28;
i++) {
2076 header = bytestream2_get_byteu(&gb);
2080 for (
int n = 0; n < 28; n++) {
2085 prev = (
c->status[
channel].sample1 * 0x3c);
2088 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2091 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2099 byte = bytestream2_get_byteu(&gb);
2105 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2108 c->status[
channel].sample1 = sampledat;
2123 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2126 filter = bytestream2_get_byteu(&gb);
2131 flag = bytestream2_get_byteu(&gb) & 0x7;
2134 for (
int n = 0; n < 28; n++) {
2140 byte = bytestream2_get_byteu(&gb);
2182 control = bytestream2_get_byteu(&gb);
2183 shift = (control >> 4) + 2;
2185 for (
int n = 0; n < 16; n++) {
2186 int sample = bytestream2_get_byteu(&gb);
2194 for (
int n = 0; n < nb_samples * avctx->
channels; n++) {
2195 int v = bytestream2_get_byteu(&gb);
2200 for (
int n = nb_samples / 2; n > 0; n--) {
2202 int v = bytestream2_get_byteu(&gb);
2237 c->status[0].step =
c->status[1].step = 511;
2278 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2279 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2280 const AVCodec ff_ ## name_ ## _decoder = { \
2282 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
2283 .type = AVMEDIA_TYPE_AUDIO, \
2285 .priv_data_size = sizeof(ADPCMDecodeContext), \
2286 .init = adpcm_decode_init, \
2287 .decode = adpcm_decode_frame, \
2288 .flush = adpcm_flush, \
2289 .capabilities = AV_CODEC_CAP_DR1, \
2290 .sample_fmts = sample_fmts_, \
2291 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
2293 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2294 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2295 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2296 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2297 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2298 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2299 name, sample_fmts, long_name)