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, },
245 40, 130, 232, 350, 493, 673, 927, 1382,
246 60, 195, 348, 526, 740, 1010, 1391, 2074,
247 85, 277, 494, 745, 1048, 1431, 1971, 2938,
248 121, 391, 697, 1052, 1480, 2021, 2782, 4148,
249 176, 570, 1017, 1535, 2158, 2947, 4058, 6050,
250 257, 831, 1482, 2236, 3145, 4295, 5913, 8815,
251 373, 1206, 2151, 3245, 4564, 6232, 8579, 12791,
252 534, 1728, 3082, 4649, 6538, 8928, 12290, 18323,
253 782, 2527, 4507, 6798, 9560, 13055, 17971, 26793,
254 1115, 3603, 6426, 9692, 13631, 18614, 25623, 32767,
255 1620, 5233, 9334, 14078, 19799, 27036, 32767, 32767,
256 2361, 7630, 13608, 20526, 28866, 32767, 32767, 32767,
257 3447, 11136, 19860, 29955, 32767, 32767, 32767, 32767,
258 4865, 15717, 28031, 32767, 32767, 32767, 32767, 32767,
259 6888, 22255, 32767, 32767, 32767, 32767, 32767, 32767,
260 -10336, 32144, 5984,-24288, 4752, 24112, 24688,-26336,
1526 int *got_frame_ptr,
AVPacket *avpkt)
1528 const uint8_t *buf = avpkt->
data;
1529 int buf_size = avpkt->
size;
1533 int16_t **samples_p;
1535 int nb_samples, coded_samples, approx_nb_samples, ret;
1539 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1540 if (nb_samples <= 0) {
1546 frame->nb_samples = nb_samples;
1549 samples = (int16_t *)
frame->data[0];
1550 samples_p = (int16_t **)
frame->extended_data;
1554 if (coded_samples) {
1555 if (!approx_nb_samples && coded_samples != nb_samples)
1557 frame->nb_samples = nb_samples = coded_samples;
1597 for (
int m = 0; m < 64; m += 2) {
1598 int byte = bytestream2_get_byteu(&gb);
1619 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1620 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1621 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1624 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1627 samples = &samples_p[
i][1 + n * samples_per_block];
1628 for (
int j = 0; j < block_size; j++) {
1630 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1635 for (
int m = 0; m < samples_per_block; m++) {
1643 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1646 samples = &samples_p[
i][1 + n * 8];
1647 for (
int m = 0; m < 8; m += 2) {
1648 int v = bytestream2_get_byteu(&gb);
1656 CASE(ADPCM_IMA_XBOX,
1669 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1672 samples = &samples_p[
i][1 + n * 8];
1673 for (
int m = 0; m < 8; m += 2) {
1674 int v = bytestream2_get_byteu(&gb);
1680 frame->nb_samples--;
1684 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1687 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1688 if (
c->status[
i].step_index > 88u) {
1690 i,
c->status[
i].step_index);
1697 samples = (int16_t *)
frame->data[
i];
1698 for (
int n = nb_samples >> 1; n > 0; n--) {
1699 int v = bytestream2_get_byteu(&gb);
1707 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1709 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1711 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1712 int v = bytestream2_get_byteu(&gb);
1718 int block_predictor;
1723 block_predictor = bytestream2_get_byteu(&gb);
1724 if (block_predictor > 6) {
1734 *samples++ =
c->status[
channel].sample2;
1735 *samples++ =
c->status[
channel].sample1;
1736 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1737 int byte = bytestream2_get_byteu(&gb);
1743 block_predictor = bytestream2_get_byteu(&gb);
1744 if (block_predictor > 6) {
1752 block_predictor = bytestream2_get_byteu(&gb);
1753 if (block_predictor > 6) {
1761 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1763 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1766 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1767 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1768 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1769 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1771 *samples++ =
c->status[0].sample2;
1772 if (st) *samples++ =
c->status[1].sample2;
1773 *samples++ =
c->status[0].sample1;
1774 if (st) *samples++ =
c->status[1].sample1;
1775 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1776 int byte = bytestream2_get_byteu(&gb);
1785 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1786 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1791 for (
int n = 0; n < nb_samples; n += 2) {
1792 int v = bytestream2_get_byteu(&gb);
1796 for (
int n = 0; n < nb_samples; n += 2) {
1797 int v = bytestream2_get_byteu(&gb);
1814 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1815 int v = bytestream2_get_byteu(&gb);
1823 if (decode_top_nibble_next) { \
1824 nibble = last_byte >> 4; \
1825 decode_top_nibble_next = 0; \
1827 last_byte = bytestream2_get_byteu(&gb); \
1828 nibble = last_byte & 0x0F; \
1829 decode_top_nibble_next = 1; \
1834 int decode_top_nibble_next = 0;
1836 const int16_t *samples_end = samples +
channels * nb_samples;
1839 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1840 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1841 c->status[0].step_index = bytestream2_get_byteu(&gb);
1842 c->status[1].step_index = bytestream2_get_byteu(&gb);
1843 if (
c->status[0].step_index > 88u ||
c->status[1].step_index > 88u){
1845 c->status[0].step_index,
c->status[1].step_index);
1849 diff_channel =
c->status[1].predictor;
1851 while (samples < samples_end) {
1865 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1866 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1867 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1874 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1875 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1876 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1882 CASE(ADPCM_IMA_MAGIX,
1894 for (
int m = 0; m <
channels*nb_samples/16; m ++) {
1895 uint32_t v0 = bytestream2_get_le32u(&gb);
1896 uint32_t v1 = bytestream2_get_le32u(&gb);
1898 for (
int n = 8; n > 0; n--, v0 >>= 4, v1 >>= 4, samples += 2) {
1916 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1918 int v = bytestream2_get_byteu(&gb);
1931 CASE(ADPCM_IMA_MOFLEX,
1943 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1945 samples = samples_p[
channel] + 256 * subframe;
1946 for (
int n = 0; n < 256; n += 2) {
1947 int v = bytestream2_get_byteu(&gb);
1954 CASE(ADPCM_IMA_DAT4,
1959 for (
int n = 0; n < nb_samples; n += 2) {
1960 int v = bytestream2_get_byteu(&gb);
1967 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1968 int v = bytestream2_get_byteu(&gb);
1973 CASE(ADPCM_IMA_HVQM2,
1974 int format = bytestream2_get_be16(&gb);
1979 CASE(ADPCM_IMA_HVQM4,
1980 int format = bytestream2_get_be16(&gb);
1986 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1987 int v = bytestream2_get_byteu(&gb);
1993 for (
int n = nb_samples / 2; n > 0; n--) {
1995 int v = bytestream2_get_byteu(&gb);
2003 for (
int n = nb_samples / 2; n > 0; n--) {
2005 int v = bytestream2_get_byteu(&gb);
2012 CASE(ADPCM_IMA_CUNNING,
2014 int16_t *smp = samples_p[
channel];
2015 for (
int n = 0; n < nb_samples / 2; n++) {
2016 int v = bytestream2_get_byteu(&gb);
2023 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2024 int v = bytestream2_get_byteu(&gb);
2040 for (
int n = 0; n < nb_samples / 2; n++) {
2043 byte[0] = bytestream2_get_byteu(&gb);
2045 byte[1] = bytestream2_get_byteu(&gb);
2055 if (
c->vqa_version == 3) {
2056 for (int channel = 0; channel < channels; channel++) {
2057 int16_t *smp = samples_p[channel];
2059 for (int n = nb_samples / 2; n > 0; n--) {
2060 int v = bytestream2_get_byteu(&gb);
2061 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
2062 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
2066 for (
int n = nb_samples / 2; n > 0; n--) {
2068 int v = bytestream2_get_byteu(&gb);
2078 int bytes_remaining,
block = 0;
2085 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
2086 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
2087 scale = bytestream2_get_le16(&gb);
2089 out[0] = history[1];
2090 out[1] = history[0];
2092 for (
int n = 0; n < 15; n++) {
2093 unsigned byte = bytestream2_get_byte(&gb);
2099 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2100 history[1] = history[0];
2101 history[0] =
out[2+n*2];
2103 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2104 history[1] = history[0];
2105 history[0] =
out[2+n*2+1];
2112 if (bytes_remaining > 0) {
2117 int16_t *out0 = samples_p[0];
2118 int16_t *out1 = samples_p[1];
2119 int samples_per_block = 28 * (3 -
channels) * 4;
2120 int sample_offset = 0;
2121 int bytes_remaining;
2124 &
c->status[0], &
c->status[1],
2128 sample_offset += samples_per_block;
2133 if (bytes_remaining > 0) {
2137 CASE(ADPCM_IMA_ESCAPE,
2138 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2139 int byte = bytestream2_get_byteu(&gb);
2144 CASE(ADPCM_IMA_EA_EACS,
2145 for (
int i = 0;
i <= st;
i++) {
2146 c->status[
i].step_index = bytestream2_get_le32u(&gb);
2147 if (
c->status[
i].step_index > 88u) {
2149 i,
c->status[
i].step_index);
2153 for (
int i = 0;
i <= st;
i++) {
2154 c->status[
i].predictor = bytestream2_get_le32u(&gb);
2159 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2160 int byte = bytestream2_get_byteu(&gb);
2165 CASE(ADPCM_IMA_EA_SEAD,
2166 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2167 int byte = bytestream2_get_byteu(&gb);
2173 int previous_left_sample, previous_right_sample;
2174 int current_left_sample, current_right_sample;
2175 int next_left_sample, next_right_sample;
2176 int coeff1l, coeff2l, coeff1r, coeff2r;
2177 int shift_left, shift_right;
2185 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2186 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2187 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2188 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2190 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
2191 int byte = bytestream2_get_byteu(&gb);
2198 byte = bytestream2_get_byteu(&gb);
2199 shift_left = 20 - (
byte >> 4);
2200 shift_right = 20 - (
byte & 0x0F);
2203 shift_left = 20 - (
byte & 0x0F);
2206 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
2207 byte = bytestream2_get_byteu(&gb);
2208 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
2210 next_left_sample = (next_left_sample +
2211 (current_left_sample * coeff1l) +
2212 (previous_left_sample * coeff2l) + 0x80) >> 8;
2214 previous_left_sample = current_left_sample;
2216 *samples++ = current_left_sample;
2219 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
2221 next_right_sample = (next_right_sample +
2222 (current_right_sample * coeff1r) +
2223 (previous_right_sample * coeff2r) + 0x80) >> 8;
2225 previous_right_sample = current_right_sample;
2227 *samples++ = current_right_sample;
2229 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
2231 next_left_sample = (next_left_sample +
2232 (current_left_sample * coeff1l) +
2233 (previous_left_sample * coeff2l) + 0x80) >> 8;
2235 previous_left_sample = current_left_sample;
2238 *samples++ = current_left_sample;
2244 CASE(ADPCM_EA_MAXIS_XA,
2248 int byte = bytestream2_get_byteu(&gb);
2249 for (
int i = 0;
i < 2;
i++)
2253 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
2256 byte[0] = bytestream2_get_byteu(&gb);
2257 if (st)
byte[1] = bytestream2_get_byteu(&gb);
2258 for (
int i = 4;
i >= 0;
i-=4) {
2266 *samples++ =
c->status[
channel].sample1;
2272#
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
2281 int previous_sample, current_sample, next_sample;
2290 bytestream2_get_le32(&gb)) +
2297 samplesC = samples_p[
channel];
2300 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2301 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2303 current_sample =
c->status[
channel].predictor;
2304 previous_sample =
c->status[
channel].prev_sample;
2307 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2308 int byte = bytestream2_get_byte(&gb);
2310 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2311 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2313 for (
int count2 = 0; count2 < 28; count2++)
2314 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2318 shift = 20 - (
byte & 0x0F);
2320 for (
int count2 = 0; count2 < 28; count2++) {
2324 byte = bytestream2_get_byte(&gb);
2328 next_sample += (current_sample * coeff1) +
2329 (previous_sample * coeff2);
2332 previous_sample = current_sample;
2333 current_sample = next_sample;
2334 *samplesC++ = current_sample;
2340 }
else if (count != count1) {
2342 count =
FFMAX(count, count1);
2346 c->status[
channel].predictor = current_sample;
2347 c->status[
channel].prev_sample = previous_sample;
2351 frame->nb_samples = count * 28;
2360 for (
int n = 0; n < 4; n++,
s += 32) {
2362 for (
int i = 0;
i < 2;
i++)
2371 for (
int m = 2; m < 32; m += 2) {
2373 for (
int n = 0; n < 4; n++,
s += 32) {
2375 int byte = bytestream2_get_byteu(&gb);
2388 CASE(ADPCM_IMA_ACORN,
2392 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2399 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2400 int byte = bytestream2_get_byteu(&gb);
2418 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2419 c->status[0].step_index = bytestream2_get_byteu(&gb);
2421 if (
c->status[0].step_index > 88u) {
2423 c->status[0].step_index);
2427 for (
int n = nb_samples >> 1; n > 0; n--) {
2428 int v = bytestream2_get_byteu(&gb);
2434 if (nb_samples & 1) {
2435 int v = bytestream2_get_byteu(&gb);
2447 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2448 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2450 if (
c->status[
i].step_index > 88u) {
2452 c->status[
i].step_index);
2457 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2458 int v = bytestream2_get_byteu(&gb);
2464 CASE(ADPCM_IMA_SMJPEG,
2466 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2467 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2469 if (
c->status[
i].step_index > 88u) {
2471 c->status[
i].step_index);
2476 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2477 int v = bytestream2_get_byteu(&gb);
2484 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2485 int v = bytestream2_get_byteu(&gb);
2490#
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2491 CONFIG_ADPCM_SBPRO_4_DECODER
2495 if (!
c->status[0].step_index) {
2497 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2499 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2500 c->status[0].step_index = 1;
2504 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2505 int byte = bytestream2_get_byteu(&gb);
2506 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2508 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2512 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2513 int byte = bytestream2_get_byteu(&gb);
2514 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2516 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2517 (byte >> 2) & 0x07, 3, 0);
2518 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2522 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2523 int byte = bytestream2_get_byteu(&gb);
2527 (
byte >> 4) & 0x03, 2, 2);
2529 (
byte >> 2) & 0x03, 2, 2);
2541 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2542 int v = bytestream2_get_byteu(&gb);
2550 for (
int n = nb_samples >> 1; n > 0; n--) {
2551 int v = bytestream2_get_byteu(&gb);
2558 int samples_per_block;
2561 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
2562 samples_per_block = avctx->extradata[0] / 16;
2563 blocks = nb_samples / avctx->extradata[0];
2565 samples_per_block = nb_samples / 16;
2569 for (
int m = 0; m < blocks; m++) {
2571 int prev1 =
c->status[
channel].sample1;
2572 int prev2 =
c->status[
channel].sample2;
2574 samples = samples_p[
channel] + m * 16;
2576 for (
int i = 0;
i < samples_per_block;
i++) {
2577 int byte = bytestream2_get_byteu(&gb);
2578 int scale = 1 << (
byte >> 4);
2579 int index =
byte & 0xf;
2584 for (
int n = 0; n < 16; n++) {
2590 byte = bytestream2_get_byteu(&gb);
2594 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2602 c->status[
channel].sample1 = prev1;
2603 c->status[
channel].sample2 = prev2;
2608#
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2614#define THP_GET16(g) \
2616 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2617 bytestream2_get_le16u(&(g)) : \
2618 bytestream2_get_be16u(&(g)), 16)
2620 if (avctx->extradata) {
2622 if (avctx->extradata_size < 32 *
channels) {
2629 for (
int n = 0; n < 16; n++)
2630 table[
i][n] = THP_GET16(tb);
2633 for (
int n = 0; n < 16; n++)
2634 table[
i][n] = THP_GET16(gb);
2636 if (!
c->has_status) {
2639 c->status[
i].sample1 = THP_GET16(gb);
2640 c->status[
i].sample2 = THP_GET16(gb);
2648 for (
int ch = 0; ch <
channels; ch++) {
2649 samples = samples_p[ch];
2652 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2653 int byte = bytestream2_get_byteu(&gb);
2654 int index = (
byte >> 4) & 7;
2655 unsigned int exp =
byte & 0x0F;
2660 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2666 byte = bytestream2_get_byteu(&gb);
2670 sampledat = ((
c->status[ch].sample1 * factor1
2671 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2673 c->status[ch].sample2 =
c->status[ch].sample1;
2674 c->status[ch].sample1 = *samples++;
2686 for (
int i = 0;
i < nb_samples / 28;
i++) {
2690 header = bytestream2_get_byteu(&gb);
2694 for (
int n = 0; n < 28; n++) {
2699 prev = (
c->status[
channel].sample1 * 0x3c);
2702 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2705 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2713 byte = bytestream2_get_byteu(&gb);
2719 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2722 c->status[
channel].sample1 = sampledat;
2731 int coefs[8*2*8] = { 0 };
2733 if (avctx->extradata) {
2734 int version, order, entries;
2737 bytestream2_init(&cb, avctx->extradata, avctx->extradata_size);
2739 version = bytestream2_get_be16(&cb);
2740 order = bytestream2_get_be16(&cb);
2741 entries = bytestream2_get_be16(&cb);
2742 if (version != 1 || order != 2 || entries > 8)
2743 return AVERROR_INVALIDDATA;
2745 for (int n = 0; n < order * entries * 8; n++)
2746 coefs[n] = sign_extend(bytestream2_get_be16(&cb), 16);
2751 int16_t hist[8] = { 0 };
2752 const int order = 2;
2758 samples = samples_p[0] +
block * 16;
2760 scale = (buf[0] >> 4) & 0xF;
2761 index = (buf[0] >> 0) & 0xF;
2765 for (
int i = 0, j = 0;
i < 16;
i += 2, j++) {
2766 int n0 = (buf[j+1] >> 4) & 0xF;
2767 int n1 = (buf[j+1] >> 0) & 0xF;
2778 for (
int j = 0; j < 2; j++) {
2779 int *sf_codes = &codes[j*8];
2780 int16_t *sf_out = &
out[j*8];
2782 for (
int i = 0;
i < 8;
i++) {
2786 for (
int o = 0; o < order; o++)
2787 delta += coefs[o*8 +
i] * hist[(8 - order) + o];
2789 for (
int k =
i-1; k > -1; k--) {
2790 for (
int o = 1; o < order; o++)
2791 delta += sf_codes[(
i-1) - k] * (unsigned)coefs[(o*8) + k];
2800 for (
int i = 8 - order;
i < 8;
i++)
2801 hist[
i] = sf_out[
i];
2804 memcpy(samples,
out,
sizeof(
out));
2817 samples = samples_p[
channel] +
block * nb_samples_per_block;
2821 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2824 filter = bytestream2_get_byteu(&gb);
2829 flag = bytestream2_get_byteu(&gb) & 0x7;
2832 for (
int n = 0; n < 28; n++) {
2838 byte = bytestream2_get_byteu(&gb);
2855 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2856 int nb_samples_per_block = ((avctx->block_align - 1) /
channels) * 2;
2860 samples = samples_p[
channel] +
block * nb_samples_per_block;
2863 filter = bytestream2_get_byteu(&gb);
2869 for (
int n = 0; n < nb_samples_per_block; n++) {
2875 byte = bytestream2_get_byteu(&gb);
2892 switch(avctx->bits_per_coded_sample) {
2893 case 3: expand = adpcm_sanyo_expand3; break;
2894 case 4: expand = adpcm_sanyo_expand4; break;
2895 case 5: expand = adpcm_sanyo_expand5; break;
2899 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2900 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2904 for (
int i = 0;
i < nb_samples;
i++)
2905 for (
int ch = 0; ch <
channels; ch++)
2911 CASE(ADPCM_RHETOREX,
2912 for (
int i = 0;
i < nb_samples / 2;
i++) {
2913 uint8_t
byte = bytestream2_get_byteu(&gb);
2936 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2944 control = bytestream2_get_byteu(&gb);
2945 shift = (control >> 4) + 2;
2947 for (
int n = 0; n < 16; n++) {
2948 int sample = bytestream2_get_byteu(&gb);
2956 for (
int n = 0; n < nb_samples; n++) {
2957 for (
int ch = 0; ch <
channels; ch++) {
2958 int v = bytestream2_get_byteu(&gb);
2964 for (
int n = 0; n < nb_samples *
channels; n++) {
2965 int v = bytestream2_get_byteu(&gb);
2970 for (
int n = nb_samples / 2; n > 0; n--) {
2972 int v = bytestream2_get_byteu(&gb);
2979 CASE(ADPCM_IMA_CITRIX,
2981 for (int ch = 0; ch < channels; ch++) {
2982 *samples++ = c->status[ch].predictor = sign_extend(bytestream2_get_le16(&gb), 16);
2983 c->status[ch].step_index = bytestream2_get_byte(&gb);
2984 if (c->status[ch].step_index > 88)
2985 return AVERROR_INVALIDDATA;
2986 bytestream2_skip(&gb, 1);
2990 uint8_t
bits = bytestream2_get_byteu(&gb);
2999 for (
int ch = 0; ch <
channels; ch++) {
3000 uint32_t
bits = bytestream2_get_le32(&gb);
3001 for (
int j = 0; j < 16; j++)
3010 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");