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);
918 has_coded_samples = 1;
919 *coded_samples = bytestream2_get_le32(gb);
920 *coded_samples -= *coded_samples % 28;
921 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
924 has_coded_samples = 1;
925 *coded_samples = bytestream2_get_le32(gb);
926 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
929 nb_samples = (buf_size - ch) / ch * 2;
936 has_coded_samples = 1;
939 header_size = 4 + 9 * ch;
940 *coded_samples = bytestream2_get_le32(gb);
943 header_size = 4 + 5 * ch;
944 *coded_samples = bytestream2_get_le32(gb);
947 header_size = 4 + 5 * ch;
948 *coded_samples = bytestream2_get_be32(gb);
951 *coded_samples -= *coded_samples % 28;
952 nb_samples = (buf_size - header_size) * 2 / ch;
953 nb_samples -= nb_samples % 28;
954 *approx_nb_samples = 1;
959 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
964 if (buf_size < 4 * ch)
966 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
971 nb_samples = (buf_size - 4 * ch) * 2 / ch;
978 if (buf_size < 4 * ch)
980 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
985 nb_samples = (buf_size - 6 * ch) * 2 / ch;
990 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
996 int samples_per_byte;
1002 if (!
s->status[0].step_index) {
1008 nb_samples += buf_size * samples_per_byte / ch;
1013 int buf_bits = buf_size * 8 - 2;
1014 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1015 int block_hdr_size = 22 * ch;
1016 int block_size = block_hdr_size + nbits * ch * 4095;
1017 int nblocks = buf_bits / block_size;
1018 int bits_left = buf_bits - nblocks * block_size;
1019 nb_samples = nblocks * 4096;
1021 nb_samples += 1 + (
bits_left - block_hdr_size) / (nbits * ch);
1027 nb_samples = buf_size * 14 / (8 * ch);
1030 has_coded_samples = 1;
1033 bytestream2_get_le32(gb) :
1034 bytestream2_get_be32(gb);
1035 buf_size -= 8 + 36 * ch;
1037 nb_samples = buf_size / 8 * 14;
1038 if (buf_size % 8 > 1)
1039 nb_samples += (buf_size % 8 - 1) * 2;
1040 *approx_nb_samples = 1;
1043 nb_samples = buf_size / (9 * ch) * 16;
1046 nb_samples = (buf_size / 128) * 224 / ch;
1049 nb_samples = buf_size / (21 * ch) * 32;
1053 nb_samples = buf_size / (16 * ch) * 28;
1059 nb_samples = buf_size / ch;
1064 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1071 int *got_frame_ptr,
AVPacket *avpkt)
1073 const uint8_t *buf = avpkt->
data;
1074 int buf_size = avpkt->
size;
1078 int16_t **samples_p;
1080 int nb_samples, coded_samples, approx_nb_samples,
ret;
1084 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1085 if (nb_samples <= 0) {
1091 frame->nb_samples = nb_samples;
1095 samples_p = (int16_t **)
frame->extended_data;
1099 if (coded_samples) {
1100 if (!approx_nb_samples && coded_samples != nb_samples)
1102 frame->nb_samples = nb_samples = coded_samples;
1142 for (
int m = 0; m < 64; m += 2) {
1143 int byte = bytestream2_get_byteu(&gb);
1168 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1171 samples = &samples_p[
i][1 + n * samples_per_block];
1172 for (
int j = 0; j < block_size; j++) {
1174 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1179 for (
int m = 0; m < samples_per_block; m++) {
1187 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1190 samples = &samples_p[
i][1 + n * 8];
1191 for (
int m = 0; m < 8; m += 2) {
1192 int v = bytestream2_get_byteu(&gb);
1202 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1205 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1206 if (
c->status[
i].step_index > 88
u) {
1208 i,
c->status[
i].step_index);
1216 for (
int n = nb_samples >> 1; n > 0; n--) {
1217 int v = bytestream2_get_byteu(&gb);
1225 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1227 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1229 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1230 int v = bytestream2_get_byteu(&gb);
1236 int block_predictor;
1241 block_predictor = bytestream2_get_byteu(&gb);
1242 if (block_predictor > 6) {
1254 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1255 int byte = bytestream2_get_byteu(&gb);
1261 block_predictor = bytestream2_get_byteu(&gb);
1262 if (block_predictor > 6) {
1270 block_predictor = bytestream2_get_byteu(&gb);
1271 if (block_predictor > 6) {
1279 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1281 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1284 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1285 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1286 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1287 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1290 if (st) *
samples++ =
c->status[1].sample2;
1292 if (st) *
samples++ =
c->status[1].sample1;
1293 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1294 int byte = bytestream2_get_byteu(&gb);
1303 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1304 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1309 for (
int n = 0; n < nb_samples; n += 2) {
1310 int v = bytestream2_get_byteu(&gb);
1314 for (
int n = 0; n < nb_samples; n += 2) {
1315 int v = bytestream2_get_byteu(&gb);
1332 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1333 int v = bytestream2_get_byteu(&gb);
1341 if (decode_top_nibble_next) { \
1342 nibble = last_byte >> 4; \
1343 decode_top_nibble_next = 0; \
1345 last_byte = bytestream2_get_byteu(&gb); \
1346 nibble = last_byte & 0x0F; \
1347 decode_top_nibble_next = 1; \
1352 int decode_top_nibble_next = 0;
1357 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1358 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1359 c->status[0].step_index = bytestream2_get_byteu(&gb);
1360 c->status[1].step_index = bytestream2_get_byteu(&gb);
1361 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1363 c->status[0].step_index,
c->status[1].step_index);
1367 diff_channel =
c->status[1].predictor;
1369 while (
samples < samples_end) {
1383 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1384 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1385 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1392 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1393 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1394 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1412 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1414 int v = bytestream2_get_byteu(&gb);
1427 CASE(ADPCM_IMA_MOFLEX,
1439 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1442 for (
int n = 0; n < 256; n += 2) {
1443 int v = bytestream2_get_byteu(&gb);
1450 CASE(ADPCM_IMA_DAT4,
1455 for (
int n = 0; n < nb_samples; n += 2) {
1456 int v = bytestream2_get_byteu(&gb);
1463 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1464 int v = bytestream2_get_byteu(&gb);
1470 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1471 int v = bytestream2_get_byteu(&gb);
1477 for (
int n = nb_samples / 2; n > 0; n--) {
1479 int v = bytestream2_get_byteu(&gb);
1487 for (
int n = nb_samples / 2; n > 0; n--) {
1489 int v = bytestream2_get_byteu(&gb);
1496 CASE(ADPCM_IMA_CUNNING,
1498 int16_t *smp = samples_p[
channel];
1499 for (
int n = 0; n < nb_samples / 2; n++) {
1500 int v = bytestream2_get_byteu(&gb);
1507 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1508 int v = bytestream2_get_byteu(&gb);
1524 for (
int n = 0; n < nb_samples / 2; n++) {
1527 byte[0] = bytestream2_get_byteu(&gb);
1529 byte[1] = bytestream2_get_byteu(&gb);
1539 if (
c->vqa_version == 3) {
1541 int16_t *smp = samples_p[
channel];
1543 for (
int n = nb_samples / 2; n > 0; n--) {
1544 int v = bytestream2_get_byteu(&gb);
1550 for (
int n = nb_samples / 2; n > 0; n--) {
1552 int v = bytestream2_get_byteu(&gb);
1562 int bytes_remaining,
block = 0;
1569 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
1570 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
1571 scale = bytestream2_get_le16(&gb);
1573 out[0] = history[1];
1574 out[1] = history[0];
1576 for (
int n = 0; n < 15; n++) {
1577 unsigned byte = bytestream2_get_byte(&gb);
1583 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1584 history[1] = history[0];
1585 history[0] =
out[2+n*2];
1587 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1588 history[1] = history[0];
1589 history[0] =
out[2+n*2+1];
1596 if (bytes_remaining > 0) {
1601 int16_t *out0 = samples_p[0];
1602 int16_t *out1 = samples_p[1];
1603 int samples_per_block = 28 * (3 -
channels) * 4;
1604 int sample_offset = 0;
1605 int bytes_remaining;
1608 &
c->status[0], &
c->status[1],
1612 sample_offset += samples_per_block;
1617 if (bytes_remaining > 0) {
1621 CASE(ADPCM_IMA_EA_EACS,
1622 for (
int i = 0;
i <= st;
i++) {
1623 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1624 if (
c->status[
i].step_index > 88
u) {
1626 i,
c->status[
i].step_index);
1630 for (
int i = 0;
i <= st;
i++) {
1631 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1636 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1637 int byte = bytestream2_get_byteu(&gb);
1642 CASE(ADPCM_IMA_EA_SEAD,
1643 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1644 int byte = bytestream2_get_byteu(&gb);
1650 int previous_left_sample, previous_right_sample;
1651 int current_left_sample, current_right_sample;
1652 int next_left_sample, next_right_sample;
1653 int coeff1l, coeff2l, coeff1r, coeff2r;
1654 int shift_left, shift_right;
1662 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1663 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1664 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1665 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1667 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1668 int byte = bytestream2_get_byteu(&gb);
1675 byte = bytestream2_get_byteu(&gb);
1676 shift_left = 20 - (
byte >> 4);
1677 shift_right = 20 - (
byte & 0x0F);
1680 shift_left = 20 - (
byte & 0x0F);
1683 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
1684 byte = bytestream2_get_byteu(&gb);
1685 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1687 next_left_sample = (next_left_sample +
1688 (current_left_sample * coeff1l) +
1689 (previous_left_sample * coeff2l) + 0x80) >> 8;
1691 previous_left_sample = current_left_sample;
1693 *
samples++ = current_left_sample;
1696 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1698 next_right_sample = (next_right_sample +
1699 (current_right_sample * coeff1r) +
1700 (previous_right_sample * coeff2r) + 0x80) >> 8;
1702 previous_right_sample = current_right_sample;
1704 *
samples++ = current_right_sample;
1706 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
1708 next_left_sample = (next_left_sample +
1709 (current_left_sample * coeff1l) +
1710 (previous_left_sample * coeff2l) + 0x80) >> 8;
1712 previous_left_sample = current_left_sample;
1715 *
samples++ = current_left_sample;
1721 CASE(ADPCM_EA_MAXIS_XA,
1725 int byte = bytestream2_get_byteu(&gb);
1726 for (
int i = 0;
i < 2;
i++)
1730 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1733 byte[0] = bytestream2_get_byteu(&gb);
1734 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1735 for (
int i = 4;
i >= 0;
i-=4) {
1749 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1758 int previous_sample, current_sample, next_sample;
1767 bytestream2_get_le32(&gb)) +
1774 samplesC = samples_p[
channel];
1777 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1778 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1780 current_sample =
c->status[
channel].predictor;
1781 previous_sample =
c->status[
channel].prev_sample;
1784 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1785 int byte = bytestream2_get_byte(&gb);
1787 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1788 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1790 for (
int count2 = 0; count2 < 28; count2++)
1791 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1795 shift = 20 - (
byte & 0x0F);
1797 for (
int count2 = 0; count2 < 28; count2++) {
1801 byte = bytestream2_get_byte(&gb);
1805 next_sample += (current_sample * coeff1) +
1806 (previous_sample * coeff2);
1809 previous_sample = current_sample;
1810 current_sample = next_sample;
1811 *samplesC++ = current_sample;
1817 }
else if (count != count1) {
1819 count =
FFMAX(count, count1);
1823 c->status[
channel].predictor = current_sample;
1824 c->status[
channel].prev_sample = previous_sample;
1828 frame->nb_samples = count * 28;
1837 for (
int n = 0; n < 4; n++,
s += 32) {
1839 for (
int i = 0;
i < 2;
i++)
1848 for (
int m = 2; m < 32; m += 2) {
1850 for (
int n = 0; n < 4; n++,
s += 32) {
1852 int byte = bytestream2_get_byteu(&gb);
1865 CASE(ADPCM_IMA_ACORN,
1869 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
1876 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1877 int byte = bytestream2_get_byteu(&gb);
1895 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1896 c->status[0].step_index = bytestream2_get_byteu(&gb);
1898 if (
c->status[0].step_index > 88
u) {
1900 c->status[0].step_index);
1904 for (
int n = nb_samples >> 1; n > 0; n--) {
1905 int v = bytestream2_get_byteu(&gb);
1911 if (nb_samples & 1) {
1912 int v = bytestream2_get_byteu(&gb);
1922 CASE(ADPCM_IMA_SMJPEG,
1924 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
1925 c->status[
i].step_index = bytestream2_get_byteu(&gb);
1927 if (
c->status[
i].step_index > 88
u) {
1929 c->status[
i].step_index);
1934 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1935 int v = bytestream2_get_byteu(&gb);
1942 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1943 int v = bytestream2_get_byteu(&gb);
1948 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
1949 CONFIG_ADPCM_SBPRO_4_DECODER
1953 if (!
c->status[0].step_index) {
1955 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1957 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1958 c->status[0].step_index = 1;
1962 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1963 int byte = bytestream2_get_byteu(&gb);
1970 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
1971 int byte = bytestream2_get_byteu(&gb);
1975 (
byte >> 2) & 0x07, 3, 0);
1980 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
1981 int byte = bytestream2_get_byteu(&gb);
1985 (
byte >> 4) & 0x03, 2, 2);
1987 (
byte >> 2) & 0x03, 2, 2);
1999 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2000 int v = bytestream2_get_byteu(&gb);
2008 for (
int n = nb_samples >> 1; n > 0; n--) {
2009 int v = bytestream2_get_byteu(&gb);
2016 int samples_per_block;
2020 samples_per_block = avctx->
extradata[0] / 16;
2021 blocks = nb_samples / avctx->
extradata[0];
2023 samples_per_block = nb_samples / 16;
2027 for (
int m = 0; m < blocks; m++) {
2029 int prev1 =
c->status[
channel].sample1;
2030 int prev2 =
c->status[
channel].sample2;
2034 for (
int i = 0;
i < samples_per_block;
i++) {
2035 int byte = bytestream2_get_byteu(&gb);
2036 int scale = 1 << (
byte >> 4);
2037 int index =
byte & 0xf;
2042 for (
int n = 0; n < 16; n++) {
2048 byte = bytestream2_get_byteu(&gb);
2052 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2060 c->status[
channel].sample1 = prev1;
2061 c->status[
channel].sample2 = prev2;
2066 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2072 #define THP_GET16(g) \
2074 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2075 bytestream2_get_le16u(&(g)) : \
2076 bytestream2_get_be16u(&(g)), 16)
2087 for (
int n = 0; n < 16; n++)
2088 table[
i][n] = THP_GET16(tb);
2091 for (
int n = 0; n < 16; n++)
2092 table[
i][n] = THP_GET16(gb);
2094 if (!
c->has_status) {
2097 c->status[
i].sample1 = THP_GET16(gb);
2098 c->status[
i].sample2 = THP_GET16(gb);
2106 for (
int ch = 0; ch <
channels; ch++) {
2110 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2111 int byte = bytestream2_get_byteu(&gb);
2112 int index = (
byte >> 4) & 7;
2113 unsigned int exp =
byte & 0x0F;
2118 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2124 byte = bytestream2_get_byteu(&gb);
2128 sampledat = ((
c->status[ch].sample1 * factor1
2129 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2131 c->status[ch].sample2 =
c->status[ch].sample1;
2132 c->status[ch].sample1 = *
samples++;
2144 for (
int i = 0;
i < nb_samples / 28;
i++) {
2148 header = bytestream2_get_byteu(&gb);
2152 for (
int n = 0; n < 28; n++) {
2157 prev = (
c->status[
channel].sample1 * 0x3c);
2160 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2163 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2171 byte = bytestream2_get_byteu(&gb);
2177 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2180 c->status[
channel].sample1 = sampledat;
2195 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2198 filter = bytestream2_get_byteu(&gb);
2203 flag = bytestream2_get_byteu(&gb) & 0x7;
2206 for (
int n = 0; n < 28; n++) {
2212 byte = bytestream2_get_byteu(&gb);
2254 control = bytestream2_get_byteu(&gb);
2255 shift = (control >> 4) + 2;
2257 for (
int n = 0; n < 16; n++) {
2258 int sample = bytestream2_get_byteu(&gb);
2266 for (
int n = 0; n < nb_samples *
channels; n++) {
2267 int v = bytestream2_get_byteu(&gb);
2272 for (
int n = nb_samples / 2; n > 0; n--) {
2274 int v = bytestream2_get_byteu(&gb);
2309 c->status[0].step =
c->status[1].step = 511;
2350 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2351 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2352 const FFCodec ff_ ## name_ ## _decoder = { \
2354 CODEC_LONG_NAME(long_name_), \
2355 .p.type = AVMEDIA_TYPE_AUDIO, \
2357 .p.capabilities = AV_CODEC_CAP_DR1, \
2358 .p.sample_fmts = sample_fmts_, \
2359 .priv_data_size = sizeof(ADPCMDecodeContext), \
2360 .init = adpcm_decode_init, \
2361 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2362 .flush = adpcm_flush, \
2364 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2365 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2366 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2367 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2368 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2369 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2370 name, sample_fmts, long_name)