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;
366 if ((nibble & 8) == 0)
376 c->step =
av_clip(
c->step * 2, 127, 24576);
407 step_index =
av_clip(step_index, 0, 88);
420 c->step_index = step_index;
422 return (int16_t)
c->predictor;
433 step_index =
av_clip(step_index, 0, 88);
443 c->step_index = step_index;
445 return (int16_t)
c->predictor;
459 c->step_index =
av_clip(step_index, 0, 88);
461 return (int16_t)
c->predictor;
474 step_index =
av_clip(step_index, 0, 60);
479 c->step_index = step_index;
492 step_index =
av_clip(step_index, 0, 88);
494 sign = nibble & (1 <<
shift);
502 c->step_index = step_index;
504 return (int16_t)
c->predictor;
515 step_index =
av_clip(step_index, 0, 88);
528 c->step_index = step_index;
537 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
538 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
540 c->sample2 =
c->sample1;
543 if (
c->idelta < 16)
c->idelta = 16;
544 if (
c->idelta > INT_MAX/768) {
546 c->idelta = INT_MAX/768;
558 step_index =
av_clip(step_index, 0, 48);
568 c->step_index = step_index;
570 return c->predictor * 16;
585 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
589 c->step =
av_clip(new_step, 511, 32767);
591 return (int16_t)
c->predictor;
598 sign = nibble & (1<<(
size-1));
608 else if (
delta == 0 &&
c->step > 0)
611 return (int16_t)
c->predictor;
639 int16_t
index =
c->step_index;
646 sample += lookup_sample >> 1;
648 sample += lookup_sample >> 2;
650 sample += lookup_sample >> 3;
652 sample += lookup_sample >> 4;
654 sample += lookup_sample >> 5;
656 sample += lookup_sample >> 6;
681 out0 += sample_offset;
685 out1 += sample_offset;
688 shift = 12 - (in[4+
i*2] & 15);
708 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
721 shift = 12 - (in[5+
i*2] & 15);
739 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
766 int k0, signmask, nb_bits, count;
767 int size = buf_size*8;
775 k0 = 1 << (nb_bits-2);
776 signmask = 1 << (nb_bits-1);
802 if (
delta & signmask)
803 c->status[
i].predictor -= vpdiff;
805 c->status[
i].predictor += vpdiff;
809 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
847 int buf_size,
int *coded_samples,
int *approx_nb_samples)
852 int has_coded_samples = 0;
856 *approx_nb_samples = 0;
864 if (buf_size < 76 * ch)
869 if (buf_size < 34 * ch)
886 nb_samples = buf_size * 2 / ch;
904 return (buf_size - header_size) * 2 / ch;
910 has_coded_samples = 1;
911 *coded_samples = bytestream2_get_le32u(gb);
912 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
916 has_coded_samples = 1;
917 *coded_samples = bytestream2_get_le32(gb);
918 *coded_samples -= *coded_samples % 28;
919 nb_samples = (buf_size - 12) / 30 * 28;
922 has_coded_samples = 1;
923 *coded_samples = bytestream2_get_le32(gb);
924 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
927 nb_samples = (buf_size - ch) / ch * 2;
934 has_coded_samples = 1;
937 header_size = 4 + 9 * ch;
938 *coded_samples = bytestream2_get_le32(gb);
941 header_size = 4 + 5 * ch;
942 *coded_samples = bytestream2_get_le32(gb);
945 header_size = 4 + 5 * ch;
946 *coded_samples = bytestream2_get_be32(gb);
949 *coded_samples -= *coded_samples % 28;
950 nb_samples = (buf_size - header_size) * 2 / ch;
951 nb_samples -= nb_samples % 28;
952 *approx_nb_samples = 1;
957 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
962 if (buf_size < 4 * ch)
964 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
969 nb_samples = (buf_size - 4 * ch) * 2 / ch;
976 if (buf_size < 4 * ch)
978 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
983 nb_samples = (buf_size - 6 * ch) * 2 / ch;
988 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
994 int samples_per_byte;
1000 if (!
s->status[0].step_index) {
1006 nb_samples += buf_size * samples_per_byte / ch;
1011 int buf_bits = buf_size * 8 - 2;
1012 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1013 int block_hdr_size = 22 * ch;
1014 int block_size = block_hdr_size + nbits * ch * 4095;
1015 int nblocks = buf_bits / block_size;
1016 int bits_left = buf_bits - nblocks * block_size;
1017 nb_samples = nblocks * 4096;
1018 if (bits_left >= block_hdr_size)
1019 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
1025 nb_samples = buf_size * 14 / (8 * ch);
1028 has_coded_samples = 1;
1031 bytestream2_get_le32(gb) :
1032 bytestream2_get_be32(gb);
1033 buf_size -= 8 + 36 * ch;
1035 nb_samples = buf_size / 8 * 14;
1036 if (buf_size % 8 > 1)
1037 nb_samples += (buf_size % 8 - 1) * 2;
1038 *approx_nb_samples = 1;
1041 nb_samples = buf_size / (9 * ch) * 16;
1044 nb_samples = (buf_size / 128) * 224 / ch;
1048 nb_samples = buf_size / (16 * ch) * 28;
1054 nb_samples = buf_size / ch;
1059 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1066 int *got_frame_ptr,
AVPacket *avpkt)
1068 const uint8_t *buf = avpkt->
data;
1069 int buf_size = avpkt->
size;
1073 int16_t **samples_p;
1075 int nb_samples, coded_samples, approx_nb_samples,
ret;
1079 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1080 if (nb_samples <= 0) {
1086 frame->nb_samples = nb_samples;
1090 samples_p = (int16_t **)
frame->extended_data;
1094 if (coded_samples) {
1095 if (!approx_nb_samples && coded_samples != nb_samples)
1097 frame->nb_samples = nb_samples = coded_samples;
1137 for (
int m = 0; m < 64; m += 2) {
1138 int byte = bytestream2_get_byteu(&gb);
1163 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1166 samples = &samples_p[
i][1 + n * samples_per_block];
1167 for (
int j = 0; j < block_size; j++) {
1169 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1174 for (
int m = 0; m < samples_per_block; m++) {
1182 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1185 samples = &samples_p[
i][1 + n * 8];
1186 for (
int m = 0; m < 8; m += 2) {
1187 int v = bytestream2_get_byteu(&gb);
1197 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1200 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1201 if (
c->status[
i].step_index > 88
u) {
1203 i,
c->status[
i].step_index);
1211 for (
int n = nb_samples >> 1; n > 0; n--) {
1212 int v = bytestream2_get_byteu(&gb);
1220 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1222 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1224 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1225 int v = bytestream2_get_byteu(&gb);
1231 int block_predictor;
1236 block_predictor = bytestream2_get_byteu(&gb);
1237 if (block_predictor > 6) {
1249 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1250 int byte = bytestream2_get_byteu(&gb);
1256 block_predictor = bytestream2_get_byteu(&gb);
1257 if (block_predictor > 6) {
1265 block_predictor = bytestream2_get_byteu(&gb);
1266 if (block_predictor > 6) {
1274 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1276 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1279 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1280 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1281 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1282 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1285 if (st) *
samples++ =
c->status[1].sample2;
1287 if (st) *
samples++ =
c->status[1].sample1;
1288 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1289 int byte = bytestream2_get_byteu(&gb);
1298 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1299 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1304 for (
int n = 0; n < nb_samples; n += 2) {
1305 int v = bytestream2_get_byteu(&gb);
1309 for (
int n = 0; n < nb_samples; n += 2) {
1310 int v = bytestream2_get_byteu(&gb);
1327 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1328 int v = bytestream2_get_byteu(&gb);
1336 if (decode_top_nibble_next) { \
1337 nibble = last_byte >> 4; \
1338 decode_top_nibble_next = 0; \
1340 last_byte = bytestream2_get_byteu(&gb); \
1341 nibble = last_byte & 0x0F; \
1342 decode_top_nibble_next = 1; \
1347 int decode_top_nibble_next = 0;
1352 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1353 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1354 c->status[0].step_index = bytestream2_get_byteu(&gb);
1355 c->status[1].step_index = bytestream2_get_byteu(&gb);
1356 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1358 c->status[0].step_index,
c->status[1].step_index);
1362 diff_channel =
c->status[1].predictor;
1364 while (
samples < samples_end) {
1378 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1379 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1380 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1387 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1388 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1389 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1407 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1409 int v = bytestream2_get_byteu(&gb);
1422 CASE(ADPCM_IMA_MOFLEX,
1434 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1437 for (
int n = 0; n < 256; n += 2) {
1438 int v = bytestream2_get_byteu(&gb);
1445 CASE(ADPCM_IMA_DAT4,
1450 for (
int n = 0; n < nb_samples; n += 2) {
1451 int v = bytestream2_get_byteu(&gb);
1458 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1459 int v = bytestream2_get_byteu(&gb);
1465 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1466 int v = bytestream2_get_byteu(&gb);
1472 for (
int n = nb_samples / 2; n > 0; n--) {
1474 int v = bytestream2_get_byteu(&gb);
1482 for (
int n = nb_samples / 2; n > 0; n--) {
1484 int v = bytestream2_get_byteu(&gb);
1491 CASE(ADPCM_IMA_CUNNING,
1493 int16_t *smp = samples_p[
channel];
1494 for (
int n = 0; n < nb_samples / 2; n++) {
1495 int v = bytestream2_get_byteu(&gb);
1502 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1503 int v = bytestream2_get_byteu(&gb);
1519 for (
int n = 0; n < nb_samples / 2; n++) {
1522 byte[0] = bytestream2_get_byteu(&gb);
1524 byte[1] = bytestream2_get_byteu(&gb);
1534 if (
c->vqa_version == 3) {
1536 int16_t *smp = samples_p[
channel];
1538 for (
int n = nb_samples / 2; n > 0; n--) {
1539 int v = bytestream2_get_byteu(&gb);
1545 for (
int n = nb_samples / 2; n > 0; n--) {
1547 int v = bytestream2_get_byteu(&gb);
1557 int16_t *out0 = samples_p[0];
1558 int16_t *out1 = samples_p[1];
1559 int samples_per_block = 28 * (3 -
channels) * 4;
1560 int sample_offset = 0;
1561 int bytes_remaining;
1564 &
c->status[0], &
c->status[1],
1568 sample_offset += samples_per_block;
1573 if (bytes_remaining > 0) {
1577 CASE(ADPCM_IMA_EA_EACS,
1578 for (
int i = 0;
i <= st;
i++) {
1579 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1580 if (
c->status[
i].step_index > 88
u) {
1582 i,
c->status[
i].step_index);
1586 for (
int i = 0;
i <= st;
i++) {
1587 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1588 if (
FFABS((int64_t)
c->status[
i].predictor) > (1<<16))
1592 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1593 int byte = bytestream2_get_byteu(&gb);
1598 CASE(ADPCM_IMA_EA_SEAD,
1599 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1600 int byte = bytestream2_get_byteu(&gb);
1606 int previous_left_sample, previous_right_sample;
1607 int current_left_sample, current_right_sample;
1608 int next_left_sample, next_right_sample;
1609 int coeff1l, coeff2l, coeff1r, coeff2r;
1610 int shift_left, shift_right;
1618 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1619 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1620 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1621 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1623 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1624 int byte = bytestream2_get_byteu(&gb);
1630 byte = bytestream2_get_byteu(&gb);
1631 shift_left = 20 - (
byte >> 4);
1632 shift_right = 20 - (
byte & 0x0F);
1634 for (
int count2 = 0; count2 < 28; count2++) {
1635 byte = bytestream2_get_byteu(&gb);
1636 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1637 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1639 next_left_sample = (next_left_sample +
1640 (current_left_sample * coeff1l) +
1641 (previous_left_sample * coeff2l) + 0x80) >> 8;
1642 next_right_sample = (next_right_sample +
1643 (current_right_sample * coeff1r) +
1644 (previous_right_sample * coeff2r) + 0x80) >> 8;
1646 previous_left_sample = current_left_sample;
1648 previous_right_sample = current_right_sample;
1650 *
samples++ = current_left_sample;
1651 *
samples++ = current_right_sample;
1657 CASE(ADPCM_EA_MAXIS_XA,
1661 int byte = bytestream2_get_byteu(&gb);
1662 for (
int i = 0;
i < 2;
i++)
1666 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1669 byte[0] = bytestream2_get_byteu(&gb);
1670 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1671 for (
int i = 4;
i >= 0;
i-=4) {
1685 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1694 int previous_sample, current_sample, next_sample;
1703 bytestream2_get_le32(&gb)) +
1710 samplesC = samples_p[
channel];
1713 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1714 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1716 current_sample =
c->status[
channel].predictor;
1717 previous_sample =
c->status[
channel].prev_sample;
1720 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1721 int byte = bytestream2_get_byte(&gb);
1723 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1724 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1726 for (
int count2 = 0; count2 < 28; count2++)
1727 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1731 shift = 20 - (
byte & 0x0F);
1733 for (
int count2 = 0; count2 < 28; count2++) {
1737 byte = bytestream2_get_byte(&gb);
1741 next_sample += (current_sample * coeff1) +
1742 (previous_sample * coeff2);
1745 previous_sample = current_sample;
1746 current_sample = next_sample;
1747 *samplesC++ = current_sample;
1753 }
else if (count != count1) {
1755 count =
FFMAX(count, count1);
1759 c->status[
channel].predictor = current_sample;
1760 c->status[
channel].prev_sample = previous_sample;
1764 frame->nb_samples = count * 28;
1773 for (
int n = 0; n < 4; n++,
s += 32) {
1775 for (
int i = 0;
i < 2;
i++)
1784 for (
int m = 2; m < 32; m += 2) {
1786 for (
int n = 0; n < 4; n++,
s += 32) {
1788 int byte = bytestream2_get_byteu(&gb);
1801 CASE(ADPCM_IMA_ACORN,
1805 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
1812 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1813 int byte = bytestream2_get_byteu(&gb);
1831 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1832 c->status[0].step_index = bytestream2_get_byteu(&gb);
1834 if (
c->status[0].step_index > 88
u) {
1836 c->status[0].step_index);
1840 for (
int n = nb_samples >> 1; n > 0; n--) {
1841 int v = bytestream2_get_byteu(&gb);
1847 if (nb_samples & 1) {
1848 int v = bytestream2_get_byteu(&gb);
1858 CASE(ADPCM_IMA_SMJPEG,
1860 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
1861 c->status[
i].step_index = bytestream2_get_byteu(&gb);
1863 if (
c->status[
i].step_index > 88
u) {
1865 c->status[
i].step_index);
1870 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1871 int v = bytestream2_get_byteu(&gb);
1878 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1879 int v = bytestream2_get_byteu(&gb);
1884 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
1885 CONFIG_ADPCM_SBPRO_4_DECODER
1889 if (!
c->status[0].step_index) {
1891 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1893 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1894 c->status[0].step_index = 1;
1898 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1899 int byte = bytestream2_get_byteu(&gb);
1906 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
1907 int byte = bytestream2_get_byteu(&gb);
1911 (
byte >> 2) & 0x07, 3, 0);
1916 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
1917 int byte = bytestream2_get_byteu(&gb);
1921 (
byte >> 4) & 0x03, 2, 2);
1923 (
byte >> 2) & 0x03, 2, 2);
1935 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1936 int v = bytestream2_get_byteu(&gb);
1944 for (
int n = nb_samples >> 1; n > 0; n--) {
1945 int v = bytestream2_get_byteu(&gb);
1952 int samples_per_block;
1956 samples_per_block = avctx->
extradata[0] / 16;
1957 blocks = nb_samples / avctx->
extradata[0];
1959 samples_per_block = nb_samples / 16;
1963 for (
int m = 0; m < blocks; m++) {
1965 int prev1 =
c->status[
channel].sample1;
1966 int prev2 =
c->status[
channel].sample2;
1970 for (
int i = 0;
i < samples_per_block;
i++) {
1971 int byte = bytestream2_get_byteu(&gb);
1972 int scale = 1 << (
byte >> 4);
1973 int index =
byte & 0xf;
1978 for (
int n = 0; n < 16; n++) {
1984 byte = bytestream2_get_byteu(&gb);
1988 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
1996 c->status[
channel].sample1 = prev1;
1997 c->status[
channel].sample2 = prev2;
2002 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2008 #define THP_GET16(g) \
2010 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2011 bytestream2_get_le16u(&(g)) : \
2012 bytestream2_get_be16u(&(g)), 16)
2023 for (
int n = 0; n < 16; n++)
2027 for (
int n = 0; n < 16; n++)
2028 table[
i][n] = THP_GET16(gb);
2030 if (!
c->has_status) {
2033 c->status[
i].sample1 = THP_GET16(gb);
2034 c->status[
i].sample2 = THP_GET16(gb);
2042 for (
int ch = 0; ch <
channels; ch++) {
2046 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2047 int byte = bytestream2_get_byteu(&gb);
2048 int index = (
byte >> 4) & 7;
2049 unsigned int exp =
byte & 0x0F;
2054 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2060 byte = bytestream2_get_byteu(&gb);
2064 sampledat = ((
c->status[ch].sample1 * factor1
2065 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2067 c->status[ch].sample2 =
c->status[ch].sample1;
2068 c->status[ch].sample1 = *
samples++;
2080 for (
int i = 0;
i < nb_samples / 28;
i++) {
2084 header = bytestream2_get_byteu(&gb);
2088 for (
int n = 0; n < 28; n++) {
2093 prev = (
c->status[
channel].sample1 * 0x3c);
2096 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2099 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2107 byte = bytestream2_get_byteu(&gb);
2113 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2116 c->status[
channel].sample1 = sampledat;
2131 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2134 filter = bytestream2_get_byteu(&gb);
2139 flag = bytestream2_get_byteu(&gb) & 0x7;
2142 for (
int n = 0; n < 28; n++) {
2148 byte = bytestream2_get_byteu(&gb);
2190 control = bytestream2_get_byteu(&gb);
2191 shift = (control >> 4) + 2;
2193 for (
int n = 0; n < 16; n++) {
2194 int sample = bytestream2_get_byteu(&gb);
2202 for (
int n = 0; n < nb_samples *
channels; n++) {
2203 int v = bytestream2_get_byteu(&gb);
2208 for (
int n = nb_samples / 2; n > 0; n--) {
2210 int v = bytestream2_get_byteu(&gb);
2245 c->status[0].step =
c->status[1].step = 511;
2286 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2287 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2288 const FFCodec ff_ ## name_ ## _decoder = { \
2290 .p.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
2291 .p.type = AVMEDIA_TYPE_AUDIO, \
2293 .p.capabilities = AV_CODEC_CAP_DR1, \
2294 .p.sample_fmts = sample_fmts_, \
2295 .priv_data_size = sizeof(ADPCMDecodeContext), \
2296 .init = adpcm_decode_init, \
2297 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2298 .flush = adpcm_flush, \
2299 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
2301 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2302 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2303 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2304 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2305 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2306 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2307 name, sample_fmts, long_name)