Revision d1e0d21f libavcodec/adpcm.c
libavcodec/adpcm.c | ||
---|---|---|
29 | 29 |
* by Mike Melanson (melanson@pcisys.net) |
30 | 30 |
* CD-ROM XA ADPCM codec by BERO |
31 | 31 |
* EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) |
32 |
* THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) |
|
32 | 33 |
* |
33 | 34 |
* Features and limitations: |
34 | 35 |
* |
... | ... | |
1308 | 1309 |
src++; |
1309 | 1310 |
} |
1310 | 1311 |
break; |
1312 |
case CODEC_ID_ADPCM_THP: |
|
1313 |
{ |
|
1314 |
GetBitContext gb; |
|
1315 |
int table[16][2]; |
|
1316 |
unsigned int samplecnt; |
|
1317 |
int prev1[2], prev2[2]; |
|
1318 |
int ch; |
|
1319 |
|
|
1320 |
if (buf_size < 80) { |
|
1321 |
av_log(avctx, AV_LOG_ERROR, "frame too small\n"); |
|
1322 |
return -1; |
|
1323 |
} |
|
1324 |
|
|
1325 |
init_get_bits(&gb, src, buf_size * 8); |
|
1326 |
src += buf_size; |
|
1327 |
|
|
1328 |
get_bits_long(&gb, 32); /* Channel size */ |
|
1329 |
samplecnt = get_bits_long(&gb, 32); |
|
1330 |
|
|
1331 |
for (ch = 0; ch < 2; ch++) |
|
1332 |
for (i = 0; i < 16; i++) |
|
1333 |
table[i][ch] = get_sbits(&gb, 16); |
|
1334 |
|
|
1335 |
/* Initialize the previous sample. */ |
|
1336 |
for (ch = 0; ch < 2; ch++) { |
|
1337 |
prev1[ch] = get_sbits(&gb, 16); |
|
1338 |
prev2[ch] = get_sbits(&gb, 16); |
|
1339 |
} |
|
1340 |
|
|
1341 |
if (samplecnt >= (samples_end - samples) / (st + 1)) { |
|
1342 |
av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); |
|
1343 |
return -1; |
|
1344 |
} |
|
1345 |
|
|
1346 |
for (ch = 0; ch <= st; ch++) { |
|
1347 |
samples = (unsigned short *) data + ch; |
|
1348 |
|
|
1349 |
/* Read in every sample for this channel. */ |
|
1350 |
for (i = 0; i < samplecnt / 14; i++) { |
|
1351 |
uint8_t index = get_bits (&gb, 4) & 7; |
|
1352 |
unsigned int exp = get_bits (&gb, 4); |
|
1353 |
int factor1 = table[index * 2][ch]; |
|
1354 |
int factor2 = table[index * 2 + 1][ch]; |
|
1355 |
|
|
1356 |
/* Decode 14 samples. */ |
|
1357 |
for (n = 0; n < 14; n++) { |
|
1358 |
int sampledat = get_sbits (&gb, 4); |
|
1359 |
|
|
1360 |
*samples = ((prev1[ch]*factor1 |
|
1361 |
+ prev2[ch]*factor2) >> 11) + (sampledat << exp); |
|
1362 |
prev2[ch] = prev1[ch]; |
|
1363 |
prev1[ch] = *samples++; |
|
1364 |
|
|
1365 |
/* In case of stereo, skip one sample, this sample |
|
1366 |
is for the other channel. */ |
|
1367 |
samples += st; |
|
1368 |
} |
|
1369 |
} |
|
1370 |
} |
|
1371 |
|
|
1372 |
/* In the previous loop, in case stereo is used, samples is |
|
1373 |
increased exactly one time too often. */ |
|
1374 |
samples -= st; |
|
1375 |
break; |
|
1376 |
} |
|
1377 |
|
|
1311 | 1378 |
default: |
1312 | 1379 |
return -1; |
1313 | 1380 |
} |
... | ... | |
1368 | 1435 |
ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); |
1369 | 1436 |
ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); |
1370 | 1437 |
ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); |
1438 |
ADPCM_CODEC(CODEC_ID_ADPCM_THP, adpcm_thp); |
|
1371 | 1439 |
|
1372 | 1440 |
#undef ADPCM_CODEC |
Also available in: Unified diff