diff mbox series

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

Message ID 20200407104835.21425-2-zane@zanevaniperen.com
State Superseded
Headers show
Series Pro Pinball Series Soundbank demuxer + decoder. | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Zane van Iperen April 7, 2020, 10:48 a.m. UTC
Signed-off-by: Zane van Iperen <zane@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(-)

Comments

Michael Niedermayer April 15, 2020, 5:31 p.m. UTC | #1
On Tue, Apr 07, 2020 at 10:48:58AM +0000, Zane van Iperen wrote:
> Signed-off-by: Zane van Iperen <zane@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
Zane van Iperen April 16, 2020, 3:54 a.m. UTC | #2
On Wed, 15 Apr 2020 19:31:44 +0200
"Michael Niedermayer" <michael@niedermayer.cc> wrote:

> On Tue, Apr 07, 2020 at 10:48:58AM +0000, Zane van Iperen wrote:
> > Signed-off-by: Zane van Iperen <zane@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
> 

Yeah, I've rebased upon the latest master, will submit as a v9 tonight.


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

Removed.

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

Removed.

> > @@ -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
> 

So, something like this?
av_assert0(frame->nb_samples == buf_size * 2);

> [...]
> 
> 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
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer April 16, 2020, 7:37 p.m. UTC | #3
On Thu, Apr 16, 2020 at 03:54:01AM +0000, Zane van Iperen wrote:
> On Wed, 15 Apr 2020 19:31:44 +0200
> "Michael Niedermayer" <michael@niedermayer.cc> wrote:
> 
> > On Tue, Apr 07, 2020 at 10:48:58AM +0000, Zane van Iperen wrote:
> > > Signed-off-by: Zane van Iperen <zane@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
> > 
> 
> Yeah, I've rebased upon the latest master, will submit as a v9 tonight.
> 
> 
> > > +    predictor = c->predictor + (step * nibble);  
> > 
> > unneeded ()
> > 
> 
> Removed.
> 
> > 
> > > +
> > > +    c->predictor = av_clip_int16(predictor);
> > > +    c->step_index = step_index;
> > > +
> > > +    return (int16_t)c->predictor;  
> > 
> > unneeded cast
> > 
> 
> Removed.
> 
> > > @@ -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
> > 
> 
> So, something like this?
> av_assert0(frame->nb_samples == buf_size * 2);

as the loop runs bytestream2_get_bytes_left(&gb) iterations
the check should be between that and nb_samples i think

thx

[...]
Zane van Iperen April 16, 2020, 11:39 p.m. UTC | #4
On Thu, 16 Apr 2020 21:37:54 +0200
"Michael Niedermayer" <michael@niedermayer.cc> wrote:

> > > > @@ -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 
> >
> > So, something like this?
> > av_assert0(frame->nb_samples == buf_size * 2);  
> 
> as the loop runs bytestream2_get_bytes_left(&gb) iterations
> the check should be between that and nb_samples i think

In that case, would it just be better to change the while() to a for()?
Same thing, but it shows the samples/nb_samples relationship.

  for (n = 0; n < nb_samples / 2; n++) {}

There's a few other decoders that use the same while() I did
originally, so it might be worth changing them too.
Michael Niedermayer April 17, 2020, 4:50 p.m. UTC | #5
On Thu, Apr 16, 2020 at 11:39:00PM +0000, Zane van Iperen wrote:
> On Thu, 16 Apr 2020 21:37:54 +0200
> "Michael Niedermayer" <michael@niedermayer.cc> wrote:
> 
> > > > > @@ -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 
> > >
> > > So, something like this?
> > > av_assert0(frame->nb_samples == buf_size * 2);  
> > 
> > as the loop runs bytestream2_get_bytes_left(&gb) iterations
> > the check should be between that and nb_samples i think
> 
> In that case, would it just be better to change the while() to a for()?
> Same thing, but it shows the samples/nb_samples relationship.

yes


> 
>   for (n = 0; n < nb_samples / 2; n++) {}
> 
> There's a few other decoders that use the same while() I did
> originally, so it might be worth changing them too.

yes i think so too

thanks

[...]
Zane van Iperen April 18, 2020, 12:17 a.m. UTC | #6
On Fri, 17 Apr 2020 18:50:05 +0200
"Michael Niedermayer" <michael@niedermayer.cc> wrote:

> On Thu, Apr 16, 2020 at 11:39:00PM +0000, Zane van Iperen wrote:
> > On Thu, 16 Apr 2020 21:37:54 +0200
> > "Michael Niedermayer" <michael@niedermayer.cc> wrote:
> >  
> > > > > > @@ -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  
> > > >
> > > > So, something like this?
> > > > av_assert0(frame->nb_samples == buf_size * 2);  
> > >
> > > as the loop runs bytestream2_get_bytes_left(&gb) iterations
> > > the check should be between that and nb_samples i think  
> >
> > In that case, would it just be better to change the while() to a
> > for()? Same thing, but it shows the samples/nb_samples
> > relationship.  
> 
> yes
> 
> 
> >
> >   for (n = 0; n < nb_samples / 2; n++) {}
> >
> > There's a few other decoders that use the same while() I did
> > originally, so it might be worth changing them too.  
> 
> yes i think so too
> 

Okay, I'll send a v10 shortly with the change, followed by a
standalone patch for the other codecs.

Zane
diff mbox series

Patch

diff --git a/Changelog b/Changelog
index e6db88af07..f1be5d674e 100644
--- a/Changelog
+++ b/Changelog
@@ -56,6 +56,7 @@  version <next>:
 - CRI HCA demuxer
 - overlay_cuda filter
 - switch from AvxSynth to AviSynth+ on Linux
+- Cunning Developments ADPCM decoder
 
 
 version 4.2:
