FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/adpcm.c
Date: 2025-07-28 20:30:09
Exec Total Coverage
Lines: 557 878 63.4%
Functions: 16 24 66.7%
Branches: 454 775 58.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2001-2003 The FFmpeg project
3 *
4 * first version by Francois Revol (revol@free.fr)
5 * fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
6 * by Mike Melanson (melanson@pcisys.net)
7 * CD-ROM XA ADPCM codec by BERO
8 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
9 * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
10 * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
11 * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
12 * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
13 * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
14 * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
15 * Argonaut Games ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
16 * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
17 * Ubisoft ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
18 * High Voltage Software ALP decoder by Zane van Iperen (zane@zanevaniperen.com)
19 * Cunning Developments decoder by Zane van Iperen (zane@zanevaniperen.com)
20 * Sanyo LD-ADPCM decoder by Peter Ross (pross@xvid.org)
21 *
22 * This file is part of FFmpeg.
23 *
24 * FFmpeg is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU Lesser General Public
26 * License as published by the Free Software Foundation; either
27 * version 2.1 of the License, or (at your option) any later version.
28 *
29 * FFmpeg is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public
35 * License along with FFmpeg; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 */
38
39 #include "config_components.h"
40
41 #include "avcodec.h"
42 #include "get_bits.h"
43 #include "bytestream.h"
44 #include "adpcm.h"
45 #include "adpcm_data.h"
46 #include "codec_internal.h"
47 #include "decode.h"
48
49 /**
50 * @file
51 * ADPCM decoders
52 * Features and limitations:
53 *
54 * Reference documents:
55 * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
56 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
57 * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
58 * http://openquicktime.sourceforge.net/
59 * XAnim sources (xa_codec.c) http://xanim.polter.net/
60 * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
61 * SoX source code http://sox.sourceforge.net/
62 *
63 * CD-ROM XA:
64 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
65 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
66 * readstr http://www.geocities.co.jp/Playtown/2004/
67 */
68
69 #define CASE_0(codec_id, ...)
70 #define CASE_1(codec_id, ...) \
71 case codec_id: \
72 { __VA_ARGS__ } \
73 break;
74 #define CASE_2(enabled, codec_id, ...) \
75 CASE_ ## enabled(codec_id, __VA_ARGS__)
76 #define CASE_3(config, codec_id, ...) \
77 CASE_2(config, codec_id, __VA_ARGS__)
78 #define CASE(codec, ...) \
79 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
80
81 /* These are for CD-ROM XA ADPCM */
82 static const int8_t xa_adpcm_table[5][2] = {
83 { 0, 0 },
84 { 60, 0 },
85 { 115, -52 },
86 { 98, -55 },
87 { 122, -60 }
88 };
89
90 static const int16_t afc_coeffs[2][16] = {
91 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
92 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
93 };
94
95 static const int16_t ea_adpcm_table[] = {
96 0, 240, 460, 392,
97 0, 0, -208, -220,
98 0, 1, 3, 4,
99 7, 8, 10, 11,
100 0, -1, -3, -4
101 };
102
103 /*
104 * Dumped from the binaries:
105 * - FantasticJourney.exe - 0x794D2, DGROUP:0x47A4D2
106 * - BigRaceUSA.exe - 0x9B8AA, DGROUP:0x49C4AA
107 * - Timeshock!.exe - 0x8506A, DGROUP:0x485C6A
108 */
109 static const int8_t ima_cunning_index_table[9] = {
110 -1, -1, -1, -1, 1, 2, 3, 4, -1
111 };
112
113 /*
114 * Dumped from the binaries:
115 * - FantasticJourney.exe - 0x79458, DGROUP:0x47A458
116 * - BigRaceUSA.exe - 0x9B830, DGROUP:0x49C430
117 * - Timeshock!.exe - 0x84FF0, DGROUP:0x485BF0
118 */
119 static const int16_t ima_cunning_step_table[61] = {
120 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
121 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
122 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
123 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
124 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
125 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
126 };
127
128 static const int8_t adpcm_index_table2[4] = {
129 -1, 2,
130 -1, 2,
131 };
132
133 static const int8_t adpcm_index_table3[8] = {
134 -1, -1, 1, 2,
135 -1, -1, 1, 2,
136 };
137
138 static const int8_t adpcm_index_table5[32] = {
139 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
140 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
141 };
142
143 static const int8_t * const adpcm_index_tables[4] = {
144 &adpcm_index_table2[0],
145 &adpcm_index_table3[0],
146 &ff_adpcm_index_table[0],
147 &adpcm_index_table5[0],
148 };
149
150 static const int16_t mtaf_stepsize[32][16] = {
151 { 1, 5, 9, 13, 16, 20, 24, 28,
152 -1, -5, -9, -13, -16, -20, -24, -28, },
153 { 2, 6, 11, 15, 20, 24, 29, 33,
154 -2, -6, -11, -15, -20, -24, -29, -33, },
155 { 2, 7, 13, 18, 23, 28, 34, 39,
156 -2, -7, -13, -18, -23, -28, -34, -39, },
157 { 3, 9, 15, 21, 28, 34, 40, 46,
158 -3, -9, -15, -21, -28, -34, -40, -46, },
159 { 3, 11, 18, 26, 33, 41, 48, 56,
160 -3, -11, -18, -26, -33, -41, -48, -56, },
161 { 4, 13, 22, 31, 40, 49, 58, 67,
162 -4, -13, -22, -31, -40, -49, -58, -67, },
163 { 5, 16, 26, 37, 48, 59, 69, 80,
164 -5, -16, -26, -37, -48, -59, -69, -80, },
165 { 6, 19, 31, 44, 57, 70, 82, 95,
166 -6, -19, -31, -44, -57, -70, -82, -95, },
167 { 7, 22, 38, 53, 68, 83, 99, 114,
168 -7, -22, -38, -53, -68, -83, -99, -114, },
169 { 9, 27, 45, 63, 81, 99, 117, 135,
170 -9, -27, -45, -63, -81, -99, -117, -135, },
171 { 10, 32, 53, 75, 96, 118, 139, 161,
172 -10, -32, -53, -75, -96, -118, -139, -161, },
173 { 12, 38, 64, 90, 115, 141, 167, 193,
174 -12, -38, -64, -90, -115, -141, -167, -193, },
175 { 15, 45, 76, 106, 137, 167, 198, 228,
176 -15, -45, -76, -106, -137, -167, -198, -228, },
177 { 18, 54, 91, 127, 164, 200, 237, 273,
178 -18, -54, -91, -127, -164, -200, -237, -273, },
179 { 21, 65, 108, 152, 195, 239, 282, 326,
180 -21, -65, -108, -152, -195, -239, -282, -326, },
181 { 25, 77, 129, 181, 232, 284, 336, 388,
182 -25, -77, -129, -181, -232, -284, -336, -388, },
183 { 30, 92, 153, 215, 276, 338, 399, 461,
184 -30, -92, -153, -215, -276, -338, -399, -461, },
185 { 36, 109, 183, 256, 329, 402, 476, 549,
186 -36, -109, -183, -256, -329, -402, -476, -549, },
187 { 43, 130, 218, 305, 392, 479, 567, 654,
188 -43, -130, -218, -305, -392, -479, -567, -654, },
189 { 52, 156, 260, 364, 468, 572, 676, 780,
190 -52, -156, -260, -364, -468, -572, -676, -780, },
191 { 62, 186, 310, 434, 558, 682, 806, 930,
192 -62, -186, -310, -434, -558, -682, -806, -930, },
193 { 73, 221, 368, 516, 663, 811, 958, 1106,
194 -73, -221, -368, -516, -663, -811, -958, -1106, },
195 { 87, 263, 439, 615, 790, 966, 1142, 1318,
196 -87, -263, -439, -615, -790, -966, -1142, -1318, },
197 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
198 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
199 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
200 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
201 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
202 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
203 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
204 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
205 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
206 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
207 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
208 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
209 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
210 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
211 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
212 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
213 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
214 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
215 };
216
217 static const int16_t oki_step_table[49] = {
218 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
219 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
220 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
221 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
222 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
223 };
224
225 // padded to zero where table size is less then 16
226 static const int8_t swf_index_tables[4][16] = {
227 /*2*/ { -1, 2 },
228 /*3*/ { -1, -1, 2, 4 },
229 /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
230 /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
231 };
232
233 static const int8_t zork_index_table[8] = {
234 -1, -1, -1, 1, 4, 7, 10, 12,
235 };
236
237 static const int8_t mtf_index_table[16] = {
238 8, 6, 4, 2, -1, -1, -1, -1,
239 -1, -1, -1, -1, 2, 4, 6, 8,
240 };
241
242 /* end of tables */
243
244 typedef struct ADPCMDecodeContext {
245 ADPCMChannelStatus status[14];
246 int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
247 int has_status; /**< Status flag. Reset to 0 after a flush. */
248 } ADPCMDecodeContext;
249
250 static void adpcm_flush(AVCodecContext *avctx);
251
252 187 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
253 {
254 187 ADPCMDecodeContext *c = avctx->priv_data;
255 187 unsigned int min_channels = 1;
256 187 unsigned int max_channels = 2;
257
258 187 adpcm_flush(avctx);
259
260
5/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 151 times.
187 switch(avctx->codec->id) {
261 3 case AV_CODEC_ID_ADPCM_IMA_AMV:
262 3 max_channels = 1;
263 3 break;
264 case AV_CODEC_ID_ADPCM_SANYO:
265 max_channels = 2;
266 break;
267 23 case AV_CODEC_ID_ADPCM_AFC:
268 case AV_CODEC_ID_ADPCM_EA_R1:
269 case AV_CODEC_ID_ADPCM_EA_R2:
270 case AV_CODEC_ID_ADPCM_EA_R3:
271 case AV_CODEC_ID_ADPCM_EA_XAS:
272 case AV_CODEC_ID_ADPCM_MS:
273 23 max_channels = 6;
274 23 break;
275 case AV_CODEC_ID_ADPCM_MTAF:
276 min_channels = 2;
277 max_channels = 8;
278 if (avctx->ch_layout.nb_channels & 1) {
279 avpriv_request_sample(avctx, "channel count %d", avctx->ch_layout.nb_channels);
280 return AVERROR_PATCHWELCOME;
281 }
282 break;
283 2 case AV_CODEC_ID_ADPCM_DTK:
284 2 min_channels = 2;
285 2 break;
286 case AV_CODEC_ID_ADPCM_PSX:
287 max_channels = 8;
288 if (avctx->ch_layout.nb_channels <= 0 ||
289 avctx->block_align % (16 * avctx->ch_layout.nb_channels))
290 return AVERROR_INVALIDDATA;
291 break;
292 8 case AV_CODEC_ID_ADPCM_IMA_DAT4:
293 case AV_CODEC_ID_ADPCM_THP:
294 case AV_CODEC_ID_ADPCM_THP_LE:
295 8 max_channels = 14;
296 8 break;
297 }
298
1/2
✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
187 if (avctx->ch_layout.nb_channels < min_channels ||
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 187 times.
187 avctx->ch_layout.nb_channels > max_channels) {
300 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
301 return AVERROR(EINVAL);
302 }
303
304
4/6
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 171 times.
187 switch(avctx->codec->id) {
305 9 case AV_CODEC_ID_ADPCM_IMA_WAV:
306
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
307 return AVERROR_INVALIDDATA;
308 9 break;
309 6 case AV_CODEC_ID_ADPCM_ARGO:
310
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (avctx->bits_per_coded_sample != 4 ||
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 avctx->block_align != 17 * avctx->ch_layout.nb_channels)
312 return AVERROR_INVALIDDATA;
313 6 break;
314 case AV_CODEC_ID_ADPCM_SANYO:
315 if (avctx->bits_per_coded_sample < 3 || avctx->bits_per_coded_sample > 5)
316 return AVERROR_INVALIDDATA;
317 break;
318 1 case AV_CODEC_ID_ADPCM_IMA_XBOX:
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (avctx->bits_per_coded_sample != 4)
320 return AVERROR_INVALIDDATA;
321 1 break;
322 case AV_CODEC_ID_ADPCM_ZORK:
323 if (avctx->bits_per_coded_sample != 8)
324 return AVERROR_INVALIDDATA;
325 break;
326 171 default:
327 171 break;
328 }
329
330
4/4
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 81 times.
187 switch (avctx->codec->id) {
331 87 case AV_CODEC_ID_ADPCM_AICA:
332 case AV_CODEC_ID_ADPCM_IMA_CUNNING:
333 case AV_CODEC_ID_ADPCM_IMA_DAT4:
334 case AV_CODEC_ID_ADPCM_IMA_QT:
335 case AV_CODEC_ID_ADPCM_IMA_WAV:
336 case AV_CODEC_ID_ADPCM_IMA_XBOX:
337 case AV_CODEC_ID_ADPCM_4XM:
338 case AV_CODEC_ID_ADPCM_XA:
339 case AV_CODEC_ID_ADPCM_XMD:
340 case AV_CODEC_ID_ADPCM_EA_R1:
341 case AV_CODEC_ID_ADPCM_EA_R2:
342 case AV_CODEC_ID_ADPCM_EA_R3:
343 case AV_CODEC_ID_ADPCM_EA_XAS:
344 case AV_CODEC_ID_ADPCM_THP:
345 case AV_CODEC_ID_ADPCM_THP_LE:
346 case AV_CODEC_ID_ADPCM_AFC:
347 case AV_CODEC_ID_ADPCM_DTK:
348 case AV_CODEC_ID_ADPCM_PSX:
349 case AV_CODEC_ID_ADPCM_SANYO:
350 case AV_CODEC_ID_ADPCM_MTAF:
351 case AV_CODEC_ID_ADPCM_ARGO:
352 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
353 87 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
354 87 break;
355 8 case AV_CODEC_ID_ADPCM_IMA_WS:
356
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
357 AV_SAMPLE_FMT_S16;
358 8 break;
359 11 case AV_CODEC_ID_ADPCM_MS:
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 avctx->sample_fmt = avctx->ch_layout.nb_channels > 2 ? AV_SAMPLE_FMT_S16P :
361 AV_SAMPLE_FMT_S16;
362 11 break;
363 81 default:
364 81 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
365 }
366 187 return 0;
367 }
368
369 static inline int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
370 {
371 int delta, pred, step, add;
372
373 pred = c->predictor;
374 delta = nibble & 7;
375 step = c->step;
376 add = (delta * 2 + 1) * step;
377 if (add < 0)
378 add = add + 7;
379
380 if ((nibble & 8) == 0)
381 pred = av_clip(pred + (add >> 3), -32767, 32767);
382 else
383 pred = av_clip(pred - (add >> 3), -32767, 32767);
384
385 switch (delta) {
386 case 7:
387 step *= 0x99;
388 break;
389 case 6:
390 c->step = av_clip(c->step * 2, 127, 24576);
391 c->predictor = pred;
392 return pred;
393 case 5:
394 step *= 0x66;
395 break;
396 case 4:
397 step *= 0x4d;
398 break;
399 default:
400 step *= 0x39;
401 break;
402 }
403
404 if (step < 0)
405 step += 0x3f;
406
407 c->step = step >> 6;
408 c->step = av_clip(c->step, 127, 24576);
409 c->predictor = pred;
410 return pred;
411 }
412
413 10327321 static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
414 {
415 int step_index;
416 int predictor;
417 int sign, delta, diff, step;
418
419 10327321 step = ff_adpcm_step_table[c->step_index];
420 10327321 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
421 10327321 step_index = av_clip(step_index, 0, 88);
422
423 10327321 sign = nibble & 8;
424 10327321 delta = nibble & 7;
425 /* perform direct multiplication instead of series of jumps proposed by
426 * the reference ADPCM implementation since modern CPUs can do the mults
427 * quickly enough */
428 10327321 diff = ((2 * delta + 1) * step) >> shift;
429 10327321 predictor = c->predictor;
430
2/2
✓ Branch 0 taken 5115828 times.
✓ Branch 1 taken 5211493 times.
10327321 if (sign) predictor -= diff;
431 5211493 else predictor += diff;
432
433 10327321 c->predictor = av_clip_int16(predictor);
434 10327321 c->step_index = step_index;
435
436 10327321 return (int16_t)c->predictor;
437 }
438
439 679344 static inline int16_t adpcm_ima_alp_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
440 {
441 int step_index;
442 int predictor;
443 int sign, delta, diff, step;
444
445 679344 step = ff_adpcm_step_table[c->step_index];
446 679344 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
447 679344 step_index = av_clip(step_index, 0, 88);
448
449 679344 sign = nibble & 8;
450 679344 delta = nibble & 7;
451 679344 diff = (delta * step) >> shift;
452 679344 predictor = c->predictor;
453
2/2
✓ Branch 0 taken 339842 times.
✓ Branch 1 taken 339502 times.
679344 if (sign) predictor -= diff;
454 339502 else predictor += diff;
455
456 679344 c->predictor = av_clip_int16(predictor);
457 679344 c->step_index = step_index;
458
459 679344 return (int16_t)c->predictor;
460 }
461
462 static inline int16_t adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nibble)
463 {
464 int step_index, step, delta, predictor;
465
466 step = ff_adpcm_step_table[c->step_index];
467
468 delta = step * (2 * nibble - 15);
469 predictor = c->predictor + delta;
470
471 step_index = c->step_index + mtf_index_table[(unsigned)nibble];
472 c->predictor = av_clip_int16(predictor >> 4);
473 c->step_index = av_clip(step_index, 0, 88);
474
475 return (int16_t)c->predictor;
476 }
477
478 386028 static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
479 {
480 int step_index;
481 int predictor;
482 int step;
483
484 386028 nibble = sign_extend(nibble & 0xF, 4);
485
486 386028 step = ima_cunning_step_table[c->step_index];
487 386028 step_index = c->step_index + ima_cunning_index_table[abs(nibble)];
488 386028 step_index = av_clip(step_index, 0, 60);
489
490 386028 predictor = c->predictor + step * nibble;
491
492 386028 c->predictor = av_clip_int16(predictor);
493 386028 c->step_index = step_index;
494
495 386028 return c->predictor;
496 }
497
498 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
499 {
500 int nibble, step_index, predictor, sign, delta, diff, step, shift;
501
502 shift = bps - 1;
503 nibble = get_bits_le(gb, bps),
504 step = ff_adpcm_step_table[c->step_index];
505 step_index = c->step_index + adpcm_index_tables[bps - 2][nibble];
506 step_index = av_clip(step_index, 0, 88);
507
508 sign = nibble & (1 << shift);
509 delta = av_zero_extend(nibble, shift);
510 diff = ((2 * delta + 1) * step) >> shift;
511 predictor = c->predictor;
512 if (sign) predictor -= diff;
513 else predictor += diff;
514
515 c->predictor = av_clip_int16(predictor);
516 c->step_index = step_index;
517
518 return (int16_t)c->predictor;
519 }
520
521 4696090 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble)
522 {
523 int step_index;
524 int predictor;
525 int diff, step;
526
527 4696090 step = ff_adpcm_step_table[c->step_index];
528 4696090 step_index = c->step_index + ff_adpcm_index_table[nibble];
529 4696090 step_index = av_clip(step_index, 0, 88);
530
531 4696090 diff = step >> 3;
532
2/2
✓ Branch 0 taken 1076119 times.
✓ Branch 1 taken 3619971 times.
4696090 if (nibble & 4) diff += step;
533
2/2
✓ Branch 0 taken 1984447 times.
✓ Branch 1 taken 2711643 times.
4696090 if (nibble & 2) diff += step >> 1;
534
2/2
✓ Branch 0 taken 2159261 times.
✓ Branch 1 taken 2536829 times.
4696090 if (nibble & 1) diff += step >> 2;
535
536
2/2
✓ Branch 0 taken 2338238 times.
✓ Branch 1 taken 2357852 times.
4696090 if (nibble & 8)
537 2338238 predictor = c->predictor - diff;
538 else
539 2357852 predictor = c->predictor + diff;
540
541 4696090 c->predictor = av_clip_int16(predictor);
542 4696090 c->step_index = step_index;
543
544 4696090 return c->predictor;
545 }
546
547 2233434 static inline int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
548 {
549 int predictor;
550
551 2233434 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
552
2/2
✓ Branch 0 taken 973371 times.
✓ Branch 1 taken 1260063 times.
2233434 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
553
554 2233434 c->sample2 = c->sample1;
555 2233434 c->sample1 = av_clip_int16(predictor);
556 2233434 c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
557
2/2
✓ Branch 0 taken 92703 times.
✓ Branch 1 taken 2140731 times.
2233434 if (c->idelta < 16) c->idelta = 16;
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2233434 times.
2233434 if (c->idelta > INT_MAX/768) {
559 av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
560 c->idelta = INT_MAX/768;
561 }
562
563 2233434 return c->sample1;
564 }
565
566 55124 static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
567 {
568 int step_index, predictor, sign, delta, diff, step;
569
570 55124 step = oki_step_table[c->step_index];
571 55124 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
572 55124 step_index = av_clip(step_index, 0, 48);
573
574 55124 sign = nibble & 8;
575 55124 delta = nibble & 7;
576 55124 diff = ((2 * delta + 1) * step) >> 3;
577 55124 predictor = c->predictor;
578
2/2
✓ Branch 0 taken 25352 times.
✓ Branch 1 taken 29772 times.
55124 if (sign) predictor -= diff;
579 29772 else predictor += diff;
580
581 55124 c->predictor = av_clip_intp2(predictor, 11);
582 55124 c->step_index = step_index;
583
584 55124 return c->predictor * 16;
585 }
586
587 524192 static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
588 {
589 int sign, delta, diff;
590 int new_step;
591
592 524192 sign = nibble & 8;
593 524192 delta = nibble & 7;
594 /* perform direct multiplication instead of series of jumps proposed by
595 * the reference ADPCM implementation since modern CPUs can do the mults
596 * quickly enough */
597 524192 diff = ((2 * delta + 1) * c->step) >> 3;
598 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
599
2/2
✓ Branch 0 taken 263253 times.
✓ Branch 1 taken 260939 times.
524192 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
600 524192 c->predictor = av_clip_int16(c->predictor);
601 /* calculate new step and clamp it to range 511..32767 */
602 524192 new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
603 524192 c->step = av_clip(new_step, 511, 32767);
604
605 524192 return (int16_t)c->predictor;
606 }
607
608 313380 static inline int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
609 {
610 int sign, delta, diff;
611
612 313380 sign = nibble & (1<<(size-1));
613 313380 delta = nibble & ((1<<(size-1))-1);
614 313380 diff = delta << (7 + c->step + shift);
615
616 /* clamp result */
617
2/2
✓ Branch 0 taken 129904 times.
✓ Branch 1 taken 183476 times.
313380 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
618
619 /* calculate new step */
620
4/4
✓ Branch 0 taken 97171 times.
✓ Branch 1 taken 216209 times.
✓ Branch 2 taken 75080 times.
✓ Branch 3 taken 22091 times.
313380 if (delta >= (2*size - 3) && c->step < 3)
621 75080 c->step++;
622
4/4
✓ Branch 0 taken 129907 times.
✓ Branch 1 taken 108393 times.
✓ Branch 2 taken 75080 times.
✓ Branch 3 taken 54827 times.
238300 else if (delta == 0 && c->step > 0)
623 75080 c->step--;
624
625 313380 return (int16_t) c->predictor;
626 }
627
628 1105920 static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
629 {
630
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1105915 times.
1105920 if(!c->step) {
631 5 c->predictor = 0;
632 5 c->step = 127;
633 }
634
635 1105920 c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
636 1105920 c->predictor = av_clip_int16(c->predictor);
637 1105920 c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
638 1105920 c->step = av_clip(c->step, 127, 24576);
639 1105920 return c->predictor;
640 }
641
642 static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
643 {
644 c->predictor += mtaf_stepsize[c->step][nibble];
645 c->predictor = av_clip_int16(c->predictor);
646 c->step += ff_adpcm_index_table[nibble];
647 c->step = av_clip_uintp2(c->step, 5);
648 return c->predictor;
649 }
650
651 static inline int16_t adpcm_zork_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
652 {
653 int16_t index = c->step_index;
654 uint32_t lookup_sample = ff_adpcm_step_table[index];
655 int32_t sample = 0;
656
657 if (nibble & 0x40)
658 sample += lookup_sample;
659 if (nibble & 0x20)
660 sample += lookup_sample >> 1;
661 if (nibble & 0x10)
662 sample += lookup_sample >> 2;
663 if (nibble & 0x08)
664 sample += lookup_sample >> 3;
665 if (nibble & 0x04)
666 sample += lookup_sample >> 4;
667 if (nibble & 0x02)
668 sample += lookup_sample >> 5;
669 if (nibble & 0x01)
670 sample += lookup_sample >> 6;
671 if (nibble & 0x80)
672 sample = -sample;
673
674 sample += c->predictor;
675 sample = av_clip_int16(sample);
676
677 index += zork_index_table[(nibble >> 4) & 7];
678 index = av_clip(index, 0, 88);
679
680 c->predictor = sample;
681 c->step_index = index;
682
683 return sample;
684 }
685
686 666 static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
687 const uint8_t *in, ADPCMChannelStatus *left,
688 ADPCMChannelStatus *right, int channels, int sample_offset)
689 {
690 int i, j;
691 int shift,filter,f0,f1;
692 int s_1,s_2;
693 int d,s,t;
694
695 666 out0 += sample_offset;
696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 666 times.
666 if (channels == 1)
697 out1 = out0 + 28;
698 else
699 666 out1 += sample_offset;
700
701
2/2
✓ Branch 0 taken 2664 times.
✓ Branch 1 taken 666 times.
3330 for(i=0;i<4;i++) {
702 2664 shift = 12 - (in[4+i*2] & 15);
703 2664 filter = in[4+i*2] >> 4;
704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
705 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
706 filter=0;
707 }
708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (shift < 0) {
709 avpriv_request_sample(avctx, "unknown XA-ADPCM shift %d", shift);
710 shift = 0;
711 }
712 2664 f0 = xa_adpcm_table[filter][0];
713 2664 f1 = xa_adpcm_table[filter][1];
714
715 2664 s_1 = left->sample1;
716 2664 s_2 = left->sample2;
717
718
2/2
✓ Branch 0 taken 74592 times.
✓ Branch 1 taken 2664 times.
77256 for(j=0;j<28;j++) {
719 74592 d = in[16+i+j*4];
720
721 74592 t = sign_extend(d, 4);
722 74592 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
723 74592 s_2 = s_1;
724 74592 s_1 = av_clip_int16(s);
725 74592 out0[j] = s_1;
726 }
727
728
1/2
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
2664 if (channels == 2) {
729 2664 left->sample1 = s_1;
730 2664 left->sample2 = s_2;
731 2664 s_1 = right->sample1;
732 2664 s_2 = right->sample2;
733 }
734
735 2664 shift = 12 - (in[5+i*2] & 15);
736 2664 filter = in[5+i*2] >> 4;
737
2/4
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2664 times.
2664 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table) || shift < 0) {
738 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
739 filter=0;
740 }
741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (shift < 0) {
742 avpriv_request_sample(avctx, "unknown XA-ADPCM shift %d", shift);
743 shift = 0;
744 }
745
746 2664 f0 = xa_adpcm_table[filter][0];
747 2664 f1 = xa_adpcm_table[filter][1];
748
749
2/2
✓ Branch 0 taken 74592 times.
✓ Branch 1 taken 2664 times.
77256 for(j=0;j<28;j++) {
750 74592 d = in[16+i+j*4];
751
752 74592 t = sign_extend(d >> 4, 4);
753 74592 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
754 74592 s_2 = s_1;
755 74592 s_1 = av_clip_int16(s);
756 74592 out1[j] = s_1;
757 }
758
759
1/2
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
2664 if (channels == 2) {
760 2664 right->sample1 = s_1;
761 2664 right->sample2 = s_2;
762 } else {
763 left->sample1 = s_1;
764 left->sample2 = s_2;
765 }
766
767 2664 out0 += 28 * (3 - channels);
768 2664 out1 += 28 * (3 - channels);
769 }
770
771 666 return 0;
772 }
773
774 195 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
775 {
776 195 ADPCMDecodeContext *c = avctx->priv_data;
777 GetBitContext gb;
778 const int8_t *table;
779 195 int channels = avctx->ch_layout.nb_channels;
780 int k0, signmask, nb_bits, count;
781 195 int size = buf_size*8;
782 int i;
783
784 195 init_get_bits(&gb, buf, size);
785
786 //read bits & initial values
787 195 nb_bits = get_bits(&gb, 2)+2;
788 195 table = swf_index_tables[nb_bits-2];
789 195 k0 = 1 << (nb_bits-2);
790 195 signmask = 1 << (nb_bits-1);
791
792
2/2
✓ Branch 1 taken 195 times.
✓ Branch 2 taken 195 times.
390 while (get_bits_count(&gb) <= size - 22 * channels) {
793
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 195 times.
585 for (i = 0; i < channels; i++) {
794 390 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
795 390 c->status[i].step_index = get_bits(&gb, 6);
796 }
797
798
3/4
✓ Branch 1 taken 798525 times.
✓ Branch 2 taken 195 times.
✓ Branch 3 taken 798525 times.
✗ Branch 4 not taken.
798720 for (count = 0; get_bits_count(&gb) <= size - nb_bits * channels && count < 4095; count++) {
799 int i;
800
801
2/2
✓ Branch 0 taken 1597050 times.
✓ Branch 1 taken 798525 times.
2395575 for (i = 0; i < channels; i++) {
802 // similar to IMA adpcm
803 1597050 int delta = get_bits(&gb, nb_bits);
804 1597050 int step = ff_adpcm_step_table[c->status[i].step_index];
805 1597050 int vpdiff = 0; // vpdiff = (delta+0.5)*step/4
806 1597050 int k = k0;
807
808 do {
809
2/2
✓ Branch 0 taken 1979561 times.
✓ Branch 1 taken 2811589 times.
4791150 if (delta & k)
810 1979561 vpdiff += step;
811 4791150 step >>= 1;
812 4791150 k >>= 1;
813
2/2
✓ Branch 0 taken 3194100 times.
✓ Branch 1 taken 1597050 times.
4791150 } while(k);
814 1597050 vpdiff += step;
815
816
2/2
✓ Branch 0 taken 803527 times.
✓ Branch 1 taken 793523 times.
1597050 if (delta & signmask)
817 803527 c->status[i].predictor -= vpdiff;
818 else
819 793523 c->status[i].predictor += vpdiff;
820
821 1597050 c->status[i].step_index += table[delta & (~signmask)];
822
823 1597050 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
824 1597050 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
825
826 1597050 *samples++ = c->status[i].predictor;
827 }
828 }
829 }
830 195 }
831
832 18335520 int16_t ff_adpcm_argo_expand_nibble(ADPCMChannelStatus *cs, int nibble, int shift, int flag)
833 {
834 18335520 int sample = sign_extend(nibble, 4) * (1 << shift);
835
836
2/2
✓ Branch 0 taken 9806208 times.
✓ Branch 1 taken 8529312 times.
18335520 if (flag)
837 9806208 sample += (8 * cs->sample1) - (4 * cs->sample2);
838 else
839 8529312 sample += 4 * cs->sample1;
840
841 18335520 sample = av_clip_int16(sample >> 2);
842
843 18335520 cs->sample2 = cs->sample1;
844 18335520 cs->sample1 = sample;
845
846 18335520 return sample;
847 }
848
849 static int adpcm_sanyo_expand3(ADPCMChannelStatus *c, int bits)
850 {
851 int sign, delta, add;
852
853 sign = bits & 4;
854 if (sign)
855 delta = 4 - (bits & 3);
856 else
857 delta = bits;
858
859 switch (delta) {
860 case 0:
861 add = 0;
862 c->step = (3 * c->step) >> 2;
863 break;
864 case 1:
865 add = c->step;
866 c->step = (4 * c->step - (c->step >> 1)) >> 2;
867 break;
868 case 2:
869 add = 2 * c->step;
870 c->step = ((c->step >> 1) + add) >> 1;
871 break;
872 case 3:
873 add = 4 * c->step - (c->step >> 1);
874 c->step = 2 * c->step;
875 break;
876 case 4:
877 add = (11 * c->step) >> 1;
878 c->step = 3 * c->step;
879 break;
880 default:
881 av_unreachable("There are cases for all control paths when bits is 3-bit");
882 }
883
884 if (sign)
885 add = -add;
886
887 c->predictor = av_clip_int16(c->predictor + add);
888 c->step = av_clip(c->step, 1, 7281);
889 return c->predictor;
890 }
891
892 static int adpcm_sanyo_expand4(ADPCMChannelStatus *c, int bits)
893 {
894 int sign, delta, add;
895
896 sign = bits & 8;
897 if (sign)
898 delta = 8 - (bits & 7);
899 else
900 delta = bits;
901
902 switch (delta) {
903 case 0:
904 add = 0;
905 c->step = (3 * c->step) >> 2;
906 break;
907 case 1:
908 add = c->step;
909 c->step = (3 * c->step) >> 2;
910 break;
911 case 2:
912 add = 2 * c->step;
913 break;
914 case 3:
915 add = 3 * c->step;
916 break;
917 case 4:
918 add = 4 * c->step;
919 break;
920 case 5:
921 add = (11 * c->step) >> 1;
922 c->step += c->step >> 2;
923 break;
924 case 6:
925 add = (15 * c->step) >> 1;
926 c->step = 2 * c->step;
927 break;
928 case 7:
929 if (sign)
930 add = (19 * c->step) >> 1;
931 else
932 add = (21 * c->step) >> 1;
933 c->step = (c->step >> 1) + 2 * c->step;
934 break;
935 case 8:
936 add = (25 * c->step) >> 1;
937 c->step = 5 * c->step;
938 break;
939 default:
940 av_unreachable("There are cases for all control paths when bits is 4-bit");
941 }
942
943 if (sign)
944 add = -add;
945
946 c->predictor = av_clip_int16(c->predictor + add);
947 c->step = av_clip(c->step, 1, 2621);
948 return c->predictor;
949 }
950
951 static int adpcm_sanyo_expand5(ADPCMChannelStatus *c, int bits)
952 {
953 int sign, delta, add;
954
955 sign = bits & 0x10;
956 if (sign)
957 delta = 16 - (bits & 0xF);
958 else
959 delta = bits;
960
961 add = delta * c->step;
962 switch (delta) {
963 case 0:
964 c->step += (c->step >> 2) - (c->step >> 1);
965 break;
966 case 1:
967 case 2:
968 case 3:
969 c->step += (c->step >> 3) - (c->step >> 2);
970 break;
971 case 4:
972 case 5:
973 c->step += (c->step >> 4) - (c->step >> 3);
974 break;
975 case 6:
976 break;
977 case 7:
978 c->step += c->step >> 3;
979 break;
980 case 8:
981 c->step += c->step >> 2;
982 break;
983 case 9:
984 c->step += c->step >> 1;
985 break;
986 case 10:
987 c->step = 2 * c->step - (c->step >> 3);
988 break;
989 case 11:
990 c->step = 2 * c->step + (c->step >> 3);
991 break;
992 case 12:
993 c->step = 2 * c->step + (c->step >> 1) - (c->step >> 3);
994 break;
995 case 13:
996 c->step = 3 * c->step - (c->step >> 2);
997 break;
998 case 14:
999 c->step *= 3;
1000 break;
1001 case 15:
1002 case 16:
1003 c->step = (7 * c->step) >> 1;
1004 break;
1005 }
1006
1007 if (sign)
1008 add = -add;
1009
1010 c->predictor = av_clip_int16(c->predictor + add);
1011 c->step = av_clip(c->step, 1, 1024);
1012 return c->predictor;
1013 }
1014
1015 /**
1016 * Get the number of samples (per channel) that will be decoded from the packet.
1017 * In one case, this is actually the maximum number of samples possible to
1018 * decode with the given buf_size.
1019 *
1020 * @param[out] coded_samples set to the number of samples as coded in the
1021 * packet, or 0 if the codec does not encode the
1022 * number of samples in each frame.
1023 * @param[out] approx_nb_samples set to non-zero if the number of samples
1024 * returned is an approximation.
1025 */
1026 37706 static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
1027 int buf_size, int *coded_samples, int *approx_nb_samples)
1028 {
1029 37706 ADPCMDecodeContext *s = avctx->priv_data;
1030 37706 int nb_samples = 0;
1031 37706 int ch = avctx->ch_layout.nb_channels;
1032 37706 int has_coded_samples = 0;
1033 int header_size;
1034
1035 37706 *coded_samples = 0;
1036 37706 *approx_nb_samples = 0;
1037
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37706 times.
37706 if(ch <= 0)
1039 return 0;
1040
1041
4/4
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 26342 times.
✓ Branch 2 taken 1195 times.
✓ Branch 3 taken 9569 times.
37706 switch (avctx->codec->id) {
1042 /* constant, only check buf_size */
1043 600 case AV_CODEC_ID_ADPCM_EA_XAS:
1044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 if (buf_size < 76 * ch)
1045 return 0;
1046 600 nb_samples = 128;
1047 600 break;
1048 26342 case AV_CODEC_ID_ADPCM_IMA_QT:
1049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26342 times.
26342 if (buf_size < 34 * ch)
1050 return 0;
1051 26342 nb_samples = 64;
1052 26342 break;
1053 /* simple 4-bit adpcm */
1054 1195 case AV_CODEC_ID_ADPCM_CT:
1055 case AV_CODEC_ID_ADPCM_IMA_APC:
1056 case AV_CODEC_ID_ADPCM_IMA_CUNNING:
1057 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1058 case AV_CODEC_ID_ADPCM_IMA_OKI:
1059 case AV_CODEC_ID_ADPCM_IMA_WS:
1060 case AV_CODEC_ID_ADPCM_YAMAHA:
1061 case AV_CODEC_ID_ADPCM_AICA:
1062 case AV_CODEC_ID_ADPCM_IMA_SSI:
1063 case AV_CODEC_ID_ADPCM_IMA_APM:
1064 case AV_CODEC_ID_ADPCM_IMA_ALP:
1065 case AV_CODEC_ID_ADPCM_IMA_MTF:
1066 1195 nb_samples = buf_size * 2 / ch;
1067 1195 break;
1068 }
1069
2/2
✓ Branch 0 taken 28137 times.
✓ Branch 1 taken 9569 times.
37706 if (nb_samples)
1070 28137 return nb_samples;
1071
1072 /* simple 4-bit adpcm, with header */
1073 9569 header_size = 0;
1074
3/3
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 350 times.
✓ Branch 2 taken 9074 times.
9569 switch (avctx->codec->id) {
1075 145 case AV_CODEC_ID_ADPCM_4XM:
1076 case AV_CODEC_ID_ADPCM_AGM:
1077 case AV_CODEC_ID_ADPCM_IMA_ACORN:
1078 case AV_CODEC_ID_ADPCM_IMA_DAT4:
1079 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
1080 145 case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
1081 350 case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
1082 }
1083
2/2
✓ Branch 0 taken 495 times.
✓ Branch 1 taken 9074 times.
9569 if (header_size > 0)
1084 495 return (buf_size - header_size) * 2 / ch;
1085
1086 /* more complex formats */
1087
17/23
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 158 times.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 400 times.
✓ Branch 5 taken 642 times.
✓ Branch 6 taken 649 times.
✓ Branch 7 taken 1000 times.
✓ Branch 8 taken 1668 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2950 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 57 times.
✓ Branch 13 taken 195 times.
✓ Branch 14 taken 71 times.
✓ Branch 15 taken 12 times.
✓ Branch 16 taken 37 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 32 times.
✓ Branch 19 taken 946 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
9074 switch (avctx->codec->id) {
1088 170 case AV_CODEC_ID_ADPCM_IMA_AMV:
1089 170 bytestream2_skip(gb, 4);
1090 170 has_coded_samples = 1;
1091 170 *coded_samples = bytestream2_get_le32u(gb);
1092 170 nb_samples = FFMIN((buf_size - 8) * 2, *coded_samples);
1093 170 bytestream2_seek(gb, -8, SEEK_CUR);
1094 170 break;
1095 158 case AV_CODEC_ID_ADPCM_EA:
1096 /* Stereo is 30 bytes per block */
1097 /* Mono is 15 bytes per block */
1098 158 has_coded_samples = 1;
1099 158 *coded_samples = bytestream2_get_le32(gb);
1100 158 *coded_samples -= *coded_samples % 28;
1101
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
1102 158 break;
1103 47 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1104 47 has_coded_samples = 1;
1105 47 *coded_samples = bytestream2_get_le32(gb);
1106 47 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
1107 47 break;
1108 40 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1109 40 nb_samples = (buf_size - ch) / ch * 2;
1110 40 break;
1111 400 case AV_CODEC_ID_ADPCM_EA_R1:
1112 case AV_CODEC_ID_ADPCM_EA_R2:
1113 case AV_CODEC_ID_ADPCM_EA_R3:
1114 /* maximum number of samples */
1115 /* has internal offsets and a per-frame switch to signal raw 16-bit */
1116 400 has_coded_samples = 1;
1117
3/4
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 125 times.
✗ Branch 3 not taken.
400 switch (avctx->codec->id) {
1118 95 case AV_CODEC_ID_ADPCM_EA_R1:
1119 95 header_size = 4 + 9 * ch;
1120 95 *coded_samples = bytestream2_get_le32(gb);
1121 95 break;
1122 180 case AV_CODEC_ID_ADPCM_EA_R2:
1123 180 header_size = 4 + 5 * ch;
1124 180 *coded_samples = bytestream2_get_le32(gb);
1125 180 break;
1126 125 case AV_CODEC_ID_ADPCM_EA_R3:
1127 125 header_size = 4 + 5 * ch;
1128 125 *coded_samples = bytestream2_get_be32(gb);
1129 125 break;
1130 }
1131 400 *coded_samples -= *coded_samples % 28;
1132 400 nb_samples = (buf_size - header_size) * 2 / ch;
1133 400 nb_samples -= nb_samples % 28;
1134 400 *approx_nb_samples = 1;
1135 400 break;
1136 642 case AV_CODEC_ID_ADPCM_IMA_DK3:
1137
1/2
✓ Branch 0 taken 642 times.
✗ Branch 1 not taken.
642 if (avctx->block_align > 0)
1138 642 buf_size = FFMIN(buf_size, avctx->block_align);
1139 642 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
1140 642 break;
1141 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
1142
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 if (avctx->block_align > 0)
1143 649 buf_size = FFMIN(buf_size, avctx->block_align);
1144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 649 times.
649 if (buf_size < 4 * ch)
1145 return AVERROR_INVALIDDATA;
1146 649 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
1147 649 break;
1148 1000 case AV_CODEC_ID_ADPCM_IMA_RAD:
1149
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 if (avctx->block_align > 0)
1150 1000 buf_size = FFMIN(buf_size, avctx->block_align);
1151 1000 nb_samples = (buf_size - 4 * ch) * 2 / ch;
1152 1000 break;
1153
2/4
✓ Branch 0 taken 1668 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1668 times.
1668 CASE(ADPCM_IMA_WAV,
1154 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1155 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1156 if (avctx->block_align > 0)
1157 buf_size = FFMIN(buf_size, avctx->block_align);
1158 if (buf_size < 4 * ch)
1159 return AVERROR_INVALIDDATA;
1160 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
1161 ) /* End of CASE */
1162 CASE(ADPCM_IMA_XBOX,
1163 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1164 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1165 if (avctx->block_align > 0)
1166 buf_size = FFMIN(buf_size, avctx->block_align);
1167 if (buf_size < 4 * ch)
1168 return AVERROR_INVALIDDATA;
1169 nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1;
1170 ) /* End of CASE */
1171 2950 case AV_CODEC_ID_ADPCM_MS:
1172
1/2
✓ Branch 0 taken 2950 times.
✗ Branch 1 not taken.
2950 if (avctx->block_align > 0)
1173 2950 buf_size = FFMIN(buf_size, avctx->block_align);
1174 2950 nb_samples = (buf_size - 6 * ch) * 2 / ch;
1175 2950 break;
1176 case AV_CODEC_ID_ADPCM_MTAF:
1177 if (avctx->block_align > 0)
1178 buf_size = FFMIN(buf_size, avctx->block_align);
1179 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
1180 break;
1181 57 case AV_CODEC_ID_ADPCM_SBPRO_2:
1182 case AV_CODEC_ID_ADPCM_SBPRO_3:
1183 case AV_CODEC_ID_ADPCM_SBPRO_4:
1184 {
1185 int samples_per_byte;
1186
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
57 switch (avctx->codec->id) {
1187 13 case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
1188 18 case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
1189 26 case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
1190 }
1191
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 54 times.
57 if (!s->status[0].step_index) {
1192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (buf_size < ch)
1193 return AVERROR_INVALIDDATA;
1194 3 nb_samples++;
1195 3 buf_size -= ch;
1196 }
1197 57 nb_samples += buf_size * samples_per_byte / ch;
1198 57 break;
1199 }
1200 195 case AV_CODEC_ID_ADPCM_SWF:
1201 {
1202 195 int buf_bits = buf_size * 8 - 2;
1203 195 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1204 195 int block_hdr_size = 22 * ch;
1205 195 int block_size = block_hdr_size + nbits * ch * 4095;
1206 195 int nblocks = buf_bits / block_size;
1207 195 int bits_left = buf_bits - nblocks * block_size;
1208 195 nb_samples = nblocks * 4096;
1209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
195 if (bits_left >= block_hdr_size)
1210 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
1211 195 break;
1212 }
1213 71 case AV_CODEC_ID_ADPCM_THP:
1214 case AV_CODEC_ID_ADPCM_THP_LE:
1215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (avctx->extradata) {
1216 nb_samples = buf_size * 14 / (8 * ch);
1217 break;
1218 }
1219 71 has_coded_samples = 1;
1220 71 bytestream2_skip(gb, 4); // channel size
1221 142 *coded_samples = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
1222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
142 bytestream2_get_le32(gb) :
1223 71 bytestream2_get_be32(gb);
1224 71 buf_size -= 8 + 36 * ch;
1225 71 buf_size /= ch;
1226 71 nb_samples = buf_size / 8 * 14;
1227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (buf_size % 8 > 1)
1228 nb_samples += (buf_size % 8 - 1) * 2;
1229 71 *approx_nb_samples = 1;
1230 71 break;
1231 12 case AV_CODEC_ID_ADPCM_AFC:
1232 12 nb_samples = buf_size / (9 * ch) * 16;
1233 12 break;
1234 37 case AV_CODEC_ID_ADPCM_XA:
1235 37 nb_samples = (buf_size / 128) * 224 / ch;
1236 37 break;
1237 case AV_CODEC_ID_ADPCM_XMD:
1238 nb_samples = buf_size / (21 * ch) * 32;
1239 break;
1240 32 case AV_CODEC_ID_ADPCM_DTK:
1241 case AV_CODEC_ID_ADPCM_PSX:
1242 32 nb_samples = buf_size / (16 * ch) * 28;
1243 32 break;
1244 946 case AV_CODEC_ID_ADPCM_ARGO:
1245 946 nb_samples = buf_size / avctx->block_align * 32;
1246 946 break;
1247 case AV_CODEC_ID_ADPCM_ZORK:
1248 nb_samples = buf_size / ch;
1249 break;
1250 case AV_CODEC_ID_ADPCM_SANYO:
1251 if (!avctx->extradata || avctx->extradata_size != 2)
1252 return AVERROR_INVALIDDATA;
1253 nb_samples = AV_RL16(avctx->extradata);
1254 break;
1255 }
1256
1257 /* validate coded sample count */
1258
4/6
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 8228 times.
✓ Branch 2 taken 846 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 846 times.
9074 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1259 return AVERROR_INVALIDDATA;
1260
1261 9074 return nb_samples;
1262 }
1263
1264 37706 static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
1265 int *got_frame_ptr, AVPacket *avpkt)
1266 {
1267 37706 const uint8_t *buf = avpkt->data;
1268 37706 int buf_size = avpkt->size;
1269 37706 ADPCMDecodeContext *c = avctx->priv_data;
1270 37706 int channels = avctx->ch_layout.nb_channels;
1271 int16_t *samples;
1272 int16_t **samples_p;
1273 int st; /* stereo */
1274 int nb_samples, coded_samples, approx_nb_samples, ret;
1275 GetByteContext gb;
1276
1277 37706 bytestream2_init(&gb, buf, buf_size);
1278 37706 nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37706 times.
37706 if (nb_samples <= 0) {
1280 av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
1281 return AVERROR_INVALIDDATA;
1282 }
1283
1284 /* get output buffer */
1285 37706 frame->nb_samples = nb_samples;
1286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37706 times.
37706 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1287 return ret;
1288 37706 samples = (int16_t *)frame->data[0];
1289 37706 samples_p = (int16_t **)frame->extended_data;
1290
1291 /* use coded_samples when applicable */
1292 /* it is always <= nb_samples, so the output buffer will be large enough */
1293
2/2
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 36860 times.
37706 if (coded_samples) {
1294
3/4
✓ Branch 0 taken 375 times.
✓ Branch 1 taken 471 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
846 if (!approx_nb_samples && coded_samples != nb_samples)
1295 av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
1296 846 frame->nb_samples = nb_samples = coded_samples;
1297 }
1298
1299 37706 st = channels == 2 ? 1 : 0;
1300
1301
32/45
✓ Branch 0 taken 26342 times.
✓ Branch 1 taken 1668 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2950 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 649 times.
✓ Branch 8 taken 642 times.
✓ Branch 9 taken 119 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 179 times.
✓ Branch 13 taken 127 times.
✓ Branch 14 taken 87 times.
✓ Branch 15 taken 85 times.
✓ Branch 16 taken 39 times.
✓ Branch 17 taken 54 times.
✓ Branch 18 taken 1000 times.
✓ Branch 19 taken 311 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 37 times.
✓ Branch 22 taken 47 times.
✓ Branch 23 taken 49 times.
✓ Branch 24 taken 158 times.
✓ Branch 25 taken 40 times.
✓ Branch 26 taken 400 times.
✓ Branch 27 taken 600 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 170 times.
✓ Branch 30 taken 350 times.
✓ Branch 31 taken 128 times.
✓ Branch 32 taken 57 times.
✓ Branch 33 taken 195 times.
✓ Branch 34 taken 136 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 12 times.
✓ Branch 37 taken 71 times.
✓ Branch 38 taken 32 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 41 taken 946 times.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
37706 switch(avctx->codec->id) {
1302
10/12
✓ Branch 1 taken 43648 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39464 times.
✓ Branch 4 taken 4184 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 43618 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 43648 times.
✓ Branch 13 taken 1396736 times.
✓ Branch 14 taken 43648 times.
✓ Branch 15 taken 43648 times.
✓ Branch 16 taken 26342 times.
1466726 CASE(ADPCM_IMA_QT,
1303 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
1304 Channel data is interleaved per-chunk. */
1305 for (int channel = 0; channel < channels; channel++) {
1306 ADPCMChannelStatus *cs = &c->status[channel];
1307 int predictor;
1308 int step_index;
1309 /* (pppppp) (piiiiiii) */
1310
1311 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
1312 predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
1313 step_index = predictor & 0x7F;
1314 predictor &= ~0x7F;
1315
1316 if (cs->step_index == step_index) {
1317 int diff = predictor - cs->predictor;
1318 if (diff < 0)
1319 diff = - diff;
1320 if (diff > 0x7f)
1321 goto update;
1322 } else {
1323 update:
1324 cs->step_index = step_index;
1325 cs->predictor = predictor;
1326 }
1327
1328 if (cs->step_index > 88u){
1329 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1330 channel, cs->step_index);
1331 return AVERROR_INVALIDDATA;
1332 }
1333
1334 samples = samples_p[channel];
1335
1336 for (int m = 0; m < 64; m += 2) {
1337 int byte = bytestream2_get_byteu(&gb);
1338 samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F);
1339 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 );
1340 }
1341 }
1342 ) /* End of CASE */
1343
10/22
✗ Branch 2 not taken.
✓ Branch 3 taken 3336 times.
✓ Branch 5 taken 3336 times.
✓ Branch 6 taken 1668 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1668 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 25 taken 1107936 times.
✓ Branch 26 taken 276984 times.
✓ Branch 27 taken 276984 times.
✓ Branch 28 taken 138492 times.
✓ Branch 29 taken 138492 times.
✓ Branch 30 taken 1668 times.
1528416 CASE(ADPCM_IMA_WAV,
1344 for (int i = 0; i < channels; i++) {
1345 ADPCMChannelStatus *cs = &c->status[i];
1346 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
1347
1348 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1349 if (cs->step_index > 88u){
1350 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1351 i, cs->step_index);
1352 return AVERROR_INVALIDDATA;
1353 }
1354 }
1355
1356 if (avctx->bits_per_coded_sample != 4) {
1357 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1358 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1359 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1360 GetBitContext g;
1361
1362 for (int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1363 for (int i = 0; i < channels; i++) {
1364 ADPCMChannelStatus *cs = &c->status[i];
1365 samples = &samples_p[i][1 + n * samples_per_block];
1366 for (int j = 0; j < block_size; j++) {
1367 temp[j] = buf[4 * channels + block_size * n * channels +
1368 (j % 4) + (j / 4) * (channels * 4) + i * 4];
1369 }
1370 ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
1371 if (ret < 0)
1372 return ret;
1373 for (int m = 0; m < samples_per_block; m++) {
1374 samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
1375 avctx->bits_per_coded_sample);
1376 }
1377 }
1378 }
1379 bytestream2_skip(&gb, avctx->block_align - channels * 4);
1380 } else {
1381 for (int n = 0; n < (nb_samples - 1) / 8; n++) {
1382 for (int i = 0; i < channels; i++) {
1383 ADPCMChannelStatus *cs = &c->status[i];
1384 samples = &samples_p[i][1 + n * 8];
1385 for (int m = 0; m < 8; m += 2) {
1386 int v = bytestream2_get_byteu(&gb);
1387 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1388 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1389 }
1390 }
1391 }
1392 }
1393 ) /* End of CASE */
1394 CASE(ADPCM_IMA_XBOX,
1395 for (int i = 0; i < channels; i++) {
1396 ADPCMChannelStatus *cs = &c->status[i];
1397 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
1398
1399 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1400 if (cs->step_index > 88u) {
1401 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1402 i, cs->step_index);
1403 return AVERROR_INVALIDDATA;
1404 }
1405 }
1406
1407 for (int n = 0; n < (nb_samples-1) / 8; n++) {
1408 for (int i = 0; i < channels; i++) {
1409 ADPCMChannelStatus *cs = &c->status[i];
1410 samples = &samples_p[i][1 + n * 8];
1411 for (int m = 0; m < 8; m += 2) {
1412 int v = bytestream2_get_byteu(&gb);
1413 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1414 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1415 }
1416 }
1417 }
1418 frame->nb_samples--;
1419 ) /* End of CASE */
1420
9/10
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 52 times.
✓ Branch 7 taken 52 times.
✓ Branch 8 taken 26 times.
✓ Branch 12 taken 38224 times.
✓ Branch 13 taken 52 times.
✓ Branch 14 taken 52 times.
✓ Branch 15 taken 26 times.
38406 CASE(ADPCM_4XM,
1421 for (int i = 0; i < channels; i++)
1422 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1423
1424 for (int i = 0; i < channels; i++) {
1425 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1426 if (c->status[i].step_index > 88u) {
1427 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1428 i, c->status[i].step_index);
1429 return AVERROR_INVALIDDATA;
1430 }
1431 }
1432
1433 for (int i = 0; i < channels; i++) {
1434 ADPCMChannelStatus *cs = &c->status[i];
1435 samples = (int16_t *)frame->data[i];
1436 for (int n = nb_samples >> 1; n > 0; n--) {
1437 int v = bytestream2_get_byteu(&gb);
1438 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
1439 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
1440 }
1441 }
1442 ) /* End of CASE */
1443 CASE(ADPCM_AGM,
1444 for (int i = 0; i < channels; i++)
1445 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1446 for (int i = 0; i < channels; i++)
1447 c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
1448
1449 for (int n = 0; n < nb_samples >> (1 - st); n++) {
1450 int v = bytestream2_get_byteu(&gb);
1451 *samples++ = adpcm_agm_expand_nibble(&c->status[0], v & 0xF);
1452 *samples++ = adpcm_agm_expand_nibble(&c->status[st], v >> 4 );
1453 }
1454 ) /* End of CASE */
1455
17/26
✗ Branch 0 not taken.
✓ Branch 1 taken 2950 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 2950 times.
✓ Branch 20 taken 2895 times.
✓ Branch 21 taken 55 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 2895 times.
✓ Branch 27 taken 2895 times.
✓ Branch 28 taken 55 times.
✓ Branch 31 taken 2895 times.
✓ Branch 32 taken 55 times.
✓ Branch 35 taken 2895 times.
✓ Branch 36 taken 55 times.
✓ Branch 38 taken 2895 times.
✓ Branch 39 taken 55 times.
✓ Branch 40 taken 2895 times.
✓ Branch 41 taken 55 times.
✓ Branch 45 taken 1116717 times.
✓ Branch 46 taken 2950 times.
1119667 CASE(ADPCM_MS,
1456 int block_predictor;
1457
1458 if (avctx->ch_layout.nb_channels > 2) {
1459 for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
1460 samples = samples_p[channel];
1461 block_predictor = bytestream2_get_byteu(&gb);
1462 if (block_predictor > 6) {
1463 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[%d] = %d\n",
1464 channel, block_predictor);
1465 return AVERROR_INVALIDDATA;
1466 }
1467 c->status[channel].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1468 c->status[channel].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1469 c->status[channel].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1470 c->status[channel].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1471 c->status[channel].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1472 *samples++ = c->status[channel].sample2;
1473 *samples++ = c->status[channel].sample1;
1474 for (int n = (nb_samples - 2) >> 1; n > 0; n--) {
1475 int byte = bytestream2_get_byteu(&gb);
1476 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte >> 4 );
1477 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte & 0x0F);
1478 }
1479 }
1480 } else {
1481 block_predictor = bytestream2_get_byteu(&gb);
1482 if (block_predictor > 6) {
1483 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
1484 block_predictor);
1485 return AVERROR_INVALIDDATA;
1486 }
1487 c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1488 c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1489 if (st) {
1490 block_predictor = bytestream2_get_byteu(&gb);
1491 if (block_predictor > 6) {
1492 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
1493 block_predictor);
1494 return AVERROR_INVALIDDATA;
1495 }
1496 c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1497 c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1498 }
1499 c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1500 if (st){
1501 c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1502 }
1503
1504 c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1505 if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1506 c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1507 if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1508
1509 *samples++ = c->status[0].sample2;
1510 if (st) *samples++ = c->status[1].sample2;
1511 *samples++ = c->status[0].sample1;
1512 if (st) *samples++ = c->status[1].sample1;
1513 for (int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1514 int byte = bytestream2_get_byteu(&gb);
1515 *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
1516 *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
1517 }
1518 }
1519 ) /* End of CASE */
1520 CASE(ADPCM_MTAF,
1521 for (int channel = 0; channel < channels; channel += 2) {
1522 bytestream2_skipu(&gb, 4);
1523 c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1524 c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1525 c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1526 bytestream2_skipu(&gb, 2);
1527 c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1528 bytestream2_skipu(&gb, 2);
1529 for (int n = 0; n < nb_samples; n += 2) {
1530 int v = bytestream2_get_byteu(&gb);
1531 samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
1532 samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 );
1533 }
1534 for (int n = 0; n < nb_samples; n += 2) {
1535 int v = bytestream2_get_byteu(&gb);
1536 samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
1537 samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 );
1538 }
1539 }
1540 ) /* End of CASE */
1541
5/6
✗ Branch 2 not taken.
✓ Branch 3 taken 1298 times.
✓ Branch 5 taken 1298 times.
✓ Branch 6 taken 649 times.
✓ Branch 10 taken 1323960 times.
✓ Branch 11 taken 649 times.
1325907 CASE(ADPCM_IMA_DK4,
1542 for (int channel = 0; channel < channels; channel++) {
1543 ADPCMChannelStatus *cs = &c->status[channel];
1544 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
1545 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1546 if (cs->step_index > 88u){
1547 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1548 channel, cs->step_index);
1549 return AVERROR_INVALIDDATA;
1550 }
1551 }
1552 for (int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1553 int v = bytestream2_get_byteu(&gb);
1554 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
1555 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1556 }
1557 ) /* End of CASE */
1558
1559 /* DK3 ADPCM support macro */
1560 #define DK3_GET_NEXT_NIBBLE() \
1561 if (decode_top_nibble_next) { \
1562 nibble = last_byte >> 4; \
1563 decode_top_nibble_next = 0; \
1564 } else { \
1565 last_byte = bytestream2_get_byteu(&gb); \
1566 nibble = last_byte & 0x0F; \
1567 decode_top_nibble_next = 1; \
1568 }
1569
11/14
✓ Branch 5 taken 642 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 642 times.
✓ Branch 10 taken 434634 times.
✓ Branch 11 taken 434634 times.
✓ Branch 14 taken 434634 times.
✓ Branch 15 taken 434634 times.
✓ Branch 18 taken 434634 times.
✓ Branch 19 taken 434634 times.
✓ Branch 22 taken 869268 times.
✓ Branch 23 taken 642 times.
✓ Branch 25 taken 642 times.
✗ Branch 26 not taken.
869910 CASE(ADPCM_IMA_DK3,
1570 int last_byte = 0;
1571 int nibble;
1572 int decode_top_nibble_next = 0;
1573 int diff_channel;
1574 const int16_t *samples_end = samples + channels * nb_samples;
1575
1576 bytestream2_skipu(&gb, 10);
1577 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1578 c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1579 c->status[0].step_index = bytestream2_get_byteu(&gb);
1580 c->status[1].step_index = bytestream2_get_byteu(&gb);
1581 if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
1582 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
1583 c->status[0].step_index, c->status[1].step_index);
1584 return AVERROR_INVALIDDATA;
1585 }
1586 /* sign extend the predictors */
1587 diff_channel = c->status[1].predictor;
1588
1589 while (samples < samples_end) {
1590
1591 /* for this algorithm, c->status[0] is the sum channel and
1592 * c->status[1] is the diff channel */
1593
1594 /* process the first predictor of the sum channel */
1595 DK3_GET_NEXT_NIBBLE();
1596 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1597
1598 /* process the diff channel predictor */
1599 DK3_GET_NEXT_NIBBLE();
1600 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
1601
1602 /* process the first pair of stereo PCM samples */
1603 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1604 *samples++ = c->status[0].predictor + c->status[1].predictor;
1605 *samples++ = c->status[0].predictor - c->status[1].predictor;
1606
1607 /* process the second predictor of the sum channel */
1608 DK3_GET_NEXT_NIBBLE();
1609 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1610
1611 /* process the second pair of stereo PCM samples */
1612 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1613 *samples++ = c->status[0].predictor + c->status[1].predictor;
1614 *samples++ = c->status[0].predictor - c->status[1].predictor;
1615 }
1616
1617 if ((bytestream2_tell(&gb) & 1))
1618 bytestream2_skip(&gb, 1);
1619 ) /* End of CASE */
1620
6/8
✗ Branch 2 not taken.
✓ Branch 3 taken 119 times.
✓ Branch 5 taken 119 times.
✓ Branch 6 taken 119 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 60452 times.
✓ Branch 12 taken 60452 times.
✓ Branch 13 taken 119 times.
60690 CASE(ADPCM_IMA_ISS,
1621 for (int channel = 0; channel < channels; channel++) {
1622 ADPCMChannelStatus *cs = &c->status[channel];
1623 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1624 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1625 if (cs->step_index > 88u){
1626 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1627 channel, cs->step_index);
1628 return AVERROR_INVALIDDATA;
1629 }
1630 }
1631
1632 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1633 int v1, v2;
1634 int v = bytestream2_get_byteu(&gb);
1635 /* nibbles are swapped for mono */
1636 if (st) {
1637 v1 = v >> 4;
1638 v2 = v & 0x0F;
1639 } else {
1640 v2 = v >> 4;
1641 v1 = v & 0x0F;
1642 }
1643 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
1644 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
1645 }
1646 ) /* End of CASE */
1647 CASE(ADPCM_IMA_MOFLEX,
1648 for (int channel = 0; channel < channels; channel++) {
1649 ADPCMChannelStatus *cs = &c->status[channel];
1650 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1651 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1652 if (cs->step_index > 88u){
1653 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1654 channel, cs->step_index);
1655 return AVERROR_INVALIDDATA;
1656 }
1657 }
1658
1659 for (int subframe = 0; subframe < nb_samples / 256; subframe++) {
1660 for (int channel = 0; channel < channels; channel++) {
1661 samples = samples_p[channel] + 256 * subframe;
1662 for (int n = 0; n < 256; n += 2) {
1663 int v = bytestream2_get_byteu(&gb);
1664 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1665 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1666 }
1667 }
1668 }
1669 ) /* End of CASE */
1670 CASE(ADPCM_IMA_DAT4,
1671 for (int channel = 0; channel < channels; channel++) {
1672 ADPCMChannelStatus *cs = &c->status[channel];
1673 samples = samples_p[channel];
1674 bytestream2_skip(&gb, 4);
1675 for (int n = 0; n < nb_samples; n += 2) {
1676 int v = bytestream2_get_byteu(&gb);
1677 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1678 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1679 }
1680 }
1681 ) /* End of CASE */
1682
2/2
✓ Branch 3 taken 732060 times.
✓ Branch 4 taken 179 times.
732239 CASE(ADPCM_IMA_APC,
1683 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1684 int v = bytestream2_get_byteu(&gb);
1685 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
1686 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1687 }
1688 ) /* End of CASE */
1689
2/2
✓ Branch 3 taken 514600 times.
✓ Branch 4 taken 127 times.
514727 CASE(ADPCM_IMA_SSI,
1690 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1691 int v = bytestream2_get_byteu(&gb);
1692 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0], v >> 4 );
1693 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0x0F);
1694 }
1695 ) /* End of CASE */
1696
4/4
✓ Branch 3 taken 347109 times.
✓ Branch 4 taken 181830 times.
✓ Branch 5 taken 181830 times.
✓ Branch 6 taken 87 times.
529026 CASE(ADPCM_IMA_APM,
1697 for (int n = nb_samples / 2; n > 0; n--) {
1698 for (int channel = 0; channel < channels; channel++) {
1699 int v = bytestream2_get_byteu(&gb);
1700 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4 );
1701 samples[st] = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F);
1702 }
1703 samples += channels;
1704 }
1705 ) /* End of CASE */
1706
4/4
✓ Branch 3 taken 339672 times.
✓ Branch 4 taken 172372 times.
✓ Branch 5 taken 172372 times.
✓ Branch 6 taken 85 times.
512129 CASE(ADPCM_IMA_ALP,
1707 for (int n = nb_samples / 2; n > 0; n--) {
1708 for (int channel = 0; channel < channels; channel++) {
1709 int v = bytestream2_get_byteu(&gb);
1710 *samples++ = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4 , 2);
1711 samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2);
1712 }
1713 samples += channels;
1714 }
1715 ) /* End of CASE */
1716
4/4
✓ Branch 3 taken 193014 times.
✓ Branch 4 taken 51 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 39 times.
193104 CASE(ADPCM_IMA_CUNNING,
1717 for (int channel = 0; channel < channels; channel++) {
1718 int16_t *smp = samples_p[channel];
1719 for (int n = 0; n < nb_samples / 2; n++) {
1720 int v = bytestream2_get_byteu(&gb);
1721 *smp++ = adpcm_ima_cunning_expand_nibble(&c->status[channel], v & 0x0F);
1722 *smp++ = adpcm_ima_cunning_expand_nibble(&c->status[channel], v >> 4);
1723 }
1724 }
1725 ) /* End of CASE */
1726
2/2
✓ Branch 3 taken 27562 times.
✓ Branch 4 taken 54 times.
27616 CASE(ADPCM_IMA_OKI,
1727 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1728 int v = bytestream2_get_byteu(&gb);
1729 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
1730 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
1731 }
1732 ) /* End of CASE */
1733
10/12
✗ Branch 2 not taken.
✓ Branch 3 taken 2000 times.
✓ Branch 5 taken 2000 times.
✓ Branch 6 taken 1000 times.
✓ Branch 8 taken 16000 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 32000 times.
✓ Branch 13 taken 16000 times.
✓ Branch 15 taken 32000 times.
✓ Branch 16 taken 16000 times.
✓ Branch 17 taken 16000 times.
✓ Branch 18 taken 1000 times.
83000 CASE(ADPCM_IMA_RAD,
1734 for (int channel = 0; channel < channels; channel++) {
1735 ADPCMChannelStatus *cs = &c->status[channel];
1736 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1737 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1738 if (cs->step_index > 88u){
1739 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1740 channel, cs->step_index);
1741 return AVERROR_INVALIDDATA;
1742 }
1743 }
1744 for (int n = 0; n < nb_samples / 2; n++) {
1745 int byte[2];
1746
1747 byte[0] = bytestream2_get_byteu(&gb);
1748 if (st)
1749 byte[1] = bytestream2_get_byteu(&gb);
1750 for (int channel = 0; channel < channels; channel++) {
1751 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
1752 }
1753 for (int channel = 0; channel < channels; channel++) {
1754 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
1755 }
1756 }
1757 ) /* End of CASE */
1758
10/10
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 299 times.
✓ Branch 5 taken 8820 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 12 times.
✓ Branch 12 taken 298777 times.
✓ Branch 13 taken 166477 times.
✓ Branch 14 taken 166477 times.
✓ Branch 15 taken 299 times.
474397 CASE(ADPCM_IMA_WS,
1759 if (c->vqa_version == 3) {
1760 for (int channel = 0; channel < channels; channel++) {
1761 int16_t *smp = samples_p[channel];
1762
1763 for (int n = nb_samples / 2; n > 0; n--) {
1764 int v = bytestream2_get_byteu(&gb);
1765 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1766 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1767 }
1768 }
1769 } else {
1770 for (int n = nb_samples / 2; n > 0; n--) {
1771 for (int channel = 0; channel < channels; channel++) {
1772 int v = bytestream2_get_byteu(&gb);
1773 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1774 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1775 }
1776 samples += channels;
1777 }
1778 }
1779 bytestream2_seek(&gb, 0, SEEK_END);
1780 ) /* End of CASE */
1781 CASE(ADPCM_XMD,
1782 int bytes_remaining, block = 0;
1783 while (bytestream2_get_bytes_left(&gb) >= 21 * channels) {
1784 for (int channel = 0; channel < channels; channel++) {
1785 int16_t *out = samples_p[channel] + block * 32;
1786 int16_t history[2];
1787 uint16_t scale;
1788
1789 history[1] = sign_extend(bytestream2_get_le16(&gb), 16);
1790 history[0] = sign_extend(bytestream2_get_le16(&gb), 16);
1791 scale = bytestream2_get_le16(&gb);
1792
1793 out[0] = history[1];
1794 out[1] = history[0];
1795
1796 for (int n = 0; n < 15; n++) {
1797 unsigned byte = bytestream2_get_byte(&gb);
1798 int32_t nibble[2];
1799
1800 nibble[0] = sign_extend(byte & 15, 4);
1801 nibble[1] = sign_extend(byte >> 4, 4);
1802
1803 out[2+n*2] = nibble[0]*scale + ((history[0]*3667 - history[1]*1642) >> 11);
1804 history[1] = history[0];
1805 history[0] = out[2+n*2];
1806
1807 out[2+n*2+1] = nibble[1]*scale + ((history[0]*3667 - history[1]*1642) >> 11);
1808 history[1] = history[0];
1809 history[0] = out[2+n*2+1];
1810 }
1811 }
1812
1813 block++;
1814 }
1815 bytes_remaining = bytestream2_get_bytes_left(&gb);
1816 if (bytes_remaining > 0) {
1817 bytestream2_skip(&gb, bytes_remaining);
1818 }
1819 ) /* End of CASE */
1820
4/6
✗ Branch 2 not taken.
✓ Branch 3 taken 666 times.
✓ Branch 6 taken 666 times.
✓ Branch 7 taken 37 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 37 times.
703 CASE(ADPCM_XA,
1821 int16_t *out0 = samples_p[0];
1822 int16_t *out1 = samples_p[1];
1823 int samples_per_block = 28 * (3 - channels) * 4;
1824 int sample_offset = 0;
1825 int bytes_remaining;
1826 while (bytestream2_get_bytes_left(&gb) >= 128) {
1827 if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
1828 &c->status[0], &c->status[1],
1829 channels, sample_offset)) < 0)
1830 return ret;
1831 bytestream2_skipu(&gb, 128);
1832 sample_offset += samples_per_block;
1833 }
1834 /* Less than a full block of data left, e.g. when reading from
1835 * 2324 byte per sector XA; the remainder is padding */
1836 bytes_remaining = bytestream2_get_bytes_left(&gb);
1837 if (bytes_remaining > 0) {
1838 bytestream2_skip(&gb, bytes_remaining);
1839 }
1840 ) /* End of CASE */
1841
8/10
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 5 taken 47 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 94 times.
✓ Branch 9 taken 94 times.
✓ Branch 10 taken 47 times.
✓ Branch 14 taken 68996 times.
✓ Branch 15 taken 47 times.
69231 CASE(ADPCM_IMA_EA_EACS,
1842 for (int i = 0; i <= st; i++) {
1843 c->status[i].step_index = bytestream2_get_le32u(&gb);
1844 if (c->status[i].step_index > 88u) {
1845 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1846 i, c->status[i].step_index);
1847 return AVERROR_INVALIDDATA;
1848 }
1849 }
1850 for (int i = 0; i <= st; i++) {
1851 c->status[i].predictor = bytestream2_get_le32u(&gb);
1852 if (FFABS((int64_t)c->status[i].predictor) > (1<<16))
1853 return AVERROR_INVALIDDATA;
1854 }
1855
1856 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1857 int byte = bytestream2_get_byteu(&gb);
1858 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
1859 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
1860 }
1861 ) /* End of CASE */
1862
2/2
✓ Branch 3 taken 71392 times.
✓ Branch 4 taken 49 times.
71441 CASE(ADPCM_IMA_EA_SEAD,
1863 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1864 int byte = bytestream2_get_byteu(&gb);
1865 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
1866 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
1867 }
1868 ) /* End of CASE */
1869
9/16
✗ Branch 0 not taken.
✓ Branch 1 taken 158 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 9 taken 8296 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 232288 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 240584 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 232288 times.
✓ Branch 18 taken 8296 times.
✓ Branch 19 taken 8296 times.
✓ Branch 20 taken 158 times.
✓ Branch 21 taken 158 times.
✗ Branch 22 not taken.
240742 CASE(ADPCM_EA,
1870 int previous_left_sample, previous_right_sample;
1871 int current_left_sample, current_right_sample;
1872 int next_left_sample, next_right_sample;
1873 int coeff1l, coeff2l, coeff1r, coeff2r;
1874 int shift_left, shift_right;
1875
1876 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte (stereo) or 15-byte (mono) pieces,
1877 each coding 28 stereo/mono samples. */
1878
1879 if (channels != 2 && channels != 1)
1880 return AVERROR_INVALIDDATA;
1881
1882 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1883 previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1884 current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1885 previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1886
1887 for (int count1 = 0; count1 < nb_samples / 28; count1++) {
1888 int byte = bytestream2_get_byteu(&gb);
1889 coeff1l = ea_adpcm_table[ byte >> 4 ];
1890 coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
1891 coeff1r = ea_adpcm_table[ byte & 0x0F];
1892 coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
1893
1894 if (channels == 2){
1895 byte = bytestream2_get_byteu(&gb);
1896 shift_left = 20 - (byte >> 4);
1897 shift_right = 20 - (byte & 0x0F);
1898 } else{
1899 /* Mono packs the shift into the coefficient byte's lower nibble instead */
1900 shift_left = 20 - (byte & 0x0F);
1901 }
1902
1903 for (int count2 = 0; count2 < (channels == 2 ? 28 : 14); count2++) {
1904 byte = bytestream2_get_byteu(&gb);
1905 next_left_sample = sign_extend(byte >> 4, 4) * (1 << shift_left);
1906
1907 next_left_sample = (next_left_sample +
1908 (current_left_sample * coeff1l) +
1909 (previous_left_sample * coeff2l) + 0x80) >> 8;
1910
1911 previous_left_sample = current_left_sample;
1912 current_left_sample = av_clip_int16(next_left_sample);
1913 *samples++ = current_left_sample;
1914
1915 if (channels == 2){
1916 next_right_sample = sign_extend(byte, 4) * (1 << shift_right);
1917
1918 next_right_sample = (next_right_sample +
1919 (current_right_sample * coeff1r) +
1920 (previous_right_sample * coeff2r) + 0x80) >> 8;
1921
1922 previous_right_sample = current_right_sample;
1923 current_right_sample = av_clip_int16(next_right_sample);
1924 *samples++ = current_right_sample;
1925 } else {
1926 next_left_sample = sign_extend(byte, 4) * (1 << shift_left);
1927
1928 next_left_sample = (next_left_sample +
1929 (current_left_sample * coeff1l) +
1930 (previous_left_sample * coeff2l) + 0x80) >> 8;
1931
1932 previous_left_sample = current_left_sample;
1933 current_left_sample = av_clip_int16(next_left_sample);
1934
1935 *samples++ = current_left_sample;
1936 }
1937 }
1938 }
1939 bytestream2_skip(&gb, channels == 2 ? 2 : 3); // Skip terminating NULs
1940 ) /* End of CASE */
1941
11/12
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 40 times.
✓ Branch 6 taken 560 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2240 times.
✓ Branch 10 taken 1120 times.
✓ Branch 11 taken 1120 times.
✓ Branch 12 taken 560 times.
✓ Branch 13 taken 560 times.
✓ Branch 14 taken 40 times.
4200 CASE(ADPCM_EA_MAXIS_XA,
1942 int coeff[2][2], shift[2];
1943
1944 for (int channel = 0; channel < channels; channel++) {
1945 int byte = bytestream2_get_byteu(&gb);
1946 for (int i = 0; i < 2; i++)
1947 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
1948 shift[channel] = 20 - (byte & 0x0F);
1949 }
1950 for (int count1 = 0; count1 < nb_samples / 2; count1++) {
1951 int byte[2];
1952
1953 byte[0] = bytestream2_get_byteu(&gb);
1954 if (st) byte[1] = bytestream2_get_byteu(&gb);
1955 for (int i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
1956 for (int channel = 0; channel < channels; channel++) {
1957 int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]);
1958 sample = (sample +
1959 c->status[channel].sample1 * coeff[channel][0] +
1960 c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
1961 c->status[channel].sample2 = c->status[channel].sample1;
1962 c->status[channel].sample1 = av_clip_int16(sample);
1963 *samples++ = c->status[channel].sample1;
1964 }
1965 }
1966 }
1967 bytestream2_seek(&gb, 0, SEEK_END);
1968 ) /* End of CASE */
1969 #if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1970 400 case AV_CODEC_ID_ADPCM_EA_R1:
1971 case AV_CODEC_ID_ADPCM_EA_R2:
1972 case AV_CODEC_ID_ADPCM_EA_R3: {
1973 /* channel numbering
1974 2chan: 0=fl, 1=fr
1975 4chan: 0=fl, 1=rl, 2=fr, 3=rr
1976 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
1977 400 const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
1978 int previous_sample, current_sample, next_sample;
1979 int coeff1, coeff2;
1980 int shift;
1981 uint16_t *samplesC;
1982 400 int count = 0;
1983 int offsets[6];
1984
1985
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 400 times.
1200 for (unsigned channel = 0; channel < channels; channel++)
1986
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 550 times.
800 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1987 550 bytestream2_get_le32(&gb)) +
1988 800 (channels + 1) * 4;
1989
1990
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 400 times.
1200 for (unsigned channel = 0; channel < channels; channel++) {
1991 int count1;
1992
1993 800 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
1994 800 samplesC = samples_p[channel];
1995
1996
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 610 times.
800 if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
1997 190 current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1998 190 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1999 } else {
2000 610 current_sample = c->status[channel].predictor;
2001 610 previous_sample = c->status[channel].prev_sample;
2002 }
2003
2004
2/2
✓ Branch 0 taken 41192 times.
✓ Branch 1 taken 800 times.
41992 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2005 41192 int byte = bytestream2_get_byte(&gb);
2006
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 41180 times.
41192 if (byte == 0xEE) { /* only seen in R2 and R3 */
2007 12 current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
2008 12 previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
2009
2010
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 12 times.
348 for (int count2 = 0; count2 < 28; count2++)
2011 336 *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
2012 } else {
2013 41180 coeff1 = ea_adpcm_table[ byte >> 4 ];
2014 41180 coeff2 = ea_adpcm_table[(byte >> 4) + 4];
2015 41180 shift = 20 - (byte & 0x0F);
2016
2017
2/2
✓ Branch 0 taken 1153040 times.
✓ Branch 1 taken 41180 times.
1194220 for (int count2 = 0; count2 < 28; count2++) {
2018
2/2
✓ Branch 0 taken 576520 times.
✓ Branch 1 taken 576520 times.
1153040 if (count2 & 1)
2019 576520 next_sample = (unsigned)sign_extend(byte, 4) << shift;
2020 else {
2021 576520 byte = bytestream2_get_byte(&gb);
2022 576520 next_sample = (unsigned)sign_extend(byte >> 4, 4) << shift;
2023 }
2024
2025 1153040 next_sample += (current_sample * coeff1) +
2026 1153040 (previous_sample * coeff2);
2027 1153040 next_sample = av_clip_int16(next_sample >> 8);
2028
2029 1153040 previous_sample = current_sample;
2030 1153040 current_sample = next_sample;
2031 1153040 *samplesC++ = current_sample;
2032 }
2033 }
2034 }
2035
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 400 times.
800 if (!count) {
2036 400 count = count1;
2037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
400 } else if (count != count1) {
2038 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
2039 count = FFMAX(count, count1);
2040 }
2041
2042
2/2
✓ Branch 0 taken 610 times.
✓ Branch 1 taken 190 times.
800 if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
2043 610 c->status[channel].predictor = current_sample;
2044 610 c->status[channel].prev_sample = previous_sample;
2045 }
2046 }
2047
2048 400 frame->nb_samples = count * 28;
2049 400 bytestream2_seek(&gb, 0, SEEK_END);
2050 400 break;
2051 }
2052 #endif /* CONFIG_ADPCM_EA_Rx_DECODER */
2053
10/10
✓ Branch 1 taken 4800 times.
✓ Branch 2 taken 2400 times.
✓ Branch 4 taken 2400 times.
✓ Branch 5 taken 600 times.
✓ Branch 7 taken 36000 times.
✓ Branch 8 taken 9000 times.
✓ Branch 9 taken 9000 times.
✓ Branch 10 taken 600 times.
✓ Branch 11 taken 600 times.
✓ Branch 12 taken 600 times.
53400 CASE(ADPCM_EA_XAS,
2054 for (int channel=0; channel < channels; channel++) {
2055 int coeff[2][4], shift[4];
2056 int16_t *s = samples_p[channel];
2057 for (int n = 0; n < 4; n++, s += 32) {
2058 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
2059 for (int i = 0; i < 2; i++)
2060 coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
2061 s[0] = val & ~0x0F;
2062
2063 val = sign_extend(bytestream2_get_le16u(&gb), 16);
2064 shift[n] = 20 - (val & 0x0F);
2065 s[1] = val & ~0x0F;
2066 }
2067
2068 for (int m = 2; m < 32; m += 2) {
2069 s = &samples_p[channel][m];
2070 for (int n = 0; n < 4; n++, s += 32) {
2071 int level, pred;
2072 int byte = bytestream2_get_byteu(&gb);
2073
2074 level = sign_extend(byte >> 4, 4) * (1 << shift[n]);
2075 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
2076 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
2077
2078 level = sign_extend(byte, 4) * (1 << shift[n]);
2079 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
2080 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
2081 }
2082 }
2083 }
2084 ) /* End of CASE */
2085 CASE(ADPCM_IMA_ACORN,
2086 for (int channel = 0; channel < channels; channel++) {
2087 ADPCMChannelStatus *cs = &c->status[channel];
2088 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
2089 cs->step_index = bytestream2_get_le16u(&gb) & 0xFF;
2090 if (cs->step_index > 88u){
2091 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
2092 channel, cs->step_index);
2093 return AVERROR_INVALIDDATA;
2094 }
2095 }
2096 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2097 int byte = bytestream2_get_byteu(&gb);
2098 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte & 0x0F, 3);
2099 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte >> 4, 3);
2100 }
2101 ) /* End of CASE */
2102
7/10
✗ Branch 0 not taken.
✓ Branch 1 taken 170 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 170 times.
✓ Branch 13 taken 117130 times.
✓ Branch 14 taken 170 times.
✓ Branch 15 taken 23 times.
✓ Branch 16 taken 147 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 23 times.
117300 CASE(ADPCM_IMA_AMV,
2103 av_assert0(channels == 1);
2104
2105 /*
2106 * Header format:
2107 * int16_t predictor;
2108 * uint8_t step_index;
2109 * uint8_t reserved;
2110 * uint32_t frame_size;
2111 *
2112 * Some implementations have step_index as 16-bits, but others
2113 * only use the lower 8 and store garbage in the upper 8.
2114 */
2115 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
2116 c->status[0].step_index = bytestream2_get_byteu(&gb);
2117 bytestream2_skipu(&gb, 5);
2118 if (c->status[0].step_index > 88u) {
2119 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
2120 c->status[0].step_index);
2121 return AVERROR_INVALIDDATA;
2122 }
2123
2124 for (int n = nb_samples >> 1; n > 0; n--) {
2125 int v = bytestream2_get_byteu(&gb);
2126
2127 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
2128 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
2129 }
2130
2131 if (nb_samples & 1) {
2132 int v = bytestream2_get_byteu(&gb);
2133 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
2134
2135 if (v & 0x0F) {
2136 /* Holds true on all the http://samples.mplayerhq.hu/amv samples. */
2137 av_log(avctx, AV_LOG_WARNING, "Last nibble set on packet with odd sample count.\n");
2138 av_log(avctx, AV_LOG_WARNING, "Sample will be skipped.\n");
2139 }
2140 }
2141 ) /* End of CASE */
2142
5/6
✗ Branch 3 not taken.
✓ Branch 4 taken 350 times.
✓ Branch 6 taken 350 times.
✓ Branch 7 taken 350 times.
✓ Branch 11 taken 89600 times.
✓ Branch 12 taken 350 times.
90300 CASE(ADPCM_IMA_SMJPEG,
2143 for (int i = 0; i < channels; i++) {
2144 c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
2145 c->status[i].step_index = bytestream2_get_byteu(&gb);
2146 bytestream2_skipu(&gb, 1);
2147 if (c->status[i].step_index > 88u) {
2148 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
2149 c->status[i].step_index);
2150 return AVERROR_INVALIDDATA;
2151 }
2152 }
2153
2154 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2155 int v = bytestream2_get_byteu(&gb);
2156
2157 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4 );
2158 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf);
2159 }
2160 ) /* End of CASE */
2161
2/2
✓ Branch 3 taken 262096 times.
✓ Branch 4 taken 128 times.
262224 CASE(ADPCM_CT,
2162 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2163 int v = bytestream2_get_byteu(&gb);
2164 *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
2165 *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
2166 }
2167 ) /* End of CASE */
2168 #if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2169 CONFIG_ADPCM_SBPRO_4_DECODER
2170 57 case AV_CODEC_ID_ADPCM_SBPRO_4:
2171 case AV_CODEC_ID_ADPCM_SBPRO_3:
2172 case AV_CODEC_ID_ADPCM_SBPRO_2:
2173
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 54 times.
57 if (!c->status[0].step_index) {
2174 /* the first byte is a raw sample */
2175 3 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (st)
2177 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2178 3 c->status[0].step_index = 1;
2179 3 nb_samples--;
2180 }
2181
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 31 times.
57 if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
2182
2/2
✓ Branch 0 taken 52230 times.
✓ Branch 1 taken 26 times.
52256 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2183 52230 int byte = bytestream2_get_byteu(&gb);
2184 104460 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2185 52230 byte >> 4, 4, 0);
2186 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2187 52230 byte & 0x0F, 4, 0);
2188 }
2189
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 13 times.
31 } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
2190
2/2
✓ Branch 0 taken 34820 times.
✓ Branch 1 taken 18 times.
34838 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2191 34820 int byte = bytestream2_get_byteu(&gb);
2192 69640 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2193 34820 byte >> 5 , 3, 0);
2194 69640 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2195 34820 (byte >> 2) & 0x07, 3, 0);
2196 34820 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2197 34820 byte & 0x03, 2, 0);
2198 }
2199 } else {
2200
2/2
✓ Branch 0 taken 26115 times.
✓ Branch 1 taken 13 times.
26128 for (int n = nb_samples >> (2 - st); n > 0; n--) {
2201 26115 int byte = bytestream2_get_byteu(&gb);
2202 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2203 26115 byte >> 6 , 2, 2);
2204 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2205 26115 (byte >> 4) & 0x03, 2, 2);
2206 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2207 26115 (byte >> 2) & 0x03, 2, 2);
2208 26115 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2209 26115 byte & 0x03, 2, 2);
2210 }
2211 }
2212 57 break;
2213 #endif /* CONFIG_ADPCM_SBPRO_x_DECODER */
2214 195 CASE(ADPCM_SWF,
2215 adpcm_swf_decode(avctx, buf, buf_size, samples);
2216 bytestream2_seek(&gb, 0, SEEK_END);
2217 ) /* End of CASE */
2218
2/2
✓ Branch 3 taken 552960 times.
✓ Branch 4 taken 136 times.
553096 CASE(ADPCM_YAMAHA,
2219 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2220 int v = bytestream2_get_byteu(&gb);
2221 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
2222 *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
2223 }
2224 ) /* End of CASE */
2225 CASE(ADPCM_AICA,
2226 for (int channel = 0; channel < channels; channel++) {
2227 samples = samples_p[channel];
2228 for (int n = nb_samples >> 1; n > 0; n--) {
2229 int v = bytestream2_get_byteu(&gb);
2230 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v & 0x0F);
2231 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v >> 4 );
2232 }
2233 }
2234 ) /* End of CASE */
2235
11/16
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 215040 times.
✓ Branch 8 taken 215040 times.
✓ Branch 10 taken 430080 times.
✓ Branch 11 taken 26880 times.
✓ Branch 12 taken 26880 times.
✓ Branch 13 taken 24 times.
✓ Branch 14 taken 24 times.
✓ Branch 15 taken 12 times.
✓ Branch 16 taken 12 times.
✓ Branch 17 taken 12 times.
457008 CASE(ADPCM_AFC,
2236 int samples_per_block;
2237 int blocks;
2238
2239 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
2240 samples_per_block = avctx->extradata[0] / 16;
2241 blocks = nb_samples / avctx->extradata[0];
2242 } else {
2243 samples_per_block = nb_samples / 16;
2244 blocks = 1;
2245 }
2246
2247 for (int m = 0; m < blocks; m++) {
2248 for (int channel = 0; channel < channels; channel++) {
2249 int prev1 = c->status[channel].sample1;
2250 int prev2 = c->status[channel].sample2;
2251
2252 samples = samples_p[channel] + m * 16;
2253 /* Read in every sample for this channel. */
2254 for (int i = 0; i < samples_per_block; i++) {
2255 int byte = bytestream2_get_byteu(&gb);
2256 int scale = 1 << (byte >> 4);
2257 int index = byte & 0xf;
2258 int factor1 = afc_coeffs[0][index];
2259 int factor2 = afc_coeffs[1][index];
2260
2261 /* Decode 16 samples. */
2262 for (int n = 0; n < 16; n++) {
2263 int32_t sampledat;
2264
2265 if (n & 1) {
2266 sampledat = sign_extend(byte, 4);
2267 } else {
2268 byte = bytestream2_get_byteu(&gb);
2269 sampledat = sign_extend(byte >> 4, 4);
2270 }
2271
2272 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2273 sampledat * scale;
2274 *samples = av_clip_int16(sampledat);
2275 prev2 = prev1;
2276 prev1 = *samples++;
2277 }
2278 }
2279
2280 c->status[channel].sample1 = prev1;
2281 c->status[channel].sample2 = prev2;
2282 }
2283 }
2284 bytestream2_seek(&gb, 0, SEEK_END);
2285 ) /* End of CASE */
2286 #if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2287 71 case AV_CODEC_ID_ADPCM_THP:
2288 case AV_CODEC_ID_ADPCM_THP_LE:
2289 {
2290 int table[14][16];
2291
2292 #define THP_GET16(g) \
2293 sign_extend( \
2294 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2295 bytestream2_get_le16u(&(g)) : \
2296 bytestream2_get_be16u(&(g)), 16)
2297
2298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (avctx->extradata) {
2299 GetByteContext tb;
2300 if (avctx->extradata_size < 32 * channels) {
2301 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
2302 return AVERROR_INVALIDDATA;
2303 }
2304
2305 bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
2306 for (int i = 0; i < channels; i++)
2307 for (int n = 0; n < 16; n++)
2308 table[i][n] = THP_GET16(tb);
2309 } else {
2310
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 71 times.
213 for (int i = 0; i < channels; i++)
2311
2/2
✓ Branch 0 taken 2272 times.
✓ Branch 1 taken 142 times.
2414 for (int n = 0; n < 16; n++)
2312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2272 times.
2272 table[i][n] = THP_GET16(gb);
2313
2314
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 70 times.
71 if (!c->has_status) {
2315 /* Initialize the previous sample. */
2316
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < channels; i++) {
2317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 c->status[i].sample1 = THP_GET16(gb);
2318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 c->status[i].sample2 = THP_GET16(gb);
2319 }
2320 1 c->has_status = 1;
2321 } else {
2322 70 bytestream2_skip(&gb, channels * 4);
2323 }
2324 }
2325
2326
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 71 times.
213 for (int ch = 0; ch < channels; ch++) {
2327 142 samples = samples_p[ch];
2328
2329 /* Read in every sample for this channel. */
2330
2/2
✓ Branch 0 taken 10840 times.
✓ Branch 1 taken 142 times.
10982 for (int i = 0; i < (nb_samples + 13) / 14; i++) {
2331 10840 int byte = bytestream2_get_byteu(&gb);
2332 10840 int index = (byte >> 4) & 7;
2333 10840 unsigned int exp = byte & 0x0F;
2334 10840 int64_t factor1 = table[ch][index * 2];
2335 10840 int64_t factor2 = table[ch][index * 2 + 1];
2336
2337 /* Decode 14 samples. */
2338
3/4
✓ Branch 0 taken 151760 times.
✓ Branch 1 taken 10840 times.
✓ Branch 2 taken 151760 times.
✗ Branch 3 not taken.
162600 for (int n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
2339 int32_t sampledat;
2340
2341
2/2
✓ Branch 0 taken 75880 times.
✓ Branch 1 taken 75880 times.
151760 if (n & 1) {
2342 75880 sampledat = sign_extend(byte, 4);
2343 } else {
2344 75880 byte = bytestream2_get_byteu(&gb);
2345 75880 sampledat = sign_extend(byte >> 4, 4);
2346 }
2347
2348 151760 sampledat = ((c->status[ch].sample1 * factor1
2349 151760 + c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 << exp);
2350 151760 *samples = av_clip_int16(sampledat);
2351 151760 c->status[ch].sample2 = c->status[ch].sample1;
2352 151760 c->status[ch].sample1 = *samples++;
2353 }
2354 }
2355 }
2356 71 break;
2357 }
2358 #endif /* CONFIG_ADPCM_THP(_LE)_DECODER */
2359
16/16
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 1024 times.
✓ Branch 5 taken 3388 times.
✓ Branch 6 taken 50876 times.
✓ Branch 7 taken 2744 times.
✓ Branch 8 taken 336 times.
✓ Branch 10 taken 28672 times.
✓ Branch 11 taken 28672 times.
✓ Branch 12 taken 57344 times.
✓ Branch 13 taken 2048 times.
✓ Branch 14 taken 2048 times.
✓ Branch 15 taken 64 times.
✓ Branch 16 taken 32 times.
✓ Branch 17 taken 32 times.
✓ Branch 19 taken 64 times.
✓ Branch 20 taken 32 times.
59488 CASE(ADPCM_DTK,
2360 for (int channel = 0; channel < channels; channel++) {
2361 samples = samples_p[channel];
2362
2363 /* Read in every sample for this channel. */
2364 for (int i = 0; i < nb_samples / 28; i++) {
2365 int byte, header;
2366 if (channel)
2367 bytestream2_skipu(&gb, 1);
2368 header = bytestream2_get_byteu(&gb);
2369 bytestream2_skipu(&gb, 3 - channel);
2370
2371 /* Decode 28 samples. */
2372 for (int n = 0; n < 28; n++) {
2373 int32_t sampledat, prev;
2374
2375 switch (header >> 4) {
2376 case 1:
2377 prev = (c->status[channel].sample1 * 0x3c);
2378 break;
2379 case 2:
2380 prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
2381 break;
2382 case 3:
2383 prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
2384 break;
2385 default:
2386 prev = 0;
2387 }
2388
2389 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
2390
2391 byte = bytestream2_get_byteu(&gb);
2392 if (!channel)
2393 sampledat = sign_extend(byte, 4);
2394 else
2395 sampledat = sign_extend(byte >> 4, 4);
2396
2397 sampledat = ((sampledat * (1 << 12)) >> (header & 0xf)) * (1 << 6) + prev;
2398 *samples++ = av_clip_int16(sampledat >> 6);
2399 c->status[channel].sample2 = c->status[channel].sample1;
2400 c->status[channel].sample1 = sampledat;
2401 }
2402 }
2403 if (!channel)
2404 bytestream2_seek(&gb, 0, SEEK_SET);
2405 }
2406 ) /* End of CASE */
2407 CASE(ADPCM_PSX,
2408 for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * channels); block++) {
2409 int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * channels) / (16 * channels);
2410 for (int channel = 0; channel < channels; channel++) {
2411 samples = samples_p[channel] + block * nb_samples_per_block;
2412 av_assert0((block + 1) * nb_samples_per_block <= nb_samples);
2413
2414 /* Read in every sample for this channel. */
2415 for (int i = 0; i < nb_samples_per_block / 28; i++) {
2416 int filter, shift, flag, byte;
2417
2418 filter = bytestream2_get_byteu(&gb);
2419 shift = filter & 0xf;
2420 filter = filter >> 4;
2421 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
2422 return AVERROR_INVALIDDATA;
2423 flag = bytestream2_get_byteu(&gb) & 0x7;
2424
2425 /* Decode 28 samples. */
2426 for (int n = 0; n < 28; n++) {
2427 int sample = 0, scale;
2428
2429 if (n & 1) {
2430 scale = sign_extend(byte >> 4, 4);
2431 } else {
2432 byte = bytestream2_get_byteu(&gb);
2433 scale = sign_extend(byte, 4);
2434 }
2435
2436 if (flag < 0x07) {
2437 scale = scale * (1 << 12);
2438 sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
2439 }
2440 *samples++ = av_clip_int16(sample);
2441 c->status[channel].sample2 = c->status[channel].sample1;
2442 c->status[channel].sample1 = sample;
2443 }
2444 }
2445 }
2446 }
2447 ) /* End of CASE */
2448 CASE(ADPCM_SANYO,
2449 int (*expand)(ADPCMChannelStatus *c, int bits);
2450 GetBitContext g;
2451
2452 switch(avctx->bits_per_coded_sample) {
2453 case 3: expand = adpcm_sanyo_expand3; break;
2454 case 4: expand = adpcm_sanyo_expand4; break;
2455 case 5: expand = adpcm_sanyo_expand5; break;
2456 }
2457
2458 for (int ch = 0; ch < channels; ch++) {
2459 c->status[ch].predictor = sign_extend(bytestream2_get_le16(&gb), 16);
2460 c->status[ch].step = sign_extend(bytestream2_get_le16(&gb), 16);
2461 }
2462
2463 init_get_bits8(&g, gb.buffer, bytestream2_get_bytes_left(&gb));
2464 for (int i = 0; i < nb_samples; i++)
2465 for (int ch = 0; ch < channels; ch++)
2466 samples_p[ch][i] = expand(&c->status[ch], get_bits_le(&g, avctx->bits_per_coded_sample));
2467
2468 align_get_bits(&g);
2469 bytestream2_skip(&gb, get_bits_count(&g) / 8);
2470 ) /* End of CASE */
2471
6/6
✓ Branch 4 taken 747296 times.
✓ Branch 5 taken 46706 times.
✓ Branch 6 taken 46706 times.
✓ Branch 7 taken 30245 times.
✓ Branch 8 taken 30245 times.
✓ Branch 9 taken 946 times.
825193 CASE(ADPCM_ARGO,
2472 /*
2473 * The format of each block:
2474 * uint8_t left_control;
2475 * uint4_t left_samples[nb_samples];
2476 * ---- and if stereo ----
2477 * uint8_t right_control;
2478 * uint4_t right_samples[nb_samples];
2479 *
2480 * Format of the control byte:
2481 * MSB [SSSSRDRR] LSB
2482 * S = (Shift Amount - 2)
2483 * D = Decoder flag.
2484 * R = Reserved
2485 *
2486 * Each block relies on the previous two samples of each channel.
2487 * They should be 0 initially.
2488 */
2489 for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
2490 for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
2491 ADPCMChannelStatus *cs = c->status + channel;
2492 int control, shift;
2493
2494 samples = samples_p[channel] + block * 32;
2495
2496 /* Get the control byte and decode the samples, 2 at a time. */
2497 control = bytestream2_get_byteu(&gb);
2498 shift = (control >> 4) + 2;
2499
2500 for (int n = 0; n < 16; n++) {
2501 int sample = bytestream2_get_byteu(&gb);
2502 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04);
2503 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04);
2504 }
2505 }
2506 }
2507 ) /* End of CASE */
2508 CASE(ADPCM_ZORK,
2509 for (int n = 0; n < nb_samples * channels; n++) {
2510 int v = bytestream2_get_byteu(&gb);
2511 *samples++ = adpcm_zork_expand_nibble(&c->status[n % channels], v);
2512 }
2513 ) /* End of CASE */
2514 CASE(ADPCM_IMA_MTF,
2515 for (int n = nb_samples / 2; n > 0; n--) {
2516 for (int channel = 0; channel < channels; channel++) {
2517 int v = bytestream2_get_byteu(&gb);
2518 *samples++ = adpcm_ima_mtf_expand_nibble(&c->status[channel], v >> 4);
2519 samples[st] = adpcm_ima_mtf_expand_nibble(&c->status[channel], v & 0x0F);
2520 }
2521 samples += channels;
2522 }
2523 ) /* End of CASE */
2524 default:
2525 av_unreachable("There are cases for all codec ids using adpcm_decode_frame");
2526 }
2527
2528
2/4
✓ Branch 0 taken 37706 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 37706 times.
37706 if (avpkt->size && bytestream2_tell(&gb) == 0) {
2529 av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
2530 return AVERROR_INVALIDDATA;
2531 }
2532
2533 37706 *got_frame_ptr = 1;
2534
2535
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37706 times.
37706 if (avpkt->size < bytestream2_tell(&gb)) {
2536 av_log(avctx, AV_LOG_ERROR, "Overread of %d < %d\n", avpkt->size, bytestream2_tell(&gb));
2537 return avpkt->size;
2538 }
2539
2540 37706 return bytestream2_tell(&gb);
2541 }
2542
2543 187 static void adpcm_flush(AVCodecContext *avctx)
2544 {
2545 187 ADPCMDecodeContext *c = avctx->priv_data;
2546
2547 /* Just nuke the entire state and re-init. */
2548 187 memset(c, 0, sizeof(ADPCMDecodeContext));
2549
2550
5/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 168 times.
187 switch(avctx->codec_id) {
2551 2 case AV_CODEC_ID_ADPCM_CT:
2552 2 c->status[0].step = c->status[1].step = 511;
2553 2 break;
2554
2555 3 case AV_CODEC_ID_ADPCM_IMA_APC:
2556
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
3 if (avctx->extradata && avctx->extradata_size >= 8) {
2557 2 c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata ), 18);
2558 2 c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18);
2559 }
2560 3 break;
2561
2562 6 case AV_CODEC_ID_ADPCM_IMA_APM:
2563
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (avctx->extradata && avctx->extradata_size >= 28) {
2564 6 c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 16), 18);
2565 6 c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 20), 0, 88);
2566 6 c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18);
2567 6 c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 8), 0, 88);
2568 }
2569 6 break;
2570
2571 8 case AV_CODEC_ID_ADPCM_IMA_WS:
2572
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
8 if (avctx->extradata && avctx->extradata_size >= 2)
2573 5 c->vqa_version = AV_RL16(avctx->extradata);
2574 8 break;
2575 168 default:
2576 /* Other codecs may want to handle this during decoding. */
2577 168 c->has_status = 0;
2578 168 return;
2579 }
2580
2581 19 c->has_status = 1;
2582 }
2583
2584
2585 static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
2586 AV_SAMPLE_FMT_NONE };
2587 static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16P,
2588 AV_SAMPLE_FMT_NONE };
2589 static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
2590 AV_SAMPLE_FMT_S16P,
2591 AV_SAMPLE_FMT_NONE };
2592
2593 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2594 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2595 const FFCodec ff_ ## name_ ## _decoder = { \
2596 .p.name = #name_, \
2597 CODEC_LONG_NAME(long_name_), \
2598 .p.type = AVMEDIA_TYPE_AUDIO, \
2599 .p.id = id_, \
2600 .p.capabilities = AV_CODEC_CAP_DR1, \
2601 CODEC_SAMPLEFMTS_ARRAY(sample_fmts_), \
2602 .priv_data_size = sizeof(ADPCMDecodeContext), \
2603 .init = adpcm_decode_init, \
2604 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2605 .flush = adpcm_flush, \
2606 };
2607 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2608 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2609 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2610 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2611 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2612 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2613 name, sample_fmts, long_name)
2614
2615 /* Note: Do not forget to add new entries to the Makefile as well. */
2616 ADPCM_DECODER(ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie")
2617 ADPCM_DECODER(ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC")
2618 ADPCM_DECODER(ADPCM_AGM, sample_fmts_s16, adpcm_agm, "ADPCM AmuseGraphics Movie")
2619 ADPCM_DECODER(ADPCM_AICA, sample_fmts_s16p, adpcm_aica, "ADPCM Yamaha AICA")
2620 ADPCM_DECODER(ADPCM_ARGO, sample_fmts_s16p, adpcm_argo, "ADPCM Argonaut Games")
2621 ADPCM_DECODER(ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology")
2622 ADPCM_DECODER(ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK")
2623 ADPCM_DECODER(ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts")
2624 ADPCM_DECODER(ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA")
2625 ADPCM_DECODER(ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1")
2626 ADPCM_DECODER(ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2")
2627 ADPCM_DECODER(ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3")
2628 ADPCM_DECODER(ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS")
2629 ADPCM_DECODER(ADPCM_IMA_ACORN, sample_fmts_s16, adpcm_ima_acorn, "ADPCM IMA Acorn Replay")
2630 ADPCM_DECODER(ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV")
2631 ADPCM_DECODER(ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC")
2632 ADPCM_DECODER(ADPCM_IMA_APM, sample_fmts_s16, adpcm_ima_apm, "ADPCM IMA Ubisoft APM")
2633 ADPCM_DECODER(ADPCM_IMA_CUNNING, sample_fmts_s16p, adpcm_ima_cunning, "ADPCM IMA Cunning Developments")
2634 ADPCM_DECODER(ADPCM_IMA_DAT4, sample_fmts_s16, adpcm_ima_dat4, "ADPCM IMA Eurocom DAT4")
2635 ADPCM_DECODER(ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3")
2636 ADPCM_DECODER(ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4")
2637 ADPCM_DECODER(ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS")
2638 ADPCM_DECODER(ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD")
2639 ADPCM_DECODER(ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS")
2640 ADPCM_DECODER(ADPCM_IMA_MOFLEX, sample_fmts_s16p, adpcm_ima_moflex, "ADPCM IMA MobiClip MOFLEX")
2641 ADPCM_DECODER(ADPCM_IMA_MTF, sample_fmts_s16, adpcm_ima_mtf, "ADPCM IMA Capcom's MT Framework")
2642 ADPCM_DECODER(ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI")
2643 ADPCM_DECODER(ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime")
2644 ADPCM_DECODER(ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical")
2645 ADPCM_DECODER(ADPCM_IMA_SSI, sample_fmts_s16, adpcm_ima_ssi, "ADPCM IMA Simon & Schuster Interactive")
2646 ADPCM_DECODER(ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG")
2647 ADPCM_DECODER(ADPCM_IMA_ALP, sample_fmts_s16, adpcm_ima_alp, "ADPCM IMA High Voltage Software ALP")
2648 ADPCM_DECODER(ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV")
2649 ADPCM_DECODER(ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood")
2650 ADPCM_DECODER(ADPCM_IMA_XBOX, sample_fmts_s16p, adpcm_ima_xbox, "ADPCM IMA Xbox")
2651 ADPCM_DECODER(ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft")
2652 ADPCM_DECODER(ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF")
2653 ADPCM_DECODER(ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation")
2654 ADPCM_DECODER(ADPCM_SANYO, sample_fmts_s16p, adpcm_sanyo, "ADPCM Sanyo")
2655 ADPCM_DECODER(ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit")
2656 ADPCM_DECODER(ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit")
2657 ADPCM_DECODER(ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit")
2658 ADPCM_DECODER(ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash")
2659 ADPCM_DECODER(ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)")
2660 ADPCM_DECODER(ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP")
2661 ADPCM_DECODER(ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA")
2662 ADPCM_DECODER(ADPCM_XMD, sample_fmts_s16p, adpcm_xmd, "ADPCM Konami XMD")
2663 ADPCM_DECODER(ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha")
2664 ADPCM_DECODER(ADPCM_ZORK, sample_fmts_s16, adpcm_zork, "ADPCM Zork")
2665