[FFmpeg-devel] [PATCH v8 1/2] avcodec: add support for Cunning Developments' ADPCM

Michael Niedermayer michael at niedermayer.cc
Wed Apr 15 20:31:44 EEST 2020


On Tue, Apr 07, 2020 at 10:48:58AM +0000, Zane van Iperen wrote:
> Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
> ---
>  Changelog               |  1 +
>  doc/general.texi        |  1 +
>  libavcodec/Makefile     |  1 +
>  libavcodec/adpcm.c      | 33 +++++++++++++++++++++++++++++++++
>  libavcodec/adpcm_data.c | 13 +++++++++++++
>  libavcodec/adpcm_data.h |  2 ++
>  libavcodec/allcodecs.c  |  1 +
>  libavcodec/avcodec.h    |  1 +
>  libavcodec/codec_desc.c |  7 +++++++
>  libavcodec/version.h    |  4 ++--
>  10 files changed, 62 insertions(+), 2 deletions(-)

this doesnt apply anymore

[...]
> @@ -109,6 +110,9 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
>      unsigned int max_channels = 2;
>  
>      switch(avctx->codec->id) {
> +    case AV_CODEC_ID_ADPCM_IMA_CUNNING:
> +        max_channels = 1;
> +        break;
>      case AV_CODEC_ID_ADPCM_DTK:
>      case AV_CODEC_ID_ADPCM_EA:
>          min_channels = 2;
> @@ -325,6 +329,26 @@ static inline int16_t adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nib
>      return (int16_t)c->predictor;
>  }
>  
> +static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
> +{
> +    int step_index;
> +    int predictor;
> +    int step;
> +
> +    nibble = sign_extend(nibble & 0xF, 4);
> +
> +    step = ff_adpcm_ima_cunning_step_table[c->step_index];
> +    step_index = c->step_index + ff_adpcm_ima_cunning_index_table[abs(nibble)];
> +    step_index = av_clip(step_index, 0, 60);
> +

> +    predictor = c->predictor + (step * nibble);

unneeded ()


> +
> +    c->predictor = av_clip_int16(predictor);
> +    c->step_index = step_index;
> +
> +    return (int16_t)c->predictor;

unneeded cast


> +}
> +
>  static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
>  {
>      int nibble, step_index, predictor, sign, delta, diff, step, shift;
> @@ -713,6 +737,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
>      /* simple 4-bit adpcm */
>      case AV_CODEC_ID_ADPCM_CT:
>      case AV_CODEC_ID_ADPCM_IMA_APC:
> +    case AV_CODEC_ID_ADPCM_IMA_CUNNING:
>      case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
>      case AV_CODEC_ID_ADPCM_IMA_OKI:
>      case AV_CODEC_ID_ADPCM_IMA_WS:

> @@ -1304,6 +1329,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
>              samples += avctx->channels;
>          }
>          break;
> +    case AV_CODEC_ID_ADPCM_IMA_CUNNING:
> +        while (bytestream2_get_bytes_left(&gb) > 0) {
> +            int v = bytestream2_get_byteu(&gb);
> +            *samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v & 0x0F);
> +            *samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v >> 4);
> +        }
> +        break;

i would add an av_assert to ensure the samples array is large enough and
the code seting it stays in sync. And also so the reader knows at a glance
that this is ok with only a check on the input size

[...]

thx
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200415/be6d9a7a/attachment.sig>


More information about the ffmpeg-devel mailing list