X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fadpcm.c;h=d7f76e80a9b883cc926db3211f7a565bed6742a1;hb=9f4aa353599b0c12c7364fd9fe80132da96f3eb7;hp=2329f9af89c992855a4d81676783a961bf510351;hpb=1218a7e33d347138177363fa55da2ad830f6981c;p=ffmpeg diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 2329f9af89c..d7f76e80a9b 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -30,6 +30,11 @@ * by Mike Melanson (melanson@pcisys.net) * CD-ROM XA ADPCM codec by BERO * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) + * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org) + * EA IMA EACS decoder by Peter Ross (pross@xvid.org) + * EA IMA SEAD decoder by Peter Ross (pross@xvid.org) + * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org) + * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com) * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) * * Features and limitations: @@ -143,9 +148,7 @@ typedef struct ADPCMChannelStatus { } ADPCMChannelStatus; typedef struct ADPCMContext { - int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */ - ADPCMChannelStatus status[2]; - short sample_buffer[32]; /* hold left samples while waiting for right samples */ + ADPCMChannelStatus status[6]; } ADPCMContext; /* XXX: implement encoding */ @@ -156,17 +159,16 @@ static int adpcm_encode_init(AVCodecContext *avctx) if (avctx->channels > 2) return -1; /* only stereo or mono =) */ switch(avctx->codec->id) { - case CODEC_ID_ADPCM_IMA_QT: - av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n"); - avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */ - return -1; - break; case CODEC_ID_ADPCM_IMA_WAV: avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */ /* and we have 4 bytes per channel overhead */ avctx->block_align = BLKSIZE; /* seems frame_size isn't taken into account... have to buffer the samples :-( */ break; + case CODEC_ID_ADPCM_IMA_QT: + avctx->frame_size = 64; + avctx->block_align = 34 * avctx->channels; + break; case CODEC_ID_ADPCM_MS: avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */ /* and we have 7 bytes per channel overhead */ @@ -297,7 +299,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, nodes[0]->step = c->step_index; nodes[0]->sample1 = c->sample1; nodes[0]->sample2 = c->sample2; - if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF)) + if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF)) nodes[0]->sample1 = c->prev_sample; if(version == CODEC_ID_ADPCM_MS) nodes[0]->step = c->idelta; @@ -368,7 +370,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, next_##NAME:; STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8)); } - } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_SWF)) { + } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) { #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ const int predictor = nodes[j]->sample1;\ const int div = (sample - predictor) * 4 / STEP_TABLE;\ @@ -444,8 +446,6 @@ static int adpcm_encode_frame(AVCodecContext *avctx, /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ switch(avctx->codec->id) { - case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */ - break; case CODEC_ID_ADPCM_IMA_WAV: n = avctx->frame_size / 8; c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ @@ -455,7 +455,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, *dst++ = 0; /* unknown */ samples++; if (avctx->channels == 2) { - c->status[1].prev_sample = (signed short)samples[1]; + c->status[1].prev_sample = (signed short)samples[0]; /* c->status[1].step_index = 0; */ bytestream_put_le16(&dst, c->status[1].prev_sample); *dst++ = (unsigned char)c->status[1].step_index; @@ -483,17 +483,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, } } else for (; n>0; n--) { - *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4; dst++; /* right channel */ if (avctx->channels == 2) { @@ -513,6 +513,36 @@ static int adpcm_encode_frame(AVCodecContext *avctx, samples += 8 * avctx->channels; } break; + case CODEC_ID_ADPCM_IMA_QT: + { + int ch, i; + PutBitContext pb; + init_put_bits(&pb, dst, buf_size*8); + + for(ch=0; chchannels; ch++){ + put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7); + put_bits(&pb, 7, c->status[ch].step_index); + if(avctx->trellis > 0) { + uint8_t buf[64]; + adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64); + for(i=0; i<64; i++) + put_bits(&pb, 4, buf[i^1]); + c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F; + } else { + for (i=0; i<64; i+=2){ + int t1, t2; + t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]); + t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]); + put_bits(&pb, 4, t2); + put_bits(&pb, 4, t1); + } + c->status[ch].prev_sample &= ~0x7F; + } + } + + dst += put_bits_count(&pb)>>3; + break; + } case CODEC_ID_ADPCM_SWF: { int i; @@ -544,9 +574,9 @@ static int adpcm_encode_frame(AVCodecContext *avctx, } } else { for (i=1; iframe_size; i++) { - put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]) & 0xF); + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i])); if (avctx->channels == 2) - put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]) & 0xF); + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1])); } } flush_put_bits(&pb); @@ -633,19 +663,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, } #endif //CONFIG_ENCODERS -static int adpcm_decode_init(AVCodecContext * avctx) +static av_cold int adpcm_decode_init(AVCodecContext * avctx) { ADPCMContext *c = avctx->priv_data; + unsigned int max_channels = 2; - if(avctx->channels > 2U){ + switch(avctx->codec->id) { + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: + max_channels = 6; + break; + } + if(avctx->channels > max_channels){ return -1; } - c->channel = 0; - c->status[0].predictor = c->status[1].predictor = 0; - c->status[0].step_index = c->status[1].step_index = 0; - c->status[0].step = c->status[1].step = 0; - switch(avctx->codec->id) { case CODEC_ID_ADPCM_CT: c->status[0].step = c->status[1].step = 511; @@ -829,7 +862,7 @@ static void xa_decode(short *out, const unsigned char *in, #define DK3_GET_NEXT_NIBBLE() \ if (decode_top_nibble_next) \ { \ - nibble = (last_byte >> 4) & 0x0F; \ + nibble = last_byte >> 4; \ decode_top_nibble_next = 0; \ } \ else \ @@ -842,7 +875,7 @@ static void xa_decode(short *out, const unsigned char *in, static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { ADPCMContext *c = avctx->priv_data; ADPCMChannelStatus *cs; @@ -850,7 +883,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, int block_predictor[2]; short *samples; short *samples_end; - uint8_t *src; + const uint8_t *src; int st; /* stereo */ /* DK3 ADPCM accounting variables */ @@ -867,6 +900,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, int32_t coeff1l, coeff2l, coeff1r, coeff2r; uint8_t shift_left, shift_right; int count1, count2; + int coeff[2][2], shift[2];//used in EA MAXIS ADPCM if (!buf_size) return 0; @@ -886,48 +920,43 @@ static int adpcm_decode_frame(AVCodecContext *avctx, switch(avctx->codec->id) { case CODEC_ID_ADPCM_IMA_QT: - n = (buf_size - 2);/* >> 2*avctx->channels;*/ - channel = c->channel; - cs = &(c->status[channel]); - /* (pppppp) (piiiiiii) */ + n = buf_size - 2*avctx->channels; + for (channel = 0; channel < avctx->channels; channel++) { + cs = &(c->status[channel]); + /* (pppppp) (piiiiiii) */ - /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ - cs->predictor = (*src++) << 8; - cs->predictor |= (*src & 0x80); - cs->predictor &= 0xFF80; + /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ + cs->predictor = (*src++) << 8; + cs->predictor |= (*src & 0x80); + cs->predictor &= 0xFF80; - /* sign extension */ - if(cs->predictor & 0x8000) - cs->predictor -= 0x10000; + /* sign extension */ + if(cs->predictor & 0x8000) + cs->predictor -= 0x10000; - cs->predictor = av_clip_int16(cs->predictor); + cs->predictor = av_clip_int16(cs->predictor); - cs->step_index = (*src++) & 0x7F; + cs->step_index = (*src++) & 0x7F; - if (cs->step_index > 88){ - av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); - cs->step_index = 88; - } + if (cs->step_index > 88){ + av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); + cs->step_index = 88; + } - cs->step = step_table[cs->step_index]; + cs->step = step_table[cs->step_index]; - if (st && channel) - samples++; + 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) */ - *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3); - samples += avctx->channels; - *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3); - samples += avctx->channels; - src ++; - } - - if(st) { /* handle stereo interlacing */ - c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */ - if(channel == 1) { /* wait for the other packet before outputing anything */ - return src - buf; + 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 += avctx->channels; + *samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3); + samples += avctx->channels; + src ++; } } + if (st) + samples--; break; case CODEC_ID_ADPCM_IMA_WAV: if (avctx->block_align != 0 && buf_size > avctx->block_align) @@ -937,11 +966,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, for(i=0; ichannels; i++){ cs = &(c->status[i]); - cs->predictor = (int16_t)(src[0] + (src[1]<<8)); + cs->predictor = *samples++ = (int16_t)(src[0] + (src[1]<<8)); src+=2; - // XXX: is this correct ??: *samples++ = cs->predictor; - cs->step_index = *src++; if (cs->step_index > 88){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); @@ -1022,7 +1049,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, *samples++ = c->status[0].sample2; if (st) *samples++ = c->status[1].sample2; for(;n>0;n--) { - *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); + *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 ); *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F); src ++; } @@ -1045,7 +1072,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, /* take care of the top nibble (always left or mono channel) */ *samples++ = adpcm_ima_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F, 3); + src[0] >> 4, 3); /* take care of the bottom nibble, which is right sample for * stereo, or another mono sample */ @@ -1110,12 +1137,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, if (st) { *samples++ = adpcm_ima_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F, 3); + src[0] >> 4 , 3); *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[0] & 0x0F, 3); } else { *samples++ = adpcm_ima_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F, 3); + src[0] >> 4 , 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3); } @@ -1124,8 +1151,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, } break; case CODEC_ID_ADPCM_XA: - c->status[0].sample1 = c->status[0].sample2 = - c->status[1].sample1 = c->status[1].sample2 = 0; while (buf_size >= 128) { xa_decode(samples, src, &c->status[0], &c->status[1], avctx->channels); @@ -1134,6 +1159,30 @@ static int adpcm_decode_frame(AVCodecContext *avctx, buf_size -= 128; } break; + case CODEC_ID_ADPCM_IMA_EA_EACS: + samples_in_chunk = bytestream_get_le32(&src) >> (1-st); + + if (samples_in_chunk > buf_size-4-(8<status[i].step_index = bytestream_get_le32(&src); + for (i=0; i<=st; i++) + c->status[i].predictor = bytestream_get_le32(&src); + + for (; samples_in_chunk; samples_in_chunk--, src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3); + *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3); + } + break; + case CODEC_ID_ADPCM_IMA_EA_SEAD: + for (; src < buf+buf_size; src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6); + *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6); + } + break; case CODEC_ID_ADPCM_EA: samples_in_chunk = AV_RL32(src); if (samples_in_chunk >= ((buf_size - 12) * 2)) { @@ -1151,19 +1200,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, src += 2; for (count1 = 0; count1 < samples_in_chunk/28;count1++) { - coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F]; - coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4]; + coeff1l = ea_adpcm_table[ *src >> 4 ]; + coeff2l = ea_adpcm_table[(*src >> 4 ) + 4]; coeff1r = ea_adpcm_table[*src & 0x0F]; coeff2r = ea_adpcm_table[(*src & 0x0F) + 4]; src++; - shift_left = ((*src >> 4) & 0x0F) + 8; + shift_left = (*src >> 4 ) + 8; shift_right = (*src & 0x0F) + 8; src++; for (count2 = 0; count2 < 28; count2++) { - next_left_sample = (((*src & 0xF0) << 24) >> shift_left); - next_right_sample = (((*src & 0x0F) << 28) >> shift_right); + next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left; + next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right; src++; next_left_sample = (next_left_sample + @@ -1182,16 +1231,159 @@ static int adpcm_decode_frame(AVCodecContext *avctx, } } break; + case CODEC_ID_ADPCM_EA_MAXIS_XA: + for(channel = 0; channel < avctx->channels; channel++) { + for (i=0; i<2; i++) + coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i]; + shift[channel] = (*src & 0x0F) + 8; + src++; + } + for (count1 = 0; count1 < (buf_size - avctx->channels) / avctx->channels; count1++) { + for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */ + for(channel = 0; channel < avctx->channels; channel++) { + int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel]; + sample = (sample + + c->status[channel].sample1 * coeff[channel][0] + + c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8; + c->status[channel].sample2 = c->status[channel].sample1; + c->status[channel].sample1 = av_clip_int16(sample); + *samples++ = c->status[channel].sample1; + } + } + src+=avctx->channels; + } + break; + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: { + /* channel numbering + 2chan: 0=fl, 1=fr + 4chan: 0=fl, 1=rl, 2=fr, 3=rr + 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */ + const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3; + int32_t previous_sample, current_sample, next_sample; + int32_t coeff1, coeff2; + uint8_t shift; + unsigned int channel; + uint16_t *samplesC; + const uint8_t *srcC; + + samples_in_chunk = (big_endian ? bytestream_get_be32(&src) + : bytestream_get_le32(&src)) / 28; + if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) || + 28*samples_in_chunk*avctx->channels > samples_end-samples) { + src += buf_size - 4; + break; + } + + for (channel=0; channelchannels; channel++) { + srcC = src + (big_endian ? bytestream_get_be32(&src) + : bytestream_get_le32(&src)) + + (avctx->channels-channel-1) * 4; + samplesC = samples + channel; + + if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) { + current_sample = (int16_t)bytestream_get_le16(&srcC); + previous_sample = (int16_t)bytestream_get_le16(&srcC); + } else { + current_sample = c->status[channel].predictor; + previous_sample = c->status[channel].prev_sample; + } + + for (count1=0; count1channels; + } + } else { + coeff1 = ea_adpcm_table[ *srcC>>4 ]; + coeff2 = ea_adpcm_table[(*srcC>>4) + 4]; + shift = (*srcC++ & 0x0F) + 8; + + for (count2=0; count2<28; count2++) { + if (count2 & 1) + next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift; + else + next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift; + + next_sample += (current_sample * coeff1) + + (previous_sample * coeff2); + next_sample = av_clip_int16(next_sample >> 8); + + previous_sample = current_sample; + current_sample = next_sample; + *samplesC = current_sample; + samplesC += avctx->channels; + } + } + } + + if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) { + c->status[channel].predictor = current_sample; + c->status[channel].prev_sample = previous_sample; + } + } + + src = src + buf_size - (4 + 4*avctx->channels); + samples += 28 * samples_in_chunk * avctx->channels; + break; + } + case CODEC_ID_ADPCM_EA_XAS: + if (samples_end-samples < 32*4*avctx->channels + || buf_size < (4+15)*4*avctx->channels) { + src += buf_size; + break; + } + for (channel=0; channelchannels; channel++) { + int coeff[2][4], shift[4]; + short *s2, *s = &samples[channel]; + for (n=0; n<4; n++, s+=32*avctx->channels) { + for (i=0; i<2; i++) + coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i]; + shift[n] = (src[2]&0x0F) + 8; + for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels) + s2[0] = (src[0]&0xF0) + (src[1]<<8); + } + + for (m=2; m<32; m+=2) { + s = &samples[m*avctx->channels + channel]; + for (n=0; n<4; n++, src++, s+=32*avctx->channels) { + for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) { + int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n]; + int pred = s2[-1*avctx->channels] * coeff[0][n] + + s2[-2*avctx->channels] * coeff[1][n]; + s2[0] = av_clip_int16((level + pred + 0x80) >> 8); + } + } + } + } + samples += 32*4*avctx->channels; + break; + case CODEC_ID_ADPCM_IMA_AMV: case CODEC_ID_ADPCM_IMA_SMJPEG: - c->status[0].predictor = *src; - src += 2; - c->status[0].step_index = *src++; - src++; /* skip another byte before getting to the meat */ + c->status[0].predictor = (int16_t)bytestream_get_le16(&src); + c->status[0].step_index = bytestream_get_le16(&src); + + if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) + src+=4; + while (src < buf + buf_size) { + char hi, lo; + lo = *src & 0x0F; + hi = *src >> 4; + + if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) + FFSWAP(char, hi, lo); + *samples++ = adpcm_ima_expand_nibble(&c->status[0], - *src & 0x0F, 3); + lo, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], - (*src >> 4) & 0x0F, 3); + hi, 3); src++; } break; @@ -1199,12 +1391,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, while (src < buf + buf_size) { if (st) { *samples++ = adpcm_ct_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F); + src[0] >> 4); *samples++ = adpcm_ct_expand_nibble(&c->status[1], src[0] & 0x0F); } else { *samples++ = adpcm_ct_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F); + src[0] >> 4); *samples++ = adpcm_ct_expand_nibble(&c->status[0], src[0] & 0x0F); } @@ -1224,7 +1416,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) { while (src < buf + buf_size) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F, 4, 0); + src[0] >> 4, 4, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], src[0] & 0x0F, 4, 0); src++; @@ -1232,7 +1424,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) { while (src < buf + buf_size && samples + 2 < samples_end) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], - (src[0] >> 5) & 0x07, 3, 0); + src[0] >> 5 , 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (src[0] >> 2) & 0x07, 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], @@ -1242,7 +1434,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, } else { while (src < buf + buf_size && samples + 3 < samples_end) { *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], - (src[0] >> 6) & 0x03, 2, 2); + src[0] >> 6 , 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], (src[0] >> 4) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], @@ -1320,12 +1512,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], src[0] & 0x0F); *samples++ = adpcm_yamaha_expand_nibble(&c->status[1], - (src[0] >> 4) & 0x0F); + src[0] >> 4 ); } else { *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], src[0] & 0x0F); *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], - (src[0] >> 4) & 0x0F); + src[0] >> 4 ); } src++; } @@ -1402,7 +1594,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, #ifdef CONFIG_ENCODERS -#define ADPCM_ENCODER(id,name) \ +#define ADPCM_ENCODER(id,name,long_name_) \ AVCodec name ## _encoder = { \ #name, \ CODEC_TYPE_AUDIO, \ @@ -1412,13 +1604,14 @@ AVCodec name ## _encoder = { \ adpcm_encode_frame, \ adpcm_encode_close, \ NULL, \ + .long_name = long_name_, \ }; #else -#define ADPCM_ENCODER(id,name) +#define ADPCM_ENCODER(id,name,long_name_) #endif #ifdef CONFIG_DECODERS -#define ADPCM_DECODER(id,name) \ +#define ADPCM_DECODER(id,name,long_name_) \ AVCodec name ## _decoder = { \ #name, \ CODEC_TYPE_AUDIO, \ @@ -1428,30 +1621,37 @@ AVCodec name ## _decoder = { \ NULL, \ NULL, \ adpcm_decode_frame, \ + .long_name = long_name_, \ }; #else -#define ADPCM_DECODER(id,name) +#define ADPCM_DECODER(id,name,long_name_) #endif -#define ADPCM_CODEC(id, name) \ -ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name) - -ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); -ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct); -ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); -ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); -ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); -ADPCM_CODEC(CODEC_ID_ADPCM_THP, adpcm_thp); -ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); -ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); - -#undef ADPCM_CODEC +#define ADPCM_CODEC(id,name,long_name_) \ + ADPCM_ENCODER(id,name,long_name_) ADPCM_DECODER(id,name,long_name_) + +ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "4X Movie ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "Creative Technology ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "Electronic Arts ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "Electronic Arts Maxis CDROM XA ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "Electronic Arts R1 ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "Electronic Arts R2 ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "Electronic Arts R3 ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "Electronic Arts XAS ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "IMA AMV ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "IMA Duck DK3 ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "IMA Duck DK4 ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "IMA Electronic Arts EACS ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "IMA Electronic Arts SEAD ADPCM"); +ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "IMA QuickTime ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "IMA Loki SDL MJPEG ADPCM"); +ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "IMA Wav ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "IMA Westwood ADPCM"); +ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "Microsoft ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "Sound Blaster Pro 2-bit ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "Sound Blaster Pro 2.6-bit ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "Sound Blaster Pro 4-bit ADPCM"); +ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "Shockwave Flash ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "Nintendo Gamecube THP ADPCM"); +ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "CDROM XA ADPCM"); +ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "Yamaha ADPCM");