153 { 1, 5, 9, 13, 16, 20, 24, 28,
154 -1, -5, -9, -13, -16, -20, -24, -28, },
155 { 2, 6, 11, 15, 20, 24, 29, 33,
156 -2, -6, -11, -15, -20, -24, -29, -33, },
157 { 2, 7, 13, 18, 23, 28, 34, 39,
158 -2, -7, -13, -18, -23, -28, -34, -39, },
159 { 3, 9, 15, 21, 28, 34, 40, 46,
160 -3, -9, -15, -21, -28, -34, -40, -46, },
161 { 3, 11, 18, 26, 33, 41, 48, 56,
162 -3, -11, -18, -26, -33, -41, -48, -56, },
163 { 4, 13, 22, 31, 40, 49, 58, 67,
164 -4, -13, -22, -31, -40, -49, -58, -67, },
165 { 5, 16, 26, 37, 48, 59, 69, 80,
166 -5, -16, -26, -37, -48, -59, -69, -80, },
167 { 6, 19, 31, 44, 57, 70, 82, 95,
168 -6, -19, -31, -44, -57, -70, -82, -95, },
169 { 7, 22, 38, 53, 68, 83, 99, 114,
170 -7, -22, -38, -53, -68, -83, -99, -114, },
171 { 9, 27, 45, 63, 81, 99, 117, 135,
172 -9, -27, -45, -63, -81, -99, -117, -135, },
173 { 10, 32, 53, 75, 96, 118, 139, 161,
174 -10, -32, -53, -75, -96, -118, -139, -161, },
175 { 12, 38, 64, 90, 115, 141, 167, 193,
176 -12, -38, -64, -90, -115, -141, -167, -193, },
177 { 15, 45, 76, 106, 137, 167, 198, 228,
178 -15, -45, -76, -106, -137, -167, -198, -228, },
179 { 18, 54, 91, 127, 164, 200, 237, 273,
180 -18, -54, -91, -127, -164, -200, -237, -273, },
181 { 21, 65, 108, 152, 195, 239, 282, 326,
182 -21, -65, -108, -152, -195, -239, -282, -326, },
183 { 25, 77, 129, 181, 232, 284, 336, 388,
184 -25, -77, -129, -181, -232, -284, -336, -388, },
185 { 30, 92, 153, 215, 276, 338, 399, 461,
186 -30, -92, -153, -215, -276, -338, -399, -461, },
187 { 36, 109, 183, 256, 329, 402, 476, 549,
188 -36, -109, -183, -256, -329, -402, -476, -549, },
189 { 43, 130, 218, 305, 392, 479, 567, 654,
190 -43, -130, -218, -305, -392, -479, -567, -654, },
191 { 52, 156, 260, 364, 468, 572, 676, 780,
192 -52, -156, -260, -364, -468, -572, -676, -780, },
193 { 62, 186, 310, 434, 558, 682, 806, 930,
194 -62, -186, -310, -434, -558, -682, -806, -930, },
195 { 73, 221, 368, 516, 663, 811, 958, 1106,
196 -73, -221, -368, -516, -663, -811, -958, -1106, },
197 { 87, 263, 439, 615, 790, 966, 1142, 1318,
198 -87, -263, -439, -615, -790, -966, -1142, -1318, },
199 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
200 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
201 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
202 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
203 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
204 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
205 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
206 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
207 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
208 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
209 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
210 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
211 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
212 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
213 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
214 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
215 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
216 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
1443 int *got_frame_ptr,
AVPacket *avpkt)
1445 const uint8_t *buf = avpkt->
data;
1446 int buf_size = avpkt->
size;
1450 int16_t **samples_p;
1452 int nb_samples, coded_samples, approx_nb_samples, ret;
1456 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1457 if (nb_samples <= 0) {
1463 frame->nb_samples = nb_samples;
1466 samples = (int16_t *)
frame->data[0];
1467 samples_p = (int16_t **)
frame->extended_data;
1471 if (coded_samples) {
1472 if (!approx_nb_samples && coded_samples != nb_samples)
1474 frame->nb_samples = nb_samples = coded_samples;
1514 for (
int m = 0; m < 64; m += 2) {
1515 int byte = bytestream2_get_byteu(&gb);
1536 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1537 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1538 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1541 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1544 samples = &samples_p[
i][1 + n * samples_per_block];
1545 for (
int j = 0; j < block_size; j++) {
1547 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1552 for (
int m = 0; m < samples_per_block; m++) {
1560 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1563 samples = &samples_p[
i][1 + n * 8];
1564 for (
int m = 0; m < 8; m += 2) {
1565 int v = bytestream2_get_byteu(&gb);
1573 CASE(ADPCM_IMA_XBOX,
1586 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1589 samples = &samples_p[
i][1 + n * 8];
1590 for (
int m = 0; m < 8; m += 2) {
1591 int v = bytestream2_get_byteu(&gb);
1597 frame->nb_samples--;
1601 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1604 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1605 if (
c->status[
i].step_index > 88u) {
1607 i,
c->status[
i].step_index);
1614 samples = (int16_t *)
frame->data[
i];
1615 for (
int n = nb_samples >> 1; n > 0; n--) {
1616 int v = bytestream2_get_byteu(&gb);
1624 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1626 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1628 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1629 int v = bytestream2_get_byteu(&gb);
1635 int block_predictor;
1640 block_predictor = bytestream2_get_byteu(&gb);
1641 if (block_predictor > 6) {
1651 *samples++ =
c->status[
channel].sample2;
1652 *samples++ =
c->status[
channel].sample1;
1653 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1654 int byte = bytestream2_get_byteu(&gb);
1660 block_predictor = bytestream2_get_byteu(&gb);
1661 if (block_predictor > 6) {
1669 block_predictor = bytestream2_get_byteu(&gb);
1670 if (block_predictor > 6) {
1678 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1680 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1683 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1684 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1685 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1686 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1688 *samples++ =
c->status[0].sample2;
1689 if (st) *samples++ =
c->status[1].sample2;
1690 *samples++ =
c->status[0].sample1;
1691 if (st) *samples++ =
c->status[1].sample1;
1692 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1693 int byte = bytestream2_get_byteu(&gb);
1702 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1703 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1708 for (
int n = 0; n < nb_samples; n += 2) {
1709 int v = bytestream2_get_byteu(&gb);
1713 for (
int n = 0; n < nb_samples; n += 2) {
1714 int v = bytestream2_get_byteu(&gb);
1731 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1732 int v = bytestream2_get_byteu(&gb);
1740 if (decode_top_nibble_next) { \
1741 nibble = last_byte >> 4; \
1742 decode_top_nibble_next = 0; \
1744 last_byte = bytestream2_get_byteu(&gb); \
1745 nibble = last_byte & 0x0F; \
1746 decode_top_nibble_next = 1; \
1751 int decode_top_nibble_next = 0;
1753 const int16_t *samples_end = samples +
channels * nb_samples;
1756 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1757 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1758 c->status[0].step_index = bytestream2_get_byteu(&gb);
1759 c->status[1].step_index = bytestream2_get_byteu(&gb);
1760 if (
c->status[0].step_index > 88u ||
c->status[1].step_index > 88u){
1762 c->status[0].step_index,
c->status[1].step_index);
1766 diff_channel =
c->status[1].predictor;
1768 while (samples < samples_end) {
1782 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1783 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1784 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1791 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1792 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1793 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1799 CASE(ADPCM_IMA_MAGIX,
1811 for (
int m = 0; m <
channels*nb_samples/16; m ++) {
1812 uint32_t v0 = bytestream2_get_le32u(&gb);
1813 uint32_t v1 = bytestream2_get_le32u(&gb);
1815 for (
int n = 8; n > 0; n--, v0 >>= 4, v1 >>= 4, samples += 2) {
1833 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1835 int v = bytestream2_get_byteu(&gb);
1848 CASE(ADPCM_IMA_MOFLEX,
1860 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1862 samples = samples_p[
channel] + 256 * subframe;
1863 for (
int n = 0; n < 256; n += 2) {
1864 int v = bytestream2_get_byteu(&gb);
1871 CASE(ADPCM_IMA_DAT4,
1876 for (
int n = 0; n < nb_samples; n += 2) {
1877 int v = bytestream2_get_byteu(&gb);
1884 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1885 int v = bytestream2_get_byteu(&gb);
1890 CASE(ADPCM_IMA_HVQM2,
1891 int format = bytestream2_get_be16(&gb);
1896 CASE(ADPCM_IMA_HVQM4,
1897 int format = bytestream2_get_be16(&gb);
1903 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1904 int v = bytestream2_get_byteu(&gb);
1910 for (
int n = nb_samples / 2; n > 0; n--) {
1912 int v = bytestream2_get_byteu(&gb);
1920 for (
int n = nb_samples / 2; n > 0; n--) {
1922 int v = bytestream2_get_byteu(&gb);
1929 CASE(ADPCM_IMA_CUNNING,
1931 int16_t *smp = samples_p[
channel];
1932 for (
int n = 0; n < nb_samples / 2; n++) {
1933 int v = bytestream2_get_byteu(&gb);
1940 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1941 int v = bytestream2_get_byteu(&gb);
1957 for (
int n = 0; n < nb_samples / 2; n++) {
1960 byte[0] = bytestream2_get_byteu(&gb);
1962 byte[1] = bytestream2_get_byteu(&gb);
1972 if (
c->vqa_version == 3) {
1973 for (int channel = 0; channel < channels; channel++) {
1974 int16_t *smp = samples_p[channel];
1976 for (int n = nb_samples / 2; n > 0; n--) {
1977 int v = bytestream2_get_byteu(&gb);
1978 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1979 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1983 for (
int n = nb_samples / 2; n > 0; n--) {
1985 int v = bytestream2_get_byteu(&gb);
1995 int bytes_remaining,
block = 0;
2002 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
2003 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
2004 scale = bytestream2_get_le16(&gb);
2006 out[0] = history[1];
2007 out[1] = history[0];
2009 for (
int n = 0; n < 15; n++) {
2010 unsigned byte = bytestream2_get_byte(&gb);
2016 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2017 history[1] = history[0];
2018 history[0] =
out[2+n*2];
2020 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2021 history[1] = history[0];
2022 history[0] =
out[2+n*2+1];
2029 if (bytes_remaining > 0) {
2034 int16_t *out0 = samples_p[0];
2035 int16_t *out1 = samples_p[1];
2036 int samples_per_block = 28 * (3 -
channels) * 4;
2037 int sample_offset = 0;
2038 int bytes_remaining;
2041 &
c->status[0], &
c->status[1],
2045 sample_offset += samples_per_block;
2050 if (bytes_remaining > 0) {
2054 CASE(ADPCM_IMA_ESCAPE,
2055 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2056 int byte = bytestream2_get_byteu(&gb);
2061 CASE(ADPCM_IMA_EA_EACS,
2062 for (
int i = 0;
i <= st;
i++) {
2063 c->status[
i].step_index = bytestream2_get_le32u(&gb);
2064 if (
c->status[
i].step_index > 88u) {
2066 i,
c->status[
i].step_index);
2070 for (
int i = 0;
i <= st;
i++) {
2071 c->status[
i].predictor = bytestream2_get_le32u(&gb);
2076 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2077 int byte = bytestream2_get_byteu(&gb);
2082 CASE(ADPCM_IMA_EA_SEAD,
2083 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2084 int byte = bytestream2_get_byteu(&gb);
2090 int previous_left_sample, previous_right_sample;
2091 int current_left_sample, current_right_sample;
2092 int next_left_sample, next_right_sample;
2093 int coeff1l, coeff2l, coeff1r, coeff2r;
2094 int shift_left, shift_right;
2102 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2103 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2104 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2105 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2107 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
2108 int byte = bytestream2_get_byteu(&gb);
2115 byte = bytestream2_get_byteu(&gb);
2116 shift_left = 20 - (
byte >> 4);
2117 shift_right = 20 - (
byte & 0x0F);
2120 shift_left = 20 - (
byte & 0x0F);
2123 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
2124 byte = bytestream2_get_byteu(&gb);
2125 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
2127 next_left_sample = (next_left_sample +
2128 (current_left_sample * coeff1l) +
2129 (previous_left_sample * coeff2l) + 0x80) >> 8;
2131 previous_left_sample = current_left_sample;
2133 *samples++ = current_left_sample;
2136 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
2138 next_right_sample = (next_right_sample +
2139 (current_right_sample * coeff1r) +
2140 (previous_right_sample * coeff2r) + 0x80) >> 8;
2142 previous_right_sample = current_right_sample;
2144 *samples++ = current_right_sample;
2146 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
2148 next_left_sample = (next_left_sample +
2149 (current_left_sample * coeff1l) +
2150 (previous_left_sample * coeff2l) + 0x80) >> 8;
2152 previous_left_sample = current_left_sample;
2155 *samples++ = current_left_sample;
2161 CASE(ADPCM_EA_MAXIS_XA,
2165 int byte = bytestream2_get_byteu(&gb);
2166 for (
int i = 0;
i < 2;
i++)
2170 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
2173 byte[0] = bytestream2_get_byteu(&gb);
2174 if (st)
byte[1] = bytestream2_get_byteu(&gb);
2175 for (
int i = 4;
i >= 0;
i-=4) {
2183 *samples++ =
c->status[
channel].sample1;
2189#
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
2198 int previous_sample, current_sample, next_sample;
2207 bytestream2_get_le32(&gb)) +
2214 samplesC = samples_p[
channel];
2217 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2218 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2220 current_sample =
c->status[
channel].predictor;
2221 previous_sample =
c->status[
channel].prev_sample;
2224 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2225 int byte = bytestream2_get_byte(&gb);
2227 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2228 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2230 for (
int count2 = 0; count2 < 28; count2++)
2231 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2235 shift = 20 - (
byte & 0x0F);
2237 for (
int count2 = 0; count2 < 28; count2++) {
2241 byte = bytestream2_get_byte(&gb);
2245 next_sample += (current_sample * coeff1) +
2246 (previous_sample * coeff2);
2249 previous_sample = current_sample;
2250 current_sample = next_sample;
2251 *samplesC++ = current_sample;
2257 }
else if (count != count1) {
2259 count =
FFMAX(count, count1);
2263 c->status[
channel].predictor = current_sample;
2264 c->status[
channel].prev_sample = previous_sample;
2268 frame->nb_samples = count * 28;
2277 for (
int n = 0; n < 4; n++,
s += 32) {
2279 for (
int i = 0;
i < 2;
i++)
2288 for (
int m = 2; m < 32; m += 2) {
2290 for (
int n = 0; n < 4; n++,
s += 32) {
2292 int byte = bytestream2_get_byteu(&gb);
2305 CASE(ADPCM_IMA_ACORN,
2309 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2316 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2317 int byte = bytestream2_get_byteu(&gb);
2335 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2336 c->status[0].step_index = bytestream2_get_byteu(&gb);
2338 if (
c->status[0].step_index > 88u) {
2340 c->status[0].step_index);
2344 for (
int n = nb_samples >> 1; n > 0; n--) {
2345 int v = bytestream2_get_byteu(&gb);
2351 if (nb_samples & 1) {
2352 int v = bytestream2_get_byteu(&gb);
2364 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2365 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2367 if (
c->status[
i].step_index > 88u) {
2369 c->status[
i].step_index);
2374 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2375 int v = bytestream2_get_byteu(&gb);
2381 CASE(ADPCM_IMA_SMJPEG,
2383 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2384 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2386 if (
c->status[
i].step_index > 88u) {
2388 c->status[
i].step_index);
2393 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2394 int v = bytestream2_get_byteu(&gb);
2401 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2402 int v = bytestream2_get_byteu(&gb);
2407#
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2408 CONFIG_ADPCM_SBPRO_4_DECODER
2412 if (!
c->status[0].step_index) {
2414 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2416 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2417 c->status[0].step_index = 1;
2421 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2422 int byte = bytestream2_get_byteu(&gb);
2423 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2425 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2429 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2430 int byte = bytestream2_get_byteu(&gb);
2431 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2433 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2434 (byte >> 2) & 0x07, 3, 0);
2435 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2439 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2440 int byte = bytestream2_get_byteu(&gb);
2444 (
byte >> 4) & 0x03, 2, 2);
2446 (
byte >> 2) & 0x03, 2, 2);
2458 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2459 int v = bytestream2_get_byteu(&gb);
2467 for (
int n = nb_samples >> 1; n > 0; n--) {
2468 int v = bytestream2_get_byteu(&gb);
2475 int samples_per_block;
2478 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
2479 samples_per_block = avctx->extradata[0] / 16;
2480 blocks = nb_samples / avctx->extradata[0];
2482 samples_per_block = nb_samples / 16;
2486 for (
int m = 0; m < blocks; m++) {
2488 int prev1 =
c->status[
channel].sample1;
2489 int prev2 =
c->status[
channel].sample2;
2491 samples = samples_p[
channel] + m * 16;
2493 for (
int i = 0;
i < samples_per_block;
i++) {
2494 int byte = bytestream2_get_byteu(&gb);
2495 int scale = 1 << (
byte >> 4);
2496 int index =
byte & 0xf;
2501 for (
int n = 0; n < 16; n++) {
2507 byte = bytestream2_get_byteu(&gb);
2511 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2519 c->status[
channel].sample1 = prev1;
2520 c->status[
channel].sample2 = prev2;
2525#
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2531#define THP_GET16(g) \
2533 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2534 bytestream2_get_le16u(&(g)) : \
2535 bytestream2_get_be16u(&(g)), 16)
2537 if (avctx->extradata) {
2539 if (avctx->extradata_size < 32 *
channels) {
2546 for (
int n = 0; n < 16; n++)
2547 table[
i][n] = THP_GET16(tb);
2550 for (
int n = 0; n < 16; n++)
2551 table[
i][n] = THP_GET16(gb);
2553 if (!
c->has_status) {
2556 c->status[
i].sample1 = THP_GET16(gb);
2557 c->status[
i].sample2 = THP_GET16(gb);
2565 for (
int ch = 0; ch <
channels; ch++) {
2566 samples = samples_p[ch];
2569 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2570 int byte = bytestream2_get_byteu(&gb);
2571 int index = (
byte >> 4) & 7;
2572 unsigned int exp =
byte & 0x0F;
2577 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2583 byte = bytestream2_get_byteu(&gb);
2587 sampledat = ((
c->status[ch].sample1 * factor1
2588 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2590 c->status[ch].sample2 =
c->status[ch].sample1;
2591 c->status[ch].sample1 = *samples++;
2603 for (
int i = 0;
i < nb_samples / 28;
i++) {
2607 header = bytestream2_get_byteu(&gb);
2611 for (
int n = 0; n < 28; n++) {
2616 prev = (
c->status[
channel].sample1 * 0x3c);
2619 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2622 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2630 byte = bytestream2_get_byteu(&gb);
2636 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2639 c->status[
channel].sample1 = sampledat;
2648 int coefs[8*2*8] = { 0 };
2650 if (avctx->extradata) {
2651 int version, order, entries;
2654 bytestream2_init(&cb, avctx->extradata, avctx->extradata_size);
2656 version = bytestream2_get_be16(&cb);
2657 order = bytestream2_get_be16(&cb);
2658 entries = bytestream2_get_be16(&cb);
2659 if (version != 1 || order != 2 || entries > 8)
2660 return AVERROR_INVALIDDATA;
2662 for (int n = 0; n < order * entries * 8; n++)
2663 coefs[n] = sign_extend(bytestream2_get_be16(&cb), 16);
2668 int16_t hist[8] = { 0 };
2669 const int order = 2;
2675 samples = samples_p[0] +
block * 16;
2677 scale = (buf[0] >> 4) & 0xF;
2678 index = (buf[0] >> 0) & 0xF;
2682 for (
int i = 0, j = 0;
i < 16;
i += 2, j++) {
2683 int n0 = (buf[j+1] >> 4) & 0xF;
2684 int n1 = (buf[j+1] >> 0) & 0xF;
2695 for (
int j = 0; j < 2; j++) {
2696 int *sf_codes = &codes[j*8];
2697 int16_t *sf_out = &
out[j*8];
2699 for (
int i = 0;
i < 8;
i++) {
2703 for (
int o = 0; o < order; o++)
2704 delta += coefs[o*8 +
i] * hist[(8 - order) + o];
2706 for (
int k =
i-1; k > -1; k--) {
2707 for (
int o = 1; o < order; o++)
2708 delta += sf_codes[(
i-1) - k] * (unsigned)coefs[(o*8) + k];
2717 for (
int i = 8 - order;
i < 8;
i++)
2718 hist[
i] = sf_out[
i];
2721 memcpy(samples,
out,
sizeof(
out));
2734 samples = samples_p[
channel] +
block * nb_samples_per_block;
2738 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2741 filter = bytestream2_get_byteu(&gb);
2746 flag = bytestream2_get_byteu(&gb) & 0x7;
2749 for (
int n = 0; n < 28; n++) {
2755 byte = bytestream2_get_byteu(&gb);
2772 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2773 int nb_samples_per_block = ((avctx->block_align - 1) /
channels) * 2;
2777 samples = samples_p[
channel] +
block * nb_samples_per_block;
2780 filter = bytestream2_get_byteu(&gb);
2786 for (
int n = 0; n < nb_samples_per_block; n++) {
2792 byte = bytestream2_get_byteu(&gb);
2809 switch(avctx->bits_per_coded_sample) {
2810 case 3: expand = adpcm_sanyo_expand3; break;
2811 case 4: expand = adpcm_sanyo_expand4; break;
2812 case 5: expand = adpcm_sanyo_expand5; break;
2816 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2817 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2821 for (
int i = 0;
i < nb_samples;
i++)
2822 for (
int ch = 0; ch <
channels; ch++)
2846 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2854 control = bytestream2_get_byteu(&gb);
2855 shift = (control >> 4) + 2;
2857 for (
int n = 0; n < 16; n++) {
2858 int sample = bytestream2_get_byteu(&gb);
2866 for (
int n = 0; n < nb_samples; n++) {
2867 for (
int ch = 0; ch <
channels; ch++) {
2868 int v = bytestream2_get_byteu(&gb);
2874 for (
int n = 0; n < nb_samples *
channels; n++) {
2875 int v = bytestream2_get_byteu(&gb);
2880 for (
int n = nb_samples / 2; n > 0; n--) {
2882 int v = bytestream2_get_byteu(&gb);
2890 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");