Mercurial > libavcodec.hg
comparison adpcm.c @ 4800:d6b2ddac2c5e libavcodec
THP PCM decoder, used on the Nintendo GameCube.
patch by Marco Gerards, mgerards xs4all nl
author | diego |
---|---|
date | Sat, 07 Apr 2007 16:03:23 +0000 |
parents | 3c6c557aa977 |
children | 39975b6c49bb |
comparison
equal
deleted
inserted
replaced
4799:812f759a7c59 | 4800:d6b2ddac2c5e |
---|---|
27 * First version by Francois Revol (revol@free.fr) | 27 * First version by Francois Revol (revol@free.fr) |
28 * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) | 28 * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) |
29 * by Mike Melanson (melanson@pcisys.net) | 29 * by Mike Melanson (melanson@pcisys.net) |
30 * CD-ROM XA ADPCM codec by BERO | 30 * CD-ROM XA ADPCM codec by BERO |
31 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) | 31 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) |
32 * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) | |
32 * | 33 * |
33 * Features and limitations: | 34 * Features and limitations: |
34 * | 35 * |
35 * Reference documents: | 36 * Reference documents: |
36 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html | 37 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html |
1306 (src[0] >> 4) & 0x0F); | 1307 (src[0] >> 4) & 0x0F); |
1307 } | 1308 } |
1308 src++; | 1309 src++; |
1309 } | 1310 } |
1310 break; | 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 default: | 1378 default: |
1312 return -1; | 1379 return -1; |
1313 } | 1380 } |
1314 *data_size = (uint8_t *)samples - (uint8_t *)data; | 1381 *data_size = (uint8_t *)samples - (uint8_t *)data; |
1315 return src - buf; | 1382 return src - buf; |
1366 ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); | 1433 ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); |
1367 ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); | 1434 ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); |
1368 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); | 1435 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); |
1369 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); | 1436 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); |
1370 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); | 1437 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); |
1438 ADPCM_CODEC(CODEC_ID_ADPCM_THP, adpcm_thp); | |
1371 | 1439 |
1372 #undef ADPCM_CODEC | 1440 #undef ADPCM_CODEC |