*/
#include "avcodec.h"
#include "bitstream.h"
+#include "bytestream.h"
/**
* @file adpcm.c
case CODEC_ID_ADPCM_CT:
c->status[0].step = c->status[1].step = 511;
break;
+ case CODEC_ID_ADPCM_IMA_WS:
+ if (avctx->extradata && avctx->extradata_size == 2 * 4) {
+ c->status[0].predictor = AV_RL32(avctx->extradata);
+ c->status[1].predictor = AV_RL32(avctx->extradata + 4);
+ }
+ break;
default:
break;
}
}
break;
case CODEC_ID_ADPCM_THP:
- {
- GetBitContext gb;
+ {
int table[2][16];
unsigned int samplecnt;
- int prev1[2], prev2[2];
+ int prev[2][2];
int ch;
if (buf_size < 80) {
return -1;
}
- init_get_bits(&gb, src, buf_size * 8);
- src += buf_size;
-
- get_bits_long(&gb, 32); /* Channel size */
- samplecnt = get_bits_long(&gb, 32);
+ src+=4;
+ samplecnt = bytestream_get_be32(&src);
- for (ch = 0; ch < 2; ch++)
- for (i = 0; i < 16; i++)
- table[ch][i] = get_sbits(&gb, 16);
+ for (i = 0; i < 32; i++)
+ table[0][i] = (int16_t)bytestream_get_be16(&src);
/* Initialize the previous sample. */
- for (ch = 0; ch < 2; ch++) {
- prev1[ch] = get_sbits(&gb, 16);
- prev2[ch] = get_sbits(&gb, 16);
- }
+ for (i = 0; i < 4; i++)
+ prev[0][i] = (int16_t)bytestream_get_be16(&src);
if (samplecnt >= (samples_end - samples) / (st + 1)) {
av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
/* Read in every sample for this channel. */
for (i = 0; i < samplecnt / 14; i++) {
- int index = get_bits (&gb, 4) & 7;
- unsigned int exp = get_bits (&gb, 4);
+ int index = (*src >> 4) & 7;
+ unsigned int exp = 28 - (*src++ & 15);
int factor1 = table[ch][index * 2];
int factor2 = table[ch][index * 2 + 1];
/* Decode 14 samples. */
for (n = 0; n < 14; n++) {
- int sampledat = get_sbits (&gb, 4);
+ int32_t sampledat;
+ if(n&1) sampledat= *src++ <<28;
+ else sampledat= (*src&0xF0)<<24;
- *samples = ((prev1[ch]*factor1
- + prev2[ch]*factor2) >> 11) + (sampledat << exp);
- prev2[ch] = prev1[ch];
- prev1[ch] = *samples++;
+ sampledat = ((prev[ch][0]*factor1
+ + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
+ CLAMP_TO_SHORT(sampledat);
+ *samples = sampledat;
+ prev[ch][1] = prev[ch][0];
+ prev[ch][0] = *samples++;
/* In case of stereo, skip one sample, this sample
is for the other channel. */
increased exactly one time too often. */
samples -= st;
break;
- }
+ }
default:
return -1;