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,
1498 int *got_frame_ptr,
AVPacket *avpkt)
1500 const uint8_t *buf = avpkt->
data;
1501 int buf_size = avpkt->
size;
1505 int16_t **samples_p;
1507 int nb_samples, coded_samples, approx_nb_samples, ret;
1511 nb_samples =
get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1512 if (nb_samples <= 0) {
1518 frame->nb_samples = nb_samples;
1521 samples = (int16_t *)
frame->data[0];
1522 samples_p = (int16_t **)
frame->extended_data;
1526 if (coded_samples) {
1527 if (!approx_nb_samples && coded_samples != nb_samples)
1529 frame->nb_samples = nb_samples = coded_samples;
1569 for (
int m = 0; m < 64; m += 2) {
1570 int byte = bytestream2_get_byteu(&gb);
1591 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1592 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1593 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1596 for (
int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1599 samples = &samples_p[
i][1 + n * samples_per_block];
1600 for (
int j = 0; j < block_size; j++) {
1602 (j % 4) + (j / 4) * (
channels * 4) +
i * 4];
1607 for (
int m = 0; m < samples_per_block; m++) {
1615 for (
int n = 0; n < (nb_samples - 1) / 8; n++) {
1618 samples = &samples_p[
i][1 + n * 8];
1619 for (
int m = 0; m < 8; m += 2) {
1620 int v = bytestream2_get_byteu(&gb);
1628 CASE(ADPCM_IMA_XBOX,
1641 for (
int n = 0; n < (nb_samples-1) / 8; n++) {
1644 samples = &samples_p[
i][1 + n * 8];
1645 for (
int m = 0; m < 8; m += 2) {
1646 int v = bytestream2_get_byteu(&gb);
1652 frame->nb_samples--;
1656 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1659 c->status[
i].step_index =
sign_extend(bytestream2_get_le16u(&gb), 16);
1660 if (
c->status[
i].step_index > 88u) {
1662 i,
c->status[
i].step_index);
1669 samples = (int16_t *)
frame->data[
i];
1670 for (
int n = nb_samples >> 1; n > 0; n--) {
1671 int v = bytestream2_get_byteu(&gb);
1679 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1681 c->status[
i].step =
sign_extend(bytestream2_get_le16u(&gb), 16);
1683 for (
int n = 0; n < nb_samples >> (1 - st); n++) {
1684 int v = bytestream2_get_byteu(&gb);
1690 int block_predictor;
1695 block_predictor = bytestream2_get_byteu(&gb);
1696 if (block_predictor > 6) {
1706 *samples++ =
c->status[
channel].sample2;
1707 *samples++ =
c->status[
channel].sample1;
1708 for (
int n = (nb_samples - 2) >> 1; n > 0; n--) {
1709 int byte = bytestream2_get_byteu(&gb);
1715 block_predictor = bytestream2_get_byteu(&gb);
1716 if (block_predictor > 6) {
1724 block_predictor = bytestream2_get_byteu(&gb);
1725 if (block_predictor > 6) {
1733 c->status[0].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1735 c->status[1].idelta =
sign_extend(bytestream2_get_le16u(&gb), 16);
1738 c->status[0].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1739 if (st)
c->status[1].sample1 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1740 c->status[0].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1741 if (st)
c->status[1].sample2 =
sign_extend(bytestream2_get_le16u(&gb), 16);
1743 *samples++ =
c->status[0].sample2;
1744 if (st) *samples++ =
c->status[1].sample2;
1745 *samples++ =
c->status[0].sample1;
1746 if (st) *samples++ =
c->status[1].sample1;
1747 for (
int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1748 int byte = bytestream2_get_byteu(&gb);
1757 c->status[
channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1758 c->status[
channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1763 for (
int n = 0; n < nb_samples; n += 2) {
1764 int v = bytestream2_get_byteu(&gb);
1768 for (
int n = 0; n < nb_samples; n += 2) {
1769 int v = bytestream2_get_byteu(&gb);
1786 for (
int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1787 int v = bytestream2_get_byteu(&gb);
1795 if (decode_top_nibble_next) { \
1796 nibble = last_byte >> 4; \
1797 decode_top_nibble_next = 0; \
1799 last_byte = bytestream2_get_byteu(&gb); \
1800 nibble = last_byte & 0x0F; \
1801 decode_top_nibble_next = 1; \
1806 int decode_top_nibble_next = 0;
1808 const int16_t *samples_end = samples +
channels * nb_samples;
1811 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1812 c->status[1].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
1813 c->status[0].step_index = bytestream2_get_byteu(&gb);
1814 c->status[1].step_index = bytestream2_get_byteu(&gb);
1815 if (
c->status[0].step_index > 88u ||
c->status[1].step_index > 88u){
1817 c->status[0].step_index,
c->status[1].step_index);
1821 diff_channel =
c->status[1].predictor;
1823 while (samples < samples_end) {
1837 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1838 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1839 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1846 diff_channel = (diff_channel +
c->status[1].predictor) / 2;
1847 *samples++ =
c->status[0].predictor +
c->status[1].predictor;
1848 *samples++ =
c->status[0].predictor -
c->status[1].predictor;
1854 CASE(ADPCM_IMA_MAGIX,
1866 for (
int m = 0; m <
channels*nb_samples/16; m ++) {
1867 uint32_t v0 = bytestream2_get_le32u(&gb);
1868 uint32_t v1 = bytestream2_get_le32u(&gb);
1870 for (
int n = 8; n > 0; n--, v0 >>= 4, v1 >>= 4, samples += 2) {
1888 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1890 int v = bytestream2_get_byteu(&gb);
1903 CASE(ADPCM_IMA_MOFLEX,
1915 for (
int subframe = 0; subframe < nb_samples / 256; subframe++) {
1917 samples = samples_p[
channel] + 256 * subframe;
1918 for (
int n = 0; n < 256; n += 2) {
1919 int v = bytestream2_get_byteu(&gb);
1926 CASE(ADPCM_IMA_DAT4,
1931 for (
int n = 0; n < nb_samples; n += 2) {
1932 int v = bytestream2_get_byteu(&gb);
1939 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1940 int v = bytestream2_get_byteu(&gb);
1945 CASE(ADPCM_IMA_HVQM2,
1946 int format = bytestream2_get_be16(&gb);
1951 CASE(ADPCM_IMA_HVQM4,
1952 int format = bytestream2_get_be16(&gb);
1958 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1959 int v = bytestream2_get_byteu(&gb);
1965 for (
int n = nb_samples / 2; n > 0; n--) {
1967 int v = bytestream2_get_byteu(&gb);
1975 for (
int n = nb_samples / 2; n > 0; n--) {
1977 int v = bytestream2_get_byteu(&gb);
1984 CASE(ADPCM_IMA_CUNNING,
1986 int16_t *smp = samples_p[
channel];
1987 for (
int n = 0; n < nb_samples / 2; n++) {
1988 int v = bytestream2_get_byteu(&gb);
1995 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
1996 int v = bytestream2_get_byteu(&gb);
2012 for (
int n = 0; n < nb_samples / 2; n++) {
2015 byte[0] = bytestream2_get_byteu(&gb);
2017 byte[1] = bytestream2_get_byteu(&gb);
2027 if (
c->vqa_version == 3) {
2028 for (int channel = 0; channel < channels; channel++) {
2029 int16_t *smp = samples_p[channel];
2031 for (int n = nb_samples / 2; n > 0; n--) {
2032 int v = bytestream2_get_byteu(&gb);
2033 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
2034 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
2038 for (
int n = nb_samples / 2; n > 0; n--) {
2040 int v = bytestream2_get_byteu(&gb);
2050 int bytes_remaining,
block = 0;
2057 history[1] =
sign_extend(bytestream2_get_le16(&gb), 16);
2058 history[0] =
sign_extend(bytestream2_get_le16(&gb), 16);
2059 scale = bytestream2_get_le16(&gb);
2061 out[0] = history[1];
2062 out[1] = history[0];
2064 for (
int n = 0; n < 15; n++) {
2065 unsigned byte = bytestream2_get_byte(&gb);
2071 out[2+n*2] = nibble[0]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2072 history[1] = history[0];
2073 history[0] =
out[2+n*2];
2075 out[2+n*2+1] = nibble[1]*
scale + ((history[0]*3667 - history[1]*1642) >> 11);
2076 history[1] = history[0];
2077 history[0] =
out[2+n*2+1];
2084 if (bytes_remaining > 0) {
2089 int16_t *out0 = samples_p[0];
2090 int16_t *out1 = samples_p[1];
2091 int samples_per_block = 28 * (3 -
channels) * 4;
2092 int sample_offset = 0;
2093 int bytes_remaining;
2096 &
c->status[0], &
c->status[1],
2100 sample_offset += samples_per_block;
2105 if (bytes_remaining > 0) {
2109 CASE(ADPCM_IMA_ESCAPE,
2110 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2111 int byte = bytestream2_get_byteu(&gb);
2116 CASE(ADPCM_IMA_EA_EACS,
2117 for (
int i = 0;
i <= st;
i++) {
2118 c->status[
i].step_index = bytestream2_get_le32u(&gb);
2119 if (
c->status[
i].step_index > 88u) {
2121 i,
c->status[
i].step_index);
2125 for (
int i = 0;
i <= st;
i++) {
2126 c->status[
i].predictor = bytestream2_get_le32u(&gb);
2131 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2132 int byte = bytestream2_get_byteu(&gb);
2137 CASE(ADPCM_IMA_EA_SEAD,
2138 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2139 int byte = bytestream2_get_byteu(&gb);
2145 int previous_left_sample, previous_right_sample;
2146 int current_left_sample, current_right_sample;
2147 int next_left_sample, next_right_sample;
2148 int coeff1l, coeff2l, coeff1r, coeff2r;
2149 int shift_left, shift_right;
2157 current_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2158 previous_left_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2159 current_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2160 previous_right_sample =
sign_extend(bytestream2_get_le16u(&gb), 16);
2162 for (
int count1 = 0; count1 < nb_samples / 28; count1++) {
2163 int byte = bytestream2_get_byteu(&gb);
2170 byte = bytestream2_get_byteu(&gb);
2171 shift_left = 20 - (
byte >> 4);
2172 shift_right = 20 - (
byte & 0x0F);
2175 shift_left = 20 - (
byte & 0x0F);
2178 for (
int count2 = 0; count2 < (
channels == 2 ? 28 : 14); count2++) {
2179 byte = bytestream2_get_byteu(&gb);
2180 next_left_sample =
sign_extend(
byte >> 4, 4) * (1 << shift_left);
2182 next_left_sample = (next_left_sample +
2183 (current_left_sample * coeff1l) +
2184 (previous_left_sample * coeff2l) + 0x80) >> 8;
2186 previous_left_sample = current_left_sample;
2188 *samples++ = current_left_sample;
2191 next_right_sample =
sign_extend(
byte, 4) * (1 << shift_right);
2193 next_right_sample = (next_right_sample +
2194 (current_right_sample * coeff1r) +
2195 (previous_right_sample * coeff2r) + 0x80) >> 8;
2197 previous_right_sample = current_right_sample;
2199 *samples++ = current_right_sample;
2201 next_left_sample =
sign_extend(
byte, 4) * (1 << shift_left);
2203 next_left_sample = (next_left_sample +
2204 (current_left_sample * coeff1l) +
2205 (previous_left_sample * coeff2l) + 0x80) >> 8;
2207 previous_left_sample = current_left_sample;
2210 *samples++ = current_left_sample;
2216 CASE(ADPCM_EA_MAXIS_XA,
2220 int byte = bytestream2_get_byteu(&gb);
2221 for (
int i = 0;
i < 2;
i++)
2225 for (
int count1 = 0; count1 < nb_samples / 2; count1++) {
2228 byte[0] = bytestream2_get_byteu(&gb);
2229 if (st)
byte[1] = bytestream2_get_byteu(&gb);
2230 for (
int i = 4;
i >= 0;
i-=4) {
2238 *samples++ =
c->status[
channel].sample1;
2244#
if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
2253 int previous_sample, current_sample, next_sample;
2262 bytestream2_get_le32(&gb)) +
2269 samplesC = samples_p[
channel];
2272 current_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2273 previous_sample =
sign_extend(bytestream2_get_le16(&gb), 16);
2275 current_sample =
c->status[
channel].predictor;
2276 previous_sample =
c->status[
channel].prev_sample;
2279 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2280 int byte = bytestream2_get_byte(&gb);
2282 current_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2283 previous_sample =
sign_extend(bytestream2_get_be16(&gb), 16);
2285 for (
int count2 = 0; count2 < 28; count2++)
2286 *samplesC++ =
sign_extend(bytestream2_get_be16(&gb), 16);
2290 shift = 20 - (
byte & 0x0F);
2292 for (
int count2 = 0; count2 < 28; count2++) {
2296 byte = bytestream2_get_byte(&gb);
2300 next_sample += (current_sample * coeff1) +
2301 (previous_sample * coeff2);
2304 previous_sample = current_sample;
2305 current_sample = next_sample;
2306 *samplesC++ = current_sample;
2312 }
else if (count != count1) {
2314 count =
FFMAX(count, count1);
2318 c->status[
channel].predictor = current_sample;
2319 c->status[
channel].prev_sample = previous_sample;
2323 frame->nb_samples = count * 28;
2332 for (
int n = 0; n < 4; n++,
s += 32) {
2334 for (
int i = 0;
i < 2;
i++)
2343 for (
int m = 2; m < 32; m += 2) {
2345 for (
int n = 0; n < 4; n++,
s += 32) {
2347 int byte = bytestream2_get_byteu(&gb);
2360 CASE(ADPCM_IMA_ACORN,
2364 cs->
step_index = bytestream2_get_le16u(&gb) & 0xFF;
2371 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2372 int byte = bytestream2_get_byteu(&gb);
2390 c->status[0].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2391 c->status[0].step_index = bytestream2_get_byteu(&gb);
2393 if (
c->status[0].step_index > 88u) {
2395 c->status[0].step_index);
2399 for (
int n = nb_samples >> 1; n > 0; n--) {
2400 int v = bytestream2_get_byteu(&gb);
2406 if (nb_samples & 1) {
2407 int v = bytestream2_get_byteu(&gb);
2419 c->status[
i].predictor =
sign_extend(bytestream2_get_le16u(&gb), 16);
2420 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2422 if (
c->status[
i].step_index > 88u) {
2424 c->status[
i].step_index);
2429 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2430 int v = bytestream2_get_byteu(&gb);
2436 CASE(ADPCM_IMA_SMJPEG,
2438 c->status[
i].predictor =
sign_extend(bytestream2_get_be16u(&gb), 16);
2439 c->status[
i].step_index = bytestream2_get_byteu(&gb);
2441 if (
c->status[
i].step_index > 88u) {
2443 c->status[
i].step_index);
2448 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2449 int v = bytestream2_get_byteu(&gb);
2456 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2457 int v = bytestream2_get_byteu(&gb);
2462#
if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2463 CONFIG_ADPCM_SBPRO_4_DECODER
2467 if (!
c->status[0].step_index) {
2469 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2471 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2472 c->status[0].step_index = 1;
2476 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2477 int byte = bytestream2_get_byteu(&gb);
2478 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2480 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2484 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2485 int byte = bytestream2_get_byteu(&gb);
2486 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2488 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2489 (byte >> 2) & 0x07, 3, 0);
2490 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2494 for (
int n = nb_samples >> (2 - st); n > 0; n--) {
2495 int byte = bytestream2_get_byteu(&gb);
2499 (
byte >> 4) & 0x03, 2, 2);
2501 (
byte >> 2) & 0x03, 2, 2);
2513 for (
int n = nb_samples >> (1 - st); n > 0; n--) {
2514 int v = bytestream2_get_byteu(&gb);
2522 for (
int n = nb_samples >> 1; n > 0; n--) {
2523 int v = bytestream2_get_byteu(&gb);
2530 int samples_per_block;
2533 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
2534 samples_per_block = avctx->extradata[0] / 16;
2535 blocks = nb_samples / avctx->extradata[0];
2537 samples_per_block = nb_samples / 16;
2541 for (
int m = 0; m < blocks; m++) {
2543 int prev1 =
c->status[
channel].sample1;
2544 int prev2 =
c->status[
channel].sample2;
2546 samples = samples_p[
channel] + m * 16;
2548 for (
int i = 0;
i < samples_per_block;
i++) {
2549 int byte = bytestream2_get_byteu(&gb);
2550 int scale = 1 << (
byte >> 4);
2551 int index =
byte & 0xf;
2556 for (
int n = 0; n < 16; n++) {
2562 byte = bytestream2_get_byteu(&gb);
2566 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2574 c->status[
channel].sample1 = prev1;
2575 c->status[
channel].sample2 = prev2;
2580#
if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2586#define THP_GET16(g) \
2588 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2589 bytestream2_get_le16u(&(g)) : \
2590 bytestream2_get_be16u(&(g)), 16)
2592 if (avctx->extradata) {
2594 if (avctx->extradata_size < 32 *
channels) {
2601 for (
int n = 0; n < 16; n++)
2602 table[
i][n] = THP_GET16(tb);
2605 for (
int n = 0; n < 16; n++)
2606 table[
i][n] = THP_GET16(gb);
2608 if (!
c->has_status) {
2611 c->status[
i].sample1 = THP_GET16(gb);
2612 c->status[
i].sample2 = THP_GET16(gb);
2620 for (
int ch = 0; ch <
channels; ch++) {
2621 samples = samples_p[ch];
2624 for (
int i = 0;
i < (nb_samples + 13) / 14;
i++) {
2625 int byte = bytestream2_get_byteu(&gb);
2626 int index = (
byte >> 4) & 7;
2627 unsigned int exp =
byte & 0x0F;
2632 for (
int n = 0; n < 14 && (
i * 14 + n < nb_samples); n++) {
2638 byte = bytestream2_get_byteu(&gb);
2642 sampledat = ((
c->status[ch].sample1 * factor1
2643 +
c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 <<
exp);
2645 c->status[ch].sample2 =
c->status[ch].sample1;
2646 c->status[ch].sample1 = *samples++;
2658 for (
int i = 0;
i < nb_samples / 28;
i++) {
2662 header = bytestream2_get_byteu(&gb);
2666 for (
int n = 0; n < 28; n++) {
2671 prev = (
c->status[
channel].sample1 * 0x3c);
2674 prev = (
c->status[
channel].sample1 * 0x73) - (
c->status[
channel].sample2 * 0x34);
2677 prev = (
c->status[
channel].sample1 * 0x62) - (
c->status[
channel].sample2 * 0x37);
2685 byte = bytestream2_get_byteu(&gb);
2691 sampledat = ((sampledat * (1 << 12)) >> (
header & 0xf)) * (1 << 6) + prev;
2694 c->status[
channel].sample1 = sampledat;
2703 int coefs[8*2*8] = { 0 };
2705 if (avctx->extradata) {
2706 int version, order, entries;
2709 bytestream2_init(&cb, avctx->extradata, avctx->extradata_size);
2711 version = bytestream2_get_be16(&cb);
2712 order = bytestream2_get_be16(&cb);
2713 entries = bytestream2_get_be16(&cb);
2714 if (version != 1 || order != 2 || entries > 8)
2715 return AVERROR_INVALIDDATA;
2717 for (int n = 0; n < order * entries * 8; n++)
2718 coefs[n] = sign_extend(bytestream2_get_be16(&cb), 16);
2723 int16_t hist[8] = { 0 };
2724 const int order = 2;
2730 samples = samples_p[0] +
block * 16;
2732 scale = (buf[0] >> 4) & 0xF;
2733 index = (buf[0] >> 0) & 0xF;
2737 for (
int i = 0, j = 0;
i < 16;
i += 2, j++) {
2738 int n0 = (buf[j+1] >> 4) & 0xF;
2739 int n1 = (buf[j+1] >> 0) & 0xF;
2750 for (
int j = 0; j < 2; j++) {
2751 int *sf_codes = &codes[j*8];
2752 int16_t *sf_out = &
out[j*8];
2754 for (
int i = 0;
i < 8;
i++) {
2758 for (
int o = 0; o < order; o++)
2759 delta += coefs[o*8 +
i] * hist[(8 - order) + o];
2761 for (
int k =
i-1; k > -1; k--) {
2762 for (
int o = 1; o < order; o++)
2763 delta += sf_codes[(
i-1) - k] * (unsigned)coefs[(o*8) + k];
2772 for (
int i = 8 - order;
i < 8;
i++)
2773 hist[
i] = sf_out[
i];
2776 memcpy(samples,
out,
sizeof(
out));
2789 samples = samples_p[
channel] +
block * nb_samples_per_block;
2793 for (
int i = 0;
i < nb_samples_per_block / 28;
i++) {
2796 filter = bytestream2_get_byteu(&gb);
2801 flag = bytestream2_get_byteu(&gb) & 0x7;
2804 for (
int n = 0; n < 28; n++) {
2810 byte = bytestream2_get_byteu(&gb);
2827 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2828 int nb_samples_per_block = ((avctx->block_align - 1) /
channels) * 2;
2832 samples = samples_p[
channel] +
block * nb_samples_per_block;
2835 filter = bytestream2_get_byteu(&gb);
2841 for (
int n = 0; n < nb_samples_per_block; n++) {
2847 byte = bytestream2_get_byteu(&gb);
2864 switch(avctx->bits_per_coded_sample) {
2865 case 3: expand = adpcm_sanyo_expand3; break;
2866 case 4: expand = adpcm_sanyo_expand4; break;
2867 case 5: expand = adpcm_sanyo_expand5; break;
2871 c->status[ch].predictor =
sign_extend(bytestream2_get_le16(&gb), 16);
2872 c->status[ch].step =
sign_extend(bytestream2_get_le16(&gb), 16);
2876 for (
int i = 0;
i < nb_samples;
i++)
2877 for (
int ch = 0; ch <
channels; ch++)
2883 CASE(ADPCM_RHETOREX,
2884 for (
int i = 0;
i < nb_samples / 2;
i++) {
2885 uint8_t
byte = bytestream2_get_byteu(&gb);
2908 for (
int block = 0;
block < avpkt->size / avctx->block_align;
block++) {
2916 control = bytestream2_get_byteu(&gb);
2917 shift = (control >> 4) + 2;
2919 for (
int n = 0; n < 16; n++) {
2920 int sample = bytestream2_get_byteu(&gb);
2928 for (
int n = 0; n < nb_samples; n++) {
2929 for (
int ch = 0; ch <
channels; ch++) {
2930 int v = bytestream2_get_byteu(&gb);
2936 for (
int n = 0; n < nb_samples *
channels; n++) {
2937 int v = bytestream2_get_byteu(&gb);
2942 for (
int n = nb_samples / 2; n > 0; n--) {
2944 int v = bytestream2_get_byteu(&gb);
2952 av_unreachable(
"There are cases for all codec ids using adpcm_decode_frame");