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;
371 if ((nibble & 8) == 0)
381 c->step =
av_clip(
c->step * 2, 127, 24576);
412 step_index =
av_clip(step_index, 0, 88);
425 c->step_index = step_index;
427 return (int16_t)
c->predictor;
438 step_index =
av_clip(step_index, 0, 88);
448 c->step_index = step_index;
450 return (int16_t)
c->predictor;
464 c->step_index =
av_clip(step_index, 0, 88);
466 return (int16_t)
c->predictor;
479 step_index =
av_clip(step_index, 0, 60);
484 c->step_index = step_index;
497 step_index =
av_clip(step_index, 0, 88);
499 sign = nibble & (1 <<
shift);
507 c->step_index = step_index;
509 return (int16_t)
c->predictor;
520 step_index =
av_clip(step_index, 0, 88);
533 c->step_index = step_index;
542 predictor = (((
c->sample1) * (
c->coeff1)) + ((
c->sample2) * (
c->coeff2))) / 64;
543 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) *
c->idelta;
545 c->sample2 =
c->sample1;
548 if (
c->idelta < 16)
c->idelta = 16;
549 if (
c->idelta > INT_MAX/768) {
551 c->idelta = INT_MAX/768;
563 step_index =
av_clip(step_index, 0, 48);
573 c->step_index = step_index;
575 return c->predictor * 16;
590 c->predictor = ((
c->predictor * 254) >> 8) + (sign ? -
diff :
diff);
594 c->step =
av_clip(new_step, 511, 32767);
596 return (int16_t)
c->predictor;
603 sign = nibble & (1<<(
size-1));
613 else if (
delta == 0 &&
c->step > 0)
616 return (int16_t)
c->predictor;
644 int16_t
index =
c->step_index;
651 sample += lookup_sample >> 1;
653 sample += lookup_sample >> 2;
655 sample += lookup_sample >> 3;
657 sample += lookup_sample >> 4;
659 sample += lookup_sample >> 5;
661 sample += lookup_sample >> 6;
686 out0 += sample_offset;
690 out1 += sample_offset;
693 shift = 12 - (in[4+
i*2] & 15);
713 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
726 shift = 12 - (in[5+
i*2] & 15);
744 s = t*(1<<
shift) + ((s_1*f0 + s_2*f1+32)>>6);
771 int k0, signmask, nb_bits, count;
772 int size = buf_size*8;
780 k0 = 1 << (nb_bits-2);
781 signmask = 1 << (nb_bits-1);
807 if (
delta & signmask)
808 c->status[
i].predictor -= vpdiff;
810 c->status[
i].predictor += vpdiff;
814 c->status[
i].step_index =
av_clip(
c->status[
i].step_index, 0, 88);
852 int buf_size,
int *coded_samples,
int *approx_nb_samples)
857 int has_coded_samples = 0;
861 *approx_nb_samples = 0;
869 if (buf_size < 76 * ch)
874 if (buf_size < 34 * ch)
891 nb_samples = buf_size * 2 / ch;
909 return (buf_size - header_size) * 2 / ch;
915 has_coded_samples = 1;
916 *coded_samples = bytestream2_get_le32u(gb);
917 nb_samples =
FFMIN((buf_size - 8) * 2, *coded_samples);
923 has_coded_samples = 1;
924 *coded_samples = bytestream2_get_le32(gb);
925 *coded_samples -= *coded_samples % 28;
926 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
929 has_coded_samples = 1;
930 *coded_samples = bytestream2_get_le32(gb);
931 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
934 nb_samples = (buf_size - ch) / ch * 2;
941 has_coded_samples = 1;
944 header_size = 4 + 9 * ch;
945 *coded_samples = bytestream2_get_le32(gb);
948 header_size = 4 + 5 * ch;
949 *coded_samples = bytestream2_get_le32(gb);
952 header_size = 4 + 5 * ch;
953 *coded_samples = bytestream2_get_be32(gb);
956 *coded_samples -= *coded_samples % 28;
957 nb_samples = (buf_size - header_size) * 2 / ch;
958 nb_samples -= nb_samples % 28;
959 *approx_nb_samples = 1;
964 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
969 if (buf_size < 4 * ch)
971 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
976 nb_samples = (buf_size - 4 * ch) * 2 / ch;
983 if (buf_size < 4 * ch)
985 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
992 if (buf_size < 4 * ch)
994 nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1;
999 nb_samples = (buf_size - 6 * ch) * 2 / ch;
1004 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
1010 int samples_per_byte;
1016 if (!
s->status[0].step_index) {
1022 nb_samples += buf_size * samples_per_byte / ch;
1027 int buf_bits = buf_size * 8 - 2;
1028 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1029 int block_hdr_size = 22 * ch;
1030 int block_size = block_hdr_size + nbits * ch * 4095;
1031 int nblocks = buf_bits / block_size;
1032 int bits_left = buf_bits - nblocks * block_size;
1033 nb_samples = nblocks * 4096;
1035 nb_samples += 1 + (
bits_left - block_hdr_size) / (nbits * ch);
1041 nb_samples = buf_size * 14 / (8 * ch);
1044 has_coded_samples = 1;
1047 bytestream2_get_le32(gb) :
1048 bytestream2_get_be32(gb);
1049 buf_size -= 8 + 36 * ch;
1051 nb_samples = buf_size / 8 * 14;
1052 if (buf_size % 8 > 1)
1053 nb_samples += (buf_size % 8 - 1) * 2;
1054 *approx_nb_samples = 1;
1057 nb_samples = buf_size / (9 * ch) * 16;
1060 nb_samples = (buf_size / 128) * 224 / ch;
1063 nb_samples = buf_size / (21 * ch) * 32;
1067 nb_samples = buf_size / (16 * ch) * 28;
1073 nb_samples = buf_size / ch;
1078 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1085 int *got_frame_ptr,
AVPacket *avpkt)
1087 const uint8_t *buf = avpkt->
data;
1088 int buf_size = avpkt->
size;
1092 int16_t **samples_p;
1094 int nb_samples, coded_samples, approx_nb_samples,
ret;
1098 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1099 if (nb_samples <= 0) {
1105 frame->nb_samples = nb_samples;
1109 samples_p = (int16_t **)
frame->extended_data;
1113 if (coded_samples) {
1114 if (!approx_nb_samples && coded_samples != nb_samples)
1116 frame->nb_samples = nb_samples = coded_samples;
1156 for (
int m = 0; m < 64; m += 2) {
1157 int byte = bytestream2_get_byteu(&gb);
1182 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1185 samples = &samples_p[
i][1 + n * samples_per_block];
1186 for (
int j = 0; j < block_size; j++) {
1188 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1193 for (
int m = 0; m < samples_per_block; m++) {
1201 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1204 samples = &samples_p[
i][1 + n * 8];
1205 for (
int m = 0; m < 8; m += 2) {
1206 int v = bytestream2_get_byteu(&gb);
1214 CASE(ADPCM_IMA_XBOX,
1227 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1230 samples = &samples_p[
i][1 + n * 8];
1231 for (
int m = 0; m < 8; m += 2) {
1232 int v = bytestream2_get_byteu(&gb);
1238 frame->nb_samples--;
1242 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1245 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1246 if (
c->status[
i].step_index > 88
u) {
1248 i,
c->status[
i].step_index);
1256 for (
int n = nb_samples >> 1; n > 0; n--) {
1257 int v = bytestream2_get_byteu(&gb);
1265 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1267 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1269 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1270 int v = bytestream2_get_byteu(&gb);
1276 int block_predictor;
1281 block_predictor = bytestream2_get_byteu(&gb);
1282 if (block_predictor > 6) {
1294 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1295 int byte = bytestream2_get_byteu(&gb);
1301 block_predictor = bytestream2_get_byteu(&gb);
1302 if (block_predictor > 6) {
1310 block_predictor = bytestream2_get_byteu(&gb);
1311 if (block_predictor > 6) {
1319 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1321 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1324 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1325 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1326 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1327 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1330 if (st) *
samples++ =
c->status[1].sample2;
1332 if (st) *
samples++ =
c->status[1].sample1;
1333 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1334 int byte = bytestream2_get_byteu(&gb);
1343 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1344 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1349 for (
int n = 0; n < nb_samples; n += 2) {
1350 int v = bytestream2_get_byteu(&gb);
1354 for (
int n = 0; n < nb_samples; n += 2) {
1355 int v = bytestream2_get_byteu(&gb);
1372 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1373 int v = bytestream2_get_byteu(&gb);
1381 if (decode_top_nibble_next) { \
1382 nibble = last_byte >> 4; \
1383 decode_top_nibble_next = 0; \
1385 last_byte = bytestream2_get_byteu(&gb); \
1386 nibble = last_byte & 0x0F; \
1387 decode_top_nibble_next = 1; \
1392 int decode_top_nibble_next = 0;
1397 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1398 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1399 c->status[0].step_index = bytestream2_get_byteu(&gb);
1400 c->status[1].step_index = bytestream2_get_byteu(&gb);
1401 if (
c->status[0].step_index > 88
u ||
c->status[1].step_index > 88
u){
1403 c->status[0].step_index,
c->status[1].step_index);
1407 diff_channel =
c->status[1].predictor;
1409 while (
samples < samples_end) {
1423 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1424 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1425 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1432 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1433 *
samples++ =
c->status[0].predictor +
c->status[1].predictor;
1434 *
samples++ =
c->status[0].predictor -
c->status[1].predictor;
1452 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1454 int v = bytestream2_get_byteu(&gb);
1467 CASE(ADPCM_IMA_MOFLEX,
1479 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1482 for (
int n = 0; n < 256; n += 2) {
1483 int v = bytestream2_get_byteu(&gb);
1490 CASE(ADPCM_IMA_DAT4,
1495 for (
int n = 0; n < nb_samples; n += 2) {
1496 int v = bytestream2_get_byteu(&gb);
1503 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1504 int v = bytestream2_get_byteu(&gb);
1510 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1511 int v = bytestream2_get_byteu(&gb);
1517 for (
int n = nb_samples / 2; n > 0; n--) {
1519 int v = bytestream2_get_byteu(&gb);
1527 for (
int n = nb_samples / 2; n > 0; n--) {
1529 int v = bytestream2_get_byteu(&gb);
1536 CASE(ADPCM_IMA_CUNNING,
1538 int16_t *smp = samples_p[
channel];
1539 for (
int n = 0; n < nb_samples / 2; n++) {
1540 int v = bytestream2_get_byteu(&gb);
1547 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1548 int v = bytestream2_get_byteu(&gb);
1564 for (
int n = 0; n < nb_samples / 2; n++) {
1567 byte[0] = bytestream2_get_byteu(&gb);
1569 byte[1] = bytestream2_get_byteu(&gb);
1579 if (
c->vqa_version == 3) {
1581 int16_t *smp = samples_p[
channel];
1583 for (
int n = nb_samples / 2; n > 0; n--) {
1584 int v = bytestream2_get_byteu(&gb);
1590 for (
int n = nb_samples / 2; n > 0; n--) {
1592 int v = bytestream2_get_byteu(&gb);
1602 int bytes_remaining,
block = 0;
1609 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
1610 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
1611 scale = bytestream2_get_le16(&gb);
1613 out[0] = history[1];
1614 out[1] = history[0];
1616 for (
int n = 0; n < 15; n++) {
1617 unsigned byte = bytestream2_get_byte(&gb);
1623 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1624 history[1] = history[0];
1625 history[0] =
out[2+n*2];
1627 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
1628 history[1] = history[0];
1629 history[0] =
out[2+n*2+1];
1636 if (bytes_remaining > 0) {
1641 int16_t *out0 = samples_p[0];
1642 int16_t *out1 = samples_p[1];
1643 int samples_per_block = 28 * (3 -
channels) * 4;
1644 int sample_offset = 0;
1645 int bytes_remaining;
1648 &
c->status[0], &
c->status[1],
1652 sample_offset += samples_per_block;
1657 if (bytes_remaining > 0) {
1661 CASE(ADPCM_IMA_EA_EACS,
1662 for (
int i = 0;
i <= st;
i++) {
1663 c->status[
i].step_index = bytestream2_get_le32u(&gb);
1664 if (
c->status[
i].step_index > 88
u) {
1666 i,
c->status[
i].step_index);
1670 for (
int i = 0;
i <= st;
i++) {
1671 c->status[
i].predictor = bytestream2_get_le32u(&gb);
1676 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1677 int byte = bytestream2_get_byteu(&gb);
1682 CASE(ADPCM_IMA_EA_SEAD,
1683 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1684 int byte = bytestream2_get_byteu(&gb);
1690 int previous_left_sample, previous_right_sample;
1691 int current_left_sample, current_right_sample;
1692 int next_left_sample, next_right_sample;
1693 int coeff1l, coeff2l, coeff1r, coeff2r;
1694 int shift_left, shift_right;
1702 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1703 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1704 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1705 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
1707 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
1708 int byte = bytestream2_get_byteu(&gb);
1715 byte = bytestream2_get_byteu(&gb);
1716 shift_left = 20 - (
byte >> 4);
1717 shift_right = 20 - (
byte & 0x0F);
1720 shift_left = 20 - (
byte & 0x0F);
1723 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
1724 byte = bytestream2_get_byteu(&gb);
1725 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
1727 next_left_sample = (next_left_sample +
1728 (current_left_sample * coeff1l) +
1729 (previous_left_sample * coeff2l) + 0x80) >> 8;
1731 previous_left_sample = current_left_sample;
1733 *
samples++ = current_left_sample;
1736 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
1738 next_right_sample = (next_right_sample +
1739 (current_right_sample * coeff1r) +
1740 (previous_right_sample * coeff2r) + 0x80) >> 8;
1742 previous_right_sample = current_right_sample;
1744 *
samples++ = current_right_sample;
1746 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
1748 next_left_sample = (next_left_sample +
1749 (current_left_sample * coeff1l) +
1750 (previous_left_sample * coeff2l) + 0x80) >> 8;
1752 previous_left_sample = current_left_sample;
1755 *
samples++ = current_left_sample;
1761 CASE(ADPCM_EA_MAXIS_XA,
1765 int byte = bytestream2_get_byteu(&gb);
1766 for (
int i = 0;
i < 2;
i++)
1770 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
1773 byte[0] = bytestream2_get_byteu(&gb);
1774 if (st)
byte[1] = bytestream2_get_byteu(&gb);
1775 for (
int i = 4;
i >= 0;
i-=4) {
1789 #
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1798 int previous_sample, current_sample, next_sample;
1807 bytestream2_get_le32(&gb)) +
1814 samplesC = samples_p[
channel];
1817 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1818 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
1820 current_sample =
c->status[
channel].predictor;
1821 previous_sample =
c->status[
channel].prev_sample;
1824 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1825 int byte = bytestream2_get_byte(&gb);
1827 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1828 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
1830 for (
int count2 = 0; count2 < 28; count2++)
1831 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
1835 shift = 20 - (
byte & 0x0F);
1837 for (
int count2 = 0; count2 < 28; count2++) {
1841 byte = bytestream2_get_byte(&gb);
1845 next_sample += (current_sample * coeff1) +
1846 (previous_sample * coeff2);
1849 previous_sample = current_sample;
1850 current_sample = next_sample;
1851 *samplesC++ = current_sample;
1857 }
else if (count != count1) {
1859 count =
FFMAX(count, count1);
1863 c->status[
channel].predictor = current_sample;
1864 c->status[
channel].prev_sample = previous_sample;
1868 frame->nb_samples = count * 28;
1877 for (
int n = 0; n < 4; n++,
s += 32) {
1879 for (
int i = 0;
i < 2;
i++)
1888 for (
int m = 2; m < 32; m += 2) {
1890 for (
int n = 0; n < 4; n++,
s += 32) {
1892 int byte = bytestream2_get_byteu(&gb);
1905 CASE(ADPCM_IMA_ACORN,
1909 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
1916 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1917 int byte = bytestream2_get_byteu(&gb);
1935 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1936 c->status[0].step_index = bytestream2_get_byteu(&gb);
1938 if (
c->status[0].step_index > 88
u) {
1940 c->status[0].step_index);
1944 for (
int n = nb_samples >> 1; n > 0; n--) {
1945 int v = bytestream2_get_byteu(&gb);
1951 if (nb_samples & 1) {
1952 int v = bytestream2_get_byteu(&gb);
1962 CASE(ADPCM_IMA_SMJPEG,
1964 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
1965 c->status[
i].step_index = bytestream2_get_byteu(&gb);
1967 if (
c->status[
i].step_index > 88
u) {
1969 c->status[
i].step_index);
1974 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1975 int v = bytestream2_get_byteu(&gb);
1982 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1983 int v = bytestream2_get_byteu(&gb);
1988 #
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
1989 CONFIG_ADPCM_SBPRO_4_DECODER
1993 if (!
c->status[0].step_index) {
1995 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1997 *
samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1998 c->status[0].step_index = 1;
2002 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2003 int byte = bytestream2_get_byteu(&gb);
2010 for (
int n = (nb_samples<<st) / 3; n > 0; n--) {
2011 int byte = bytestream2_get_byteu(&gb);
2015 (
byte >> 2) & 0x07, 3, 0);
2020 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2021 int byte = bytestream2_get_byteu(&gb);
2025 (
byte >> 4) & 0x03, 2, 2);
2027 (
byte >> 2) & 0x03, 2, 2);
2039 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2040 int v = bytestream2_get_byteu(&gb);
2048 for (
int n = nb_samples >> 1; n > 0; n--) {
2049 int v = bytestream2_get_byteu(&gb);
2056 int samples_per_block;
2060 samples_per_block = avctx->
extradata[0] / 16;
2061 blocks = nb_samples / avctx->
extradata[0];
2063 samples_per_block = nb_samples / 16;
2067 for (
int m = 0; m < blocks; m++) {
2069 int prev1 =
c->status[
channel].sample1;
2070 int prev2 =
c->status[
channel].sample2;
2074 for (
int i = 0;
i < samples_per_block;
i++) {
2075 int byte = bytestream2_get_byteu(&gb);
2076 int scale = 1 << (
byte >> 4);
2077 int index =
byte & 0xf;
2082 for (
int n = 0; n < 16; n++) {
2088 byte = bytestream2_get_byteu(&gb);
2092 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2100 c->status[
channel].sample1 = prev1;
2101 c->status[
channel].sample2 = prev2;
2106 #
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2112 #define THP_GET16(g) \
2114 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2115 bytestream2_get_le16u(&(g)) : \
2116 bytestream2_get_be16u(&(g)), 16)
2127 for (
int n = 0; n < 16; n++)
2128 table[
i][n] = THP_GET16(tb);
2131 for (
int n = 0; n < 16; n++)
2132 table[
i][n] = THP_GET16(gb);
2134 if (!
c->has_status) {
2137 c->status[
i].sample1 = THP_GET16(gb);
2138 c->status[
i].sample2 = THP_GET16(gb);
2146 for (
int ch = 0; ch <
channels; ch++) {
2150 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2151 int byte = bytestream2_get_byteu(&gb);
2152 int index = (
byte >> 4) & 7;
2153 unsigned int exp =
byte & 0x0F;
2158 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2164 byte = bytestream2_get_byteu(&gb);
2168 sampledat = ((
c->status[ch].sample1 * factor1
2169 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2171 c->status[ch].sample2 =
c->status[ch].sample1;
2172 c->status[ch].sample1 = *
samples++;
2184 for (
int i = 0;
i < nb_samples / 28;
i++) {
2188 header = bytestream2_get_byteu(&gb);
2192 for (
int n = 0; n < 28; n++) {
2197 prev = (
c->status[
channel].sample1 * 0x3c);
2200 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2203 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2211 byte = bytestream2_get_byteu(&gb);
2217 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2220 c->status[
channel].sample1 = sampledat;
2235 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2238 filter = bytestream2_get_byteu(&gb);
2243 flag = bytestream2_get_byteu(&gb) & 0x7;
2246 for (
int n = 0; n < 28; n++) {
2252 byte = bytestream2_get_byteu(&gb);
2294 control = bytestream2_get_byteu(&gb);
2295 shift = (control >> 4) + 2;
2297 for (
int n = 0; n < 16; n++) {
2298 int sample = bytestream2_get_byteu(&gb);
2306 for (
int n = 0; n < nb_samples *
channels; n++) {
2307 int v = bytestream2_get_byteu(&gb);
2312 for (
int n = nb_samples / 2; n > 0; n--) {
2314 int v = bytestream2_get_byteu(&gb);
2349 c->status[0].step =
c->status[1].step = 511;
2390 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2391 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2392 const FFCodec ff_ ## name_ ## _decoder = { \
2394 CODEC_LONG_NAME(long_name_), \
2395 .p.type = AVMEDIA_TYPE_AUDIO, \
2397 .p.capabilities = AV_CODEC_CAP_DR1, \
2398 .p.sample_fmts = sample_fmts_, \
2399 .priv_data_size = sizeof(ADPCMDecodeContext), \
2400 .init = adpcm_decode_init, \
2401 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2402 .flush = adpcm_flush, \
2404 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2405 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2406 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2407 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2408 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2409 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2410 name, sample_fmts, long_name)