|
|
@ -808,6 +808,32 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, |
|
|
|
return (short)c->predictor; |
|
|
|
return (short)c->predictor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int step_index; |
|
|
|
|
|
|
|
int predictor; |
|
|
|
|
|
|
|
int diff, step; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
step = step_table[c->step_index]; |
|
|
|
|
|
|
|
step_index = c->step_index + index_table[nibble]; |
|
|
|
|
|
|
|
step_index = av_clip(step_index, 0, 88); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diff = step >> 3; |
|
|
|
|
|
|
|
if (nibble & 4) diff += step; |
|
|
|
|
|
|
|
if (nibble & 2) diff += step >> 1; |
|
|
|
|
|
|
|
if (nibble & 1) diff += step >> 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nibble & 8) |
|
|
|
|
|
|
|
predictor = c->predictor - diff; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
predictor = c->predictor + diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c->predictor = av_clip_int16(predictor); |
|
|
|
|
|
|
|
c->step_index = step_index; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return c->predictor; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) |
|
|
|
static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int predictor; |
|
|
|
int predictor; |
|
|
@ -1010,35 +1036,41 @@ static int adpcm_decode_frame(AVCodecContext *avctx, |
|
|
|
case CODEC_ID_ADPCM_IMA_QT: |
|
|
|
case CODEC_ID_ADPCM_IMA_QT: |
|
|
|
n = buf_size - 2*avctx->channels; |
|
|
|
n = buf_size - 2*avctx->channels; |
|
|
|
for (channel = 0; channel < avctx->channels; channel++) { |
|
|
|
for (channel = 0; channel < avctx->channels; channel++) { |
|
|
|
|
|
|
|
int16_t predictor; |
|
|
|
|
|
|
|
int step_index; |
|
|
|
cs = &(c->status[channel]); |
|
|
|
cs = &(c->status[channel]); |
|
|
|
/* (pppppp) (piiiiiii) */ |
|
|
|
/* (pppppp) (piiiiiii) */ |
|
|
|
|
|
|
|
|
|
|
|
/* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ |
|
|
|
/* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ |
|
|
|
cs->predictor = (*src++) << 8; |
|
|
|
predictor = AV_RB16(src); |
|
|
|
cs->predictor |= (*src & 0x80); |
|
|
|
step_index = predictor & 0x7F; |
|
|
|
cs->predictor &= 0xFF80; |
|
|
|
predictor &= 0xFF80; |
|
|
|
|
|
|
|
|
|
|
|
/* sign extension */ |
|
|
|
src += 2; |
|
|
|
if(cs->predictor & 0x8000) |
|
|
|
|
|
|
|
cs->predictor -= 0x10000; |
|
|
|
if (cs->step_index == step_index) { |
|
|
|
|
|
|
|
int diff = (int)predictor - cs->predictor; |
|
|
|
cs->predictor = av_clip_int16(cs->predictor); |
|
|
|
if (diff < 0) |
|
|
|
|
|
|
|
diff = - diff; |
|
|
|
cs->step_index = (*src++) & 0x7F; |
|
|
|
if (diff > 0x7f) |
|
|
|
|
|
|
|
goto update; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
update: |
|
|
|
|
|
|
|
cs->step_index = step_index; |
|
|
|
|
|
|
|
cs->predictor = predictor; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cs->step_index > 88){ |
|
|
|
if (cs->step_index > 88){ |
|
|
|
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); |
|
|
|
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); |
|
|
|
cs->step_index = 88; |
|
|
|
cs->step_index = 88; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cs->step = step_table[cs->step_index]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
samples = (short*)data + channel; |
|
|
|
samples = (short*)data + channel; |
|
|
|
|
|
|
|
|
|
|
|
for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */ |
|
|
|
for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */ |
|
|
|
*samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3); |
|
|
|
*samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3); |
|
|
|
samples += avctx->channels; |
|
|
|
samples += avctx->channels; |
|
|
|
*samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3); |
|
|
|
*samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4 , 3); |
|
|
|
samples += avctx->channels; |
|
|
|
samples += avctx->channels; |
|
|
|
src ++; |
|
|
|
src ++; |
|
|
|
} |
|
|
|
} |
|
|
|