diff options
author | melanson <melanson@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-03-30 22:27:45 +0000 |
---|---|---|
committer | melanson <melanson@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-03-30 22:27:45 +0000 |
commit | a9803b9f75c07b97c597cca6223e29887a75b759 (patch) | |
tree | 2f0f9d2b085ce8402512fcf422d989715bcd8df8 /adpcm.c | |
parent | 73309be6c854414cecdcfbb8110926ed45b4af52 (diff) |
reworked ADPCM decoders; changes include:
* fixed MS IMA ADPCM
* dissolved adpcm.c/.h into appropriate ad_* decoders
* DK4 audio is handled directly by IMA ADPCM decoder (this obsoletes
ad_dk4adpcm.c)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@5409 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'adpcm.c')
-rw-r--r-- | adpcm.c | 66 |
1 files changed, 65 insertions, 1 deletions
@@ -9,6 +9,7 @@ (C) 2001 Mike Melanson */ +#if 0 #include "config.h" #include "bswap.h" #include "adpcm.h" @@ -119,7 +120,7 @@ void decode_nibbles(unsigned short *output, } } -int ima_adpcm_decode_block(unsigned short *output, unsigned char *input, +int qt_ima_adpcm_decode_block(unsigned short *output, unsigned char *input, int channels) { int initial_predictor_l = 0; @@ -180,6 +181,67 @@ int ima_adpcm_decode_block(unsigned short *output, unsigned char *input, return IMA_ADPCM_SAMPLES_PER_BLOCK * channels; } +int ms_ima_adpcm_decode_block(unsigned short *output, unsigned char *input, + int channels, int block_size) +{ + int initial_predictor_l = 0; + int initial_predictor_r = 0; + int initial_index_l = 0; + int initial_index_r = 0; + int i; + + initial_predictor_l = BE_16(&input[0]); + initial_index_l = initial_predictor_l; + + // mask, sign-extend, and clamp the predictor portion + initial_predictor_l &= 0xFF80; + SE_16BIT(initial_predictor_l); + CLAMP_S16(initial_predictor_l); + + // mask and clamp the index portion + initial_index_l &= 0x7F; + CLAMP_0_TO_88(initial_index_l); + + // handle stereo + if (channels > 1) + { + initial_predictor_r = BE_16(&input[IMA_ADPCM_BLOCK_SIZE]); + initial_index_r = initial_predictor_r; + + // mask, sign-extend, and clamp the predictor portion + initial_predictor_r &= 0xFF80; + SE_16BIT(initial_predictor_r); + CLAMP_S16(initial_predictor_r); + + // mask and clamp the index portion + initial_index_r &= 0x7F; + CLAMP_0_TO_88(initial_index_r); + } + + // break apart all of the nibbles in the block + if (channels == 1) + for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++) + { + output[i * 2 + 0] = input[2 + i] & 0x0F; + output[i * 2 + 1] = input[2 + i] >> 4; + } + else + for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++) + { + output[i * 4 + 0] = input[2 + i] & 0x0F; + output[i * 4 + 1] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] & 0x0F; + output[i * 4 + 2] = input[2 + i] >> 4; + output[i * 4 + 3] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] >> 4; + } + + decode_nibbles(output, + IMA_ADPCM_SAMPLES_PER_BLOCK * channels, channels, + initial_predictor_l, initial_index_l, + initial_predictor_r, initial_index_r); + + return IMA_ADPCM_SAMPLES_PER_BLOCK * channels; +} + int ms_adpcm_decode_block(unsigned short *output, unsigned char *input, int channels, int block_size) { @@ -439,3 +501,5 @@ int dk3_adpcm_decode_block(unsigned short *output, unsigned char *input) return out_ptr; } +#endif + |