X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fadpcm.c;h=d5fa6bcb619972694b098e216804ec52246fd6e2;hb=9d14ffbccee7e6e3f521aa0aa543d9e61b07514f;hp=53341fd17ff9a886864097bc34cf3cd6bc3189e0;hpb=e4a50e6d2e4798f7dec9f9224605dd09b55c18d7;p=ffmpeg diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 53341fd17ff..d5fa6bcb619 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -297,7 +297,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) + if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF)) nodes[0]->sample1 = c->prev_sample; if(version == CODEC_ID_ADPCM_MS) nodes[0]->step = c->idelta; @@ -368,7 +368,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) { + } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (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;\ @@ -519,6 +519,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, PutBitContext pb; init_put_bits(&pb, dst, buf_size*8); + n = avctx->frame_size-1; + //Store AdpcmCodeSize put_bits(&pb, 2, 2); //Set 4bits flash adpcm format @@ -530,10 +532,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, c->status[i].prev_sample = (signed short)samples[i]; } - for (i=1; iframe_size; i++) { - put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]) & 0xF); + if(avctx->trellis > 0) { + uint8_t buf[2][n]; + adpcm_compress_trellis(avctx, samples+2, buf[0], &c->status[0], n); if (avctx->channels == 2) - put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]) & 0xF); + adpcm_compress_trellis(avctx, samples+3, buf[1], &c->status[1], n); + for(i=0; ichannels == 2) + put_bits(&pb, 4, buf[1][i]); + } + } else { + for (i=1; iframe_size; i++) { + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]) & 0xF); + if (avctx->channels == 2) + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]) & 0xF); + } } flush_put_bits(&pb); dst += put_bits_count(&pb)>>3; @@ -706,11 +720,7 @@ static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble) c->predictor = av_clip_int16(c->predictor); /* calculate new step and clamp it to range 511..32767 */ new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8; - c->step = new_step; - if(c->step < 511) - c->step = 511; - if(c->step > 32767) - c->step = 32767; + c->step = av_clip(new_step, 511, 32767); return (short)c->predictor; } @@ -723,16 +733,8 @@ static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble delta = nibble & ((1<<(size-1))-1); diff = delta << (7 + c->step + shift); - if (sign) - c->predictor -= diff; - else - c->predictor += diff; - /* clamp result */ - if (c->predictor > 16256) - c->predictor = 16256; - else if (c->predictor < -16384) - c->predictor = -16384; + c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256); /* calculate new step */ if (delta >= (2*size - 3) && c->step < 3)