diff --git a/doc/general.texi b/doc/general.texi
index 4adcc9e742..4aaf506e56 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1102,6 +1102,7 @@  following image formats are supported:
 @item ADPCM G.726            @tab  X  @tab  X
 @item ADPCM IMA AMV          @tab     @tab  X
     @tab Used in AMV files
+@item ADPCM IMA Cunning Developments  @tab     @tab  X
 @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
 @item ADPCM IMA Electronic Arts SEAD  @tab     @tab  X
 @item ADPCM IMA Funcom       @tab     @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c1c9a44f2b..e799077f09 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -839,6 +839,7 @@  OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER)      += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_CUNNING_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER)     += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER)      += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index e9abddc43c..89c4572538 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -16,6 +16,7 @@ 
  * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
  * Ubisoft ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
  * High Voltage Software ALP decoder by Zane van Iperen (zane@zanevaniperen.com)
+ * Cunning Developments decoder by Zane van Iperen (zane@zanevaniperen.com)
  *
  * This file is part of FFmpeg.
  *
@@ -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);
+
+    c->predictor = av_clip_int16(predictor);
+    c->step_index = step_index;
+
+    return (int16_t)c->predictor;
+}
+
 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;
     case AV_CODEC_ID_ADPCM_IMA_OKI:
         while (bytestream2_get_bytes_left(&gb) > 0) {
             int v = bytestream2_get_byteu(&gb);
@@ -2053,6 +2085,7 @@  ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS,      sample_fmts_s16p, adpcm_ea_xas,
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV,     sample_fmts_s16,  adpcm_ima_amv,     "ADPCM IMA AMV");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC,     sample_fmts_s16,  adpcm_ima_apc,     "ADPCM IMA CRYO APC");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APM,     sample_fmts_s16,  adpcm_ima_apm,     "ADPCM IMA Ubisoft APM");
+ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_CUNNING, sample_fmts_s16,  adpcm_ima_cunning, "ADPCM IMA Cunning Developments");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DAT4,    sample_fmts_s16,  adpcm_ima_dat4,    "ADPCM IMA Eurocom DAT4");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3,     sample_fmts_s16,  adpcm_ima_dk3,     "ADPCM IMA Duck DK3");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4,     sample_fmts_s16,  adpcm_ima_dk4,     "ADPCM IMA Duck DK4");
diff --git a/libavcodec/adpcm_data.c b/libavcodec/adpcm_data.c
index 4cce0a5857..cb9d20948e 100644
--- a/libavcodec/adpcm_data.c
+++ b/libavcodec/adpcm_data.c
@@ -177,3 +177,16 @@  const int16_t ff_adpcm_mtaf_stepsize[32][16] = {
     {   424,  1273,  2121,  2970,  3819,  4668,  5516,  6365,
        -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
 };
+
+const int8_t ff_adpcm_ima_cunning_index_table[8] = {
+    -1, -1, -1, -1, 1, 2, 3, 4,
+};
+
+const int16_t ff_adpcm_ima_cunning_step_table[61] = {
+       1,    1,   1,      1,     2,     2,     3,     3,    4,      5,
+       6,    7,   8,     10,    12,    14,    16,    20,    24,    28,
+      32,   40,  48,     56,    64,    80,    96,   112,   128,   160,
+     192,  224,  256,   320,   384,   448,   512,   640,   768,   896,
+    1024, 1280, 1536,  1792,  2048,  2560,  3072,  3584,  4096,  5120,
+    6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
+};
diff --git a/libavcodec/adpcm_data.h b/libavcodec/adpcm_data.h
index 5a687131d8..fa8a03ee1f 100644
--- a/libavcodec/adpcm_data.h
+++ b/libavcodec/adpcm_data.h
@@ -42,5 +42,7 @@  extern const int16_t ff_adpcm_yamaha_indexscale[];
 extern const int8_t  ff_adpcm_yamaha_difflookup[];
 extern const int16_t ff_adpcm_afc_coeffs[2][16];
 extern const int16_t ff_adpcm_mtaf_stepsize[32][16];
+extern const int8_t  ff_adpcm_ima_cunning_index_table[8];
+extern const int16_t ff_adpcm_ima_cunning_step_table[61];
 
 #endif /* AVCODEC_ADPCM_DATA_H */
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b3184af954..8c5da63a82 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -604,6 +604,7 @@  extern AVCodec ff_adpcm_ima_amv_decoder;
 extern AVCodec ff_adpcm_ima_alp_decoder;
 extern AVCodec ff_adpcm_ima_apc_decoder;
 extern AVCodec ff_adpcm_ima_apm_decoder;
+extern AVCodec ff_adpcm_ima_cunning_decoder;
 extern AVCodec ff_adpcm_ima_dat4_decoder;
 extern AVCodec ff_adpcm_ima_dk3_decoder;
 extern AVCodec ff_adpcm_ima_dk4_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 8fc0ad92c9..14f925b5ed 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -554,6 +554,7 @@  enum AVCodecID {
     AV_CODEC_ID_ADPCM_IMA_APM,
     AV_CODEC_ID_ADPCM_IMA_ALP,
     AV_CODEC_ID_ADPCM_IMA_MTF,
+    AV_CODEC_ID_ADPCM_IMA_CUNNING,
 
     /* AMR */
     AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index ece6eadae4..68151d4af9 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2339,6 +2339,13 @@  static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Capcom's MT Framework"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_ADPCM_IMA_CUNNING,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "adpcm_ima_cunning",
+        .long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Cunning Developments"),
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+    },
 
     /* AMR */
     {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index f4d1d4de21..e62d1a7925 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,8 +28,8 @@ 
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  77
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR  78
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \