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,
1544 int *got_frame_ptr,
AVPacket *avpkt)
1546 const uint8_t *buf = avpkt->
data;
1547 int buf_size = avpkt->
size;
1553 int nb_samples, coded_samples, approx_nb_samples,
ret;
1557 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1558 if (nb_samples <= 0) {
1564 frame->nb_samples = nb_samples;
1567 samples = (int16_t *)
frame->data[0];
1568 samples_p = (int16_t **)
frame->extended_data;
1572 if (coded_samples) {
1573 if (!approx_nb_samples && coded_samples != nb_samples)
1575 frame->nb_samples = nb_samples = coded_samples;
1615 for (
int m = 0; m < 64; m += 2) {
1616 int byte = bytestream2_get_byteu(&gb);
1637 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1638 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1639 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1642 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1645 samples = &samples_p[
i][1 + n * samples_per_block];
1646 for (
int j = 0; j < block_size; j++) {
1648 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1653 for (
int m = 0; m < samples_per_block; m++) {
1661 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1664 samples = &samples_p[
i][1 + n * 8];
1665 for (
int m = 0; m < 8; m += 2) {
1666 int v = bytestream2_get_byteu(&gb);
1674 CASE(ADPCM_IMA_XBOX,
1687 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1690 samples = &samples_p[
i][1 + n * 8];
1691 for (
int m = 0; m < 8; m += 2) {
1692 int v = bytestream2_get_byteu(&gb);
1698 frame->nb_samples--;
1702 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1705 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1706 if (
c->status[
i].step_index > 88u) {
1708 i,
c->status[
i].step_index);
1715 samples = (int16_t *)
frame->data[
i];
1716 for (
int n = nb_samples >> 1; n > 0; n--) {
1717 int v = bytestream2_get_byteu(&gb);
1725 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1727 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1729 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1730 int v = bytestream2_get_byteu(&gb);
1736 int block_predictor;
1741 block_predictor = bytestream2_get_byteu(&gb);
1742 if (block_predictor > 6) {
1752 *samples++ =
c->status[
channel].sample2;
1753 *samples++ =
c->status[
channel].sample1;
1754 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1755 int byte = bytestream2_get_byteu(&gb);
1761 block_predictor = bytestream2_get_byteu(&gb);
1762 if (block_predictor > 6) {
1770 block_predictor = bytestream2_get_byteu(&gb);
1771 if (block_predictor > 6) {
1779 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1781 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1784 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1785 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1786 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1787 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1789 *samples++ =
c->status[0].sample2;
1790 if (st) *samples++ =
c->status[1].sample2;
1791 *samples++ =
c->status[0].sample1;
1792 if (st) *samples++ =
c->status[1].sample1;
1793 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1794 int byte = bytestream2_get_byteu(&gb);
1803 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1804 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1809 for (
int n = 0; n < nb_samples; n += 2) {
1810 int v = bytestream2_get_byteu(&gb);
1814 for (
int n = 0; n < nb_samples; n += 2) {
1815 int v = bytestream2_get_byteu(&gb);
1832 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1833 int v = bytestream2_get_byteu(&gb);
1841 if (decode_top_nibble_next) { \
1842 nibble = last_byte >> 4; \
1843 decode_top_nibble_next = 0; \
1845 last_byte = bytestream2_get_byteu(&gb); \
1846 nibble = last_byte & 0x0F; \
1847 decode_top_nibble_next = 1; \
1852 int decode_top_nibble_next = 0;
1854 const int16_t *samples_end = samples +
channels * nb_samples;
1857 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1858 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1859 c->status[0].step_index = bytestream2_get_byteu(&gb);
1860 c->status[1].step_index = bytestream2_get_byteu(&gb);
1861 if (
c->status[0].step_index > 88u ||
c->status[1].step_index > 88u){
1863 c->status[0].step_index,
c->status[1].step_index);
1867 diff_channel =
c->status[1].predictor;
1869 while (samples < samples_end) {
1883 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1884 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1885 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1892 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1893 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1894 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1900 CASE(ADPCM_IMA_MAGIX,
1912 for (
int m = 0; m <
channels*nb_samples/16; m ++) {
1913 uint32_t v0 = bytestream2_get_le32u(&gb);
1914 uint32_t v1 = bytestream2_get_le32u(&gb);
1916 for (
int n = 8; n > 0; n--, v0 >>= 4, v1 >>= 4, samples += 2) {
1934 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1936 int v = bytestream2_get_byteu(&gb);
1949 CASE(ADPCM_IMA_MOFLEX,
1961 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1963 samples = samples_p[
channel] + 256 * subframe;
1964 for (
int n = 0; n < 256; n += 2) {
1965 int v = bytestream2_get_byteu(&gb);
1972 CASE(ADPCM_IMA_DAT4,
1977 for (
int n = 0; n < nb_samples; n += 2) {
1978 int v = bytestream2_get_byteu(&gb);
1985 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1986 int v = bytestream2_get_byteu(&gb);
1991 CASE(ADPCM_IMA_HVQM2,
1992 int format = bytestream2_get_be16(&gb);
1995 decode_adpcm_ima_hvqm2(avctx, samples, nb_samples,
format, &gb);
1997 CASE(ADPCM_IMA_HVQM4,
1998 int format = bytestream2_get_be16(&gb);
2001 decode_adpcm_ima_hvqm4(avctx, samples, nb_samples,
format, &gb);
2004 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2005 int v = bytestream2_get_byteu(&gb);
2011 for (
int n = nb_samples / 2; n > 0; n--) {
2013 int v = bytestream2_get_byteu(&gb);
2021 for (
int n = nb_samples / 2; n > 0; n--) {
2023 int v = bytestream2_get_byteu(&gb);
2030 CASE(ADPCM_IMA_CUNNING,
2032 int16_t *smp = samples_p[
channel];
2033 for (
int n = 0; n < nb_samples / 2; n++) {
2034 int v = bytestream2_get_byteu(&gb);
2041 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2042 int v = bytestream2_get_byteu(&gb);
2058 for (
int n = 0; n < nb_samples / 2; n++) {
2061 byte[0] = bytestream2_get_byteu(&gb);
2063 byte[1] = bytestream2_get_byteu(&gb);
2073 if (
c->vqa_version == 3) {
2074 for (int channel = 0; channel < channels; channel++) {
2075 int16_t *smp = samples_p[channel];
2077 for (int n = nb_samples / 2; n > 0; n--) {
2078 int v = bytestream2_get_byteu(&gb);
2079 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
2080 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
2084 for (
int n = nb_samples / 2; n > 0; n--) {
2086 int v = bytestream2_get_byteu(&gb);
2096 int bytes_remaining,
block = 0;
2103 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
2104 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
2105 scale = bytestream2_get_le16(&gb);
2107 out[0] = history[1];
2108 out[1] = history[0];
2110 for (
int n = 0; n < 15; n++) {
2111 unsigned byte = bytestream2_get_byte(&gb);
2117 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2118 history[1] = history[0];
2119 history[0] =
out[2+n*2];
2121 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2122 history[1] = history[0];
2123 history[0] =
out[2+n*2+1];
2130 if (bytes_remaining > 0) {
2135 int16_t *out0 = samples_p[0];
2136 int16_t *out1 = samples_p[1];
2137 int samples_per_block = 28 * (3 -
channels) * 4;
2138 int sample_offset = 0;
2139 int bytes_remaining;
2142 &
c->status[0], &
c->status[1],
2146 sample_offset += samples_per_block;
2151 if (bytes_remaining > 0) {
2155 CASE(ADPCM_IMA_ESCAPE,
2156 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2157 int byte = bytestream2_get_byteu(&gb);
2158 *samples++ = adpcm_ima_escape_expand_nibble(&
c->status[0],
byte >> 4);
2159 *samples++ = adpcm_ima_escape_expand_nibble(&
c->status[st],
byte & 0xF);
2162 CASE(ADPCM_IMA_EA_EACS,
2163 for (
int i = 0;
i <= st;
i++) {
2164 c->status[
i].step_index = bytestream2_get_le32u(&gb);
2165 if (
c->status[
i].step_index > 88u) {
2167 i,
c->status[
i].step_index);
2171 for (
int i = 0;
i <= st;
i++) {
2172 c->status[
i].predictor = bytestream2_get_le32u(&gb);
2177 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2178 int byte = bytestream2_get_byteu(&gb);
2183 CASE(ADPCM_IMA_EA_SEAD,
2184 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2185 int byte = bytestream2_get_byteu(&gb);
2191 int previous_left_sample, previous_right_sample;
2192 int current_left_sample, current_right_sample;
2193 int next_left_sample, next_right_sample;
2194 int coeff1l, coeff2l, coeff1r, coeff2r;
2195 int shift_left, shift_right;
2203 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2204 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2205 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2206 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2208 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
2209 int byte = bytestream2_get_byteu(&gb);
2216 byte = bytestream2_get_byteu(&gb);
2217 shift_left = 20 - (
byte >> 4);
2218 shift_right = 20 - (
byte & 0x0F);
2221 shift_left = 20 - (
byte & 0x0F);
2224 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
2225 byte = bytestream2_get_byteu(&gb);
2226 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
2228 next_left_sample = (next_left_sample +
2229 (current_left_sample * coeff1l) +
2230 (previous_left_sample * coeff2l) + 0x80) >> 8;
2232 previous_left_sample = current_left_sample;
2234 *samples++ = current_left_sample;
2237 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
2239 next_right_sample = (next_right_sample +
2240 (current_right_sample * coeff1r) +
2241 (previous_right_sample * coeff2r) + 0x80) >> 8;
2243 previous_right_sample = current_right_sample;
2245 *samples++ = current_right_sample;
2247 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
2249 next_left_sample = (next_left_sample +
2250 (current_left_sample * coeff1l) +
2251 (previous_left_sample * coeff2l) + 0x80) >> 8;
2253 previous_left_sample = current_left_sample;
2256 *samples++ = current_left_sample;
2262 CASE(ADPCM_EA_MAXIS_XA,
2263 int coeff[2][2],
shift[2];
2266 int byte = bytestream2_get_byteu(&gb);
2267 for (
int i = 0;
i < 2;
i++)
2271 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
2274 byte[0] = bytestream2_get_byteu(&gb);
2275 if (st)
byte[1] = bytestream2_get_byteu(&gb);
2276 for (
int i = 4;
i >= 0;
i-=4) {
2284 *samples++ =
c->status[
channel].sample1;
2290#
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
2299 int previous_sample, current_sample, next_sample;
2308 bytestream2_get_le32(&gb)) +
2315 samplesC = samples_p[
channel];
2318 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2319 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2321 current_sample =
c->status[
channel].predictor;
2322 previous_sample =
c->status[
channel].prev_sample;
2325 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2326 int byte = bytestream2_get_byte(&gb);
2328 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2329 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2331 for (
int count2 = 0; count2 < 28; count2++)
2332 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2336 shift = 20 - (
byte & 0x0F);
2338 for (
int count2 = 0; count2 < 28; count2++) {
2342 byte = bytestream2_get_byte(&gb);
2346 next_sample += (current_sample * coeff1) +
2347 (previous_sample * coeff2);
2350 previous_sample = current_sample;
2351 current_sample = next_sample;
2352 *samplesC++ = current_sample;
2358 }
else if (count != count1) {
2360 count =
FFMAX(count, count1);
2364 c->status[
channel].predictor = current_sample;
2365 c->status[
channel].prev_sample = previous_sample;
2369 frame->nb_samples = count * 28;
2376 int coeff[2][4],
shift[4];
2378 for (
int n = 0; n < 4; n++,
s += 32) {
2380 for (
int i = 0;
i < 2;
i++)
2389 for (
int m = 2; m < 32; m += 2) {
2391 for (
int n = 0; n < 4; n++,
s += 32) {
2393 int byte = bytestream2_get_byteu(&gb);
2396 pred =
s[-1] * coeff[0][n] +
s[-2] * coeff[1][n];
2400 pred =
s[0] * coeff[0][n] +
s[-1] * coeff[1][n];
2406 CASE(ADPCM_IMA_ACORN,
2410 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2417 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2418 int byte = bytestream2_get_byteu(&gb);
2436 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2437 c->status[0].step_index = bytestream2_get_byteu(&gb);
2439 if (
c->status[0].step_index > 88u) {
2441 c->status[0].step_index);
2445 for (
int n = nb_samples >> 1; n > 0; n--) {
2446 int v = bytestream2_get_byteu(&gb);
2452 if (nb_samples & 1) {
2453 int v = bytestream2_get_byteu(&gb);
2465 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2466 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2468 if (
c->status[
i].step_index > 88u) {
2470 c->status[
i].step_index);
2475 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2476 int v = bytestream2_get_byteu(&gb);
2482 CASE(ADPCM_IMA_SMJPEG,
2484 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2485 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2487 if (
c->status[
i].step_index > 88u) {
2489 c->status[
i].step_index);
2494 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2495 int v = bytestream2_get_byteu(&gb);
2502 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2503 int v = bytestream2_get_byteu(&gb);
2508#
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2509 CONFIG_ADPCM_SBPRO_4_DECODER
2513 if (!
c->status[0].step_index) {
2515 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2517 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2518 c->status[0].step_index = 1;
2522 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2523 int byte = bytestream2_get_byteu(&gb);
2524 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2526 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2530 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2531 int byte = bytestream2_get_byteu(&gb);
2532 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2534 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2535 (byte >> 2) & 0x07, 3, 0);
2536 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2540 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2541 int byte = bytestream2_get_byteu(&gb);
2545 (
byte >> 4) & 0x03, 2, 2);
2547 (
byte >> 2) & 0x03, 2, 2);
2555 adpcm_swf_decode(avctx, buf, buf_size, samples);
2559 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2560 int v = bytestream2_get_byteu(&gb);
2568 for (
int n = nb_samples >> 1; n > 0; n--) {
2569 int v = bytestream2_get_byteu(&gb);
2576 int samples_per_block;
2580 samples_per_block = avctx->extradata[0] / 16;
2581 blocks = nb_samples / avctx->extradata[0];
2583 samples_per_block = nb_samples / 16;
2587 for (
int m = 0; m < blocks; m++) {
2589 int prev1 =
c->status[
channel].sample1;
2590 int prev2 =
c->status[
channel].sample2;
2592 samples = samples_p[
channel] + m * 16;
2594 for (
int i = 0;
i < samples_per_block;
i++) {
2595 int byte = bytestream2_get_byteu(&gb);
2596 int scale = 1 << (
byte >> 4);
2597 int index =
byte & 0xf;
2602 for (
int n = 0; n < 16; n++) {
2608 byte = bytestream2_get_byteu(&gb);
2612 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2620 c->status[
channel].sample1 = prev1;
2621 c->status[
channel].sample2 = prev2;
2626#
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2632#define THP_GET16(g) \
2634 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2635 bytestream2_get_le16u(&(g)) : \
2636 bytestream2_get_be16u(&(g)), 16)
2647 for (
int n = 0; n < 16; n++)
2648 table[
i][n] = THP_GET16(tb);
2651 for (
int n = 0; n < 16; n++)
2652 table[
i][n] = THP_GET16(gb);
2654 if (!
c->has_status) {
2657 c->status[
i].sample1 = THP_GET16(gb);
2658 c->status[
i].sample2 = THP_GET16(gb);
2666 for (
int ch = 0; ch <
channels; ch++) {
2667 samples = samples_p[ch];
2670 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2671 int byte = bytestream2_get_byteu(&gb);
2672 int index = (
byte >> 4) & 7;
2673 unsigned int exp =
byte & 0x0F;
2678 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2684 byte = bytestream2_get_byteu(&gb);
2688 sampledat = ((
c->status[ch].sample1 * factor1
2689 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2691 c->status[ch].sample2 =
c->status[ch].sample1;
2692 c->status[ch].sample1 = *samples++;
2704 for (
int i = 0;
i < nb_samples / 28;
i++) {
2708 header = bytestream2_get_byteu(&gb);
2712 for (
int n = 0; n < 28; n++) {
2717 prev = (
c->status[
channel].sample1 * 0x3c);
2720 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2723 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2731 byte = bytestream2_get_byteu(&gb);
2737 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2740 c->status[
channel].sample1 = sampledat;
2749 int coefs[8*2*8] = { 0 };
2752 int version, order, entries;
2755 bytestream2_init(&cb, avctx->extradata, avctx->extradata_size);
2757 version = bytestream2_get_be16(&cb);
2758 order = bytestream2_get_be16(&cb);
2759 entries = bytestream2_get_be16(&cb);
2760 if (version != 1 || order != 2 || entries > 8)
2761 return AVERROR_INVALIDDATA;
2763 for (int n = 0; n < order * entries * 8; n++)
2764 coefs[n] = sign_extend(bytestream2_get_be16(&cb), 16);
2769 int16_t hist[8] = { 0 };
2770 const int order = 2;
2776 samples = samples_p[0] +
block * 16;
2778 scale = (buf[0] >> 4) & 0xF;
2779 index = (buf[0] >> 0) & 0xF;
2783 for (
int i = 0, j = 0;
i < 16;
i += 2, j++) {
2784 int n0 = (buf[j+1] >> 4) & 0xF;
2785 int n1 = (buf[j+1] >> 0) & 0xF;
2796 for (
int j = 0; j < 2; j++) {
2797 int *sf_codes = &codes[j*8];
2798 int16_t *sf_out = &
out[j*8];
2800 for (
int i = 0;
i < 8;
i++) {
2804 for (
int o = 0; o < order; o++)
2805 delta += coefs[o*8 +
i] * hist[(8 - order) + o];
2807 for (
int k =
i-1; k > -1; k--) {
2808 for (
int o = 1; o < order; o++)
2809 delta += sf_codes[(
i-1) - k] * (unsigned)coefs[(o*8) + k];
2818 for (
int i = 8 - order;
i < 8;
i++)
2819 hist[
i] = sf_out[
i];
2822 memcpy(samples,
out,
sizeof(
out));
2835 samples = samples_p[
channel] +
block * nb_samples_per_block;
2839 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2842 filter = bytestream2_get_byteu(&gb);
2847 flag = bytestream2_get_byteu(&gb) & 0x7;
2850 for (
int n = 0; n < 28; n++) {
2856 byte = bytestream2_get_byteu(&gb);
2878 samples = samples_p[
channel] +
block * nb_samples_per_block;
2881 filter = bytestream2_get_byteu(&gb);
2887 for (
int n = 0; n < nb_samples_per_block; n++) {
2893 byte = bytestream2_get_byteu(&gb);
2911 case 3: expand = adpcm_sanyo_expand3; break;
2912 case 4: expand = adpcm_sanyo_expand4; break;
2913 case 5: expand = adpcm_sanyo_expand5; break;
2917 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2918 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2922 for (
int i = 0;
i < nb_samples;
i++)
2923 for (
int ch = 0; ch <
channels; ch++)
2929 CASE(ADPCM_RHETOREX,
2930 for (
int i = 0;
i < nb_samples / 2;
i++) {
2931 uint8_t
byte = bytestream2_get_byteu(&gb);
2962 control = bytestream2_get_byteu(&gb);
2963 shift = (control >> 4) + 2;
2965 for (
int n = 0; n < 16; n++) {
2966 int sample = bytestream2_get_byteu(&gb);
2974 for (
int n = 0; n < nb_samples; n++) {
2975 for (
int ch = 0; ch <
channels; ch++) {
2976 int v = bytestream2_get_byteu(&gb);
2977 *samples++ = adpcm_circus_expand_nibble(&
c->status[ch], v);
2982 for (
int n = 0; n < nb_samples *
channels; n++) {
2983 int v = bytestream2_get_byteu(&gb);
2988 for (
int n = nb_samples / 2; n > 0; n--) {
2990 int v = bytestream2_get_byteu(&gb);
2997 CASE(ADPCM_IMA_CITRIX,
2999 for (int ch = 0; ch < channels; ch++) {
3000 *samples++ = c->status[ch].predictor = sign_extend(bytestream2_get_le16(&gb), 16);
3001 c->status[ch].step_index = bytestream2_get_byte(&gb);
3002 if (c->status[ch].step_index > 88)
3003 return AVERROR_INVALIDDATA;
3004 bytestream2_skip(&gb, 1);
3008 uint8_t
bits = bytestream2_get_byteu(&gb);
3009 samples[0] = adpcm_citrix_expand(&
c->status[0],
bits & 3);
3010 samples[1] = adpcm_citrix_expand(&
c->status[0], (
bits >> 2) & 3);
3011 samples[2] = adpcm_citrix_expand(&
c->status[0], (
bits >> 4) & 3);
3012 samples[3] = adpcm_citrix_expand(&
c->status[0], (
bits >> 6) & 3);
3017 for (
int ch = 0; ch <
channels; ch++) {
3018 uint32_t
bits = bytestream2_get_le32(&gb);
3019 for (
int j = 0; j < 16; j++)
3020 samples[j*
channels + ch] = adpcm_citrix_expand(&
c->status[ch], (
bits >> (2*j)) & 3);
3028 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");