[FFmpeg-devel,1/2] avcodec: Implement Acorn Replay IMA ADPCM decoder

Submitted by Cameron Cawley on June 27, 2019, 7:56 p.m.

Details

Message ID 20190627195602.10889-1-ccawley2011@gmail.com
State New
Headers show

Commit Message

Cameron Cawley June 27, 2019, 7:56 p.m.
Signed-off-by: Cameron Cawley <ccawley2011@gmail.com>
---
 doc/general.texi        |  1 +
 libavcodec/Makefile     |  1 +
 libavcodec/adpcm.c      | 14 ++++++++++++++
 libavcodec/allcodecs.c  |  1 +
 libavcodec/avcodec.h    |  1 +
 libavcodec/codec_desc.c |  7 +++++++
 libavcodec/utils.c      |  1 +
 7 files changed, 26 insertions(+)

Comments

Michael Niedermayer July 5, 2019, 4:16 p.m.
On Thu, Jun 27, 2019 at 08:56:01PM +0100, Cameron Cawley wrote:
> Signed-off-by: Cameron Cawley <ccawley2011@gmail.com>
> ---
>  doc/general.texi        |  1 +
>  libavcodec/Makefile     |  1 +
>  libavcodec/adpcm.c      | 14 ++++++++++++++
>  libavcodec/allcodecs.c  |  1 +
>  libavcodec/avcodec.h    |  1 +
>  libavcodec/codec_desc.c |  7 +++++++
>  libavcodec/utils.c      |  1 +
>  7 files changed, 26 insertions(+)
> 
> diff --git a/doc/general.texi b/doc/general.texi
> index ed3cdfcf99..fbbbc24753 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -1070,6 +1070,7 @@ following image formats are supported:
>  @item ADPCM Electronic Arts XAS @tab     @tab  X
>  @item ADPCM G.722            @tab  X  @tab  X
>  @item ADPCM G.726            @tab  X  @tab  X
> +@item ADPCM IMA Acorn Replay @tab     @tab  X
>  @item ADPCM IMA AMV          @tab     @tab  X
>      @tab Used in AMV files
>  @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index edccd73037..9c0dd5d189 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -825,6 +825,7 @@ OBJS-$(CONFIG_ADPCM_G726_DECODER)         += g726.o
>  OBJS-$(CONFIG_ADPCM_G726_ENCODER)         += g726.o
>  OBJS-$(CONFIG_ADPCM_G726LE_DECODER)       += g726.o
>  OBJS-$(CONFIG_ADPCM_G726LE_ENCODER)       += g726.o
> +OBJS-$(CONFIG_ADPCM_IMA_ACORN_DECODER)    += adpcm.o adpcm_data.o
>  OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
>  OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
>  OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER)     += adpcm.o adpcm_data.o
> diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
> index ede0130bf1..1d4b4d2c22 100644
> --- a/libavcodec/adpcm.c
> +++ b/libavcodec/adpcm.c
> @@ -594,6 +594,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
>      switch (avctx->codec->id) {
>          case AV_CODEC_ID_ADPCM_4XM:
>          case AV_CODEC_ID_ADPCM_AGM:
> +        case AV_CODEC_ID_ADPCM_IMA_ACORN:
>          case AV_CODEC_ID_ADPCM_IMA_DAT4:
>          case AV_CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;      break;
>          case AV_CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;           break;
> @@ -1412,6 +1413,18 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
>              }
>          }
>          break;
> +    case AV_CODEC_ID_ADPCM_IMA_ACORN:
> +        for (i=0; i<=st; i++) {
> +            bytestream2_skip(&gb, 2); // TODO: What does this do?
> +            c->status[i].step_index = bytestream2_get_le16u(&gb);
> +        }

where can we find such adpcm files for testing ?

2 bytes per stream could be initial raw pcm samples

thx

[...]
Cameron Cawley July 5, 2019, 4:53 p.m.
Samples are available from
http://riscos.com/ftp_space/370/files/diversions.zip (in the "AudioDemos"
folder) and http://riscos.com/ftp_space/370/files/sound.zip (the files
"1812" and "Enigma").

On Fri, 5 Jul 2019 at 17:16, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Thu, Jun 27, 2019 at 08:56:01PM +0100, Cameron Cawley wrote:
> > Signed-off-by: Cameron Cawley <ccawley2011@gmail.com>
> > ---
> >  doc/general.texi        |  1 +
> >  libavcodec/Makefile     |  1 +
> >  libavcodec/adpcm.c      | 14 ++++++++++++++
> >  libavcodec/allcodecs.c  |  1 +
> >  libavcodec/avcodec.h    |  1 +
> >  libavcodec/codec_desc.c |  7 +++++++
> >  libavcodec/utils.c      |  1 +
> >  7 files changed, 26 insertions(+)
> >
> > diff --git a/doc/general.texi b/doc/general.texi
> > index ed3cdfcf99..fbbbc24753 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -1070,6 +1070,7 @@ following image formats are supported:
> >  @item ADPCM Electronic Arts XAS @tab     @tab  X
> >  @item ADPCM G.722            @tab  X  @tab  X
> >  @item ADPCM G.726            @tab  X  @tab  X
> > +@item ADPCM IMA Acorn Replay @tab     @tab  X
> >  @item ADPCM IMA AMV          @tab     @tab  X
> >      @tab Used in AMV files
> >  @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index edccd73037..9c0dd5d189 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -825,6 +825,7 @@ OBJS-$(CONFIG_ADPCM_G726_DECODER)         += g726.o
> >  OBJS-$(CONFIG_ADPCM_G726_ENCODER)         += g726.o
> >  OBJS-$(CONFIG_ADPCM_G726LE_DECODER)       += g726.o
> >  OBJS-$(CONFIG_ADPCM_G726LE_ENCODER)       += g726.o
> > +OBJS-$(CONFIG_ADPCM_IMA_ACORN_DECODER)    += adpcm.o adpcm_data.o
> >  OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
> >  OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
> >  OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER)     += adpcm.o adpcm_data.o
> > diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
> > index ede0130bf1..1d4b4d2c22 100644
> > --- a/libavcodec/adpcm.c
> > +++ b/libavcodec/adpcm.c
> > @@ -594,6 +594,7 @@ static int get_nb_samples(AVCodecContext *avctx,
> GetByteContext *gb,
> >      switch (avctx->codec->id) {
> >          case AV_CODEC_ID_ADPCM_4XM:
> >          case AV_CODEC_ID_ADPCM_AGM:
> > +        case AV_CODEC_ID_ADPCM_IMA_ACORN:
> >          case AV_CODEC_ID_ADPCM_IMA_DAT4:
> >          case AV_CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;
> break;
> >          case AV_CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;
>  break;
> > @@ -1412,6 +1413,18 @@ static int adpcm_decode_frame(AVCodecContext
> *avctx, void *data,
> >              }
> >          }
> >          break;
> > +    case AV_CODEC_ID_ADPCM_IMA_ACORN:
> > +        for (i=0; i<=st; i++) {
> > +            bytestream2_skip(&gb, 2); // TODO: What does this do?
> > +            c->status[i].step_index = bytestream2_get_le16u(&gb);
> > +        }
>
> where can we find such adpcm files for testing ?
>
> 2 bytes per stream could be initial raw pcm samples
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> No great genius has ever existed without some touch of madness. --
> Aristotle
> _______________________________________________
> 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".

Patch hide | download patch | download mbox

diff --git a/doc/general.texi b/doc/general.texi
index ed3cdfcf99..fbbbc24753 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1070,6 +1070,7 @@  following image formats are supported:
 @item ADPCM Electronic Arts XAS @tab     @tab  X
 @item ADPCM G.722            @tab  X  @tab  X
 @item ADPCM G.726            @tab  X  @tab  X
+@item ADPCM IMA Acorn Replay @tab     @tab  X
 @item ADPCM IMA AMV          @tab     @tab  X
     @tab Used in AMV files
 @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index edccd73037..9c0dd5d189 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -825,6 +825,7 @@  OBJS-$(CONFIG_ADPCM_G726_DECODER)         += g726.o
 OBJS-$(CONFIG_ADPCM_G726_ENCODER)         += g726.o
 OBJS-$(CONFIG_ADPCM_G726LE_DECODER)       += g726.o
 OBJS-$(CONFIG_ADPCM_G726LE_ENCODER)       += g726.o
+OBJS-$(CONFIG_ADPCM_IMA_ACORN_DECODER)    += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)      += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER)     += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index ede0130bf1..1d4b4d2c22 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -594,6 +594,7 @@  static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
     switch (avctx->codec->id) {
         case AV_CODEC_ID_ADPCM_4XM:
         case AV_CODEC_ID_ADPCM_AGM:
+        case AV_CODEC_ID_ADPCM_IMA_ACORN:
         case AV_CODEC_ID_ADPCM_IMA_DAT4:
         case AV_CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;      break;
         case AV_CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;           break;
@@ -1412,6 +1413,18 @@  static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
         break;
+    case AV_CODEC_ID_ADPCM_IMA_ACORN:
+        for (i=0; i<=st; i++) {
+            bytestream2_skip(&gb, 2); // TODO: What does this do?
+            c->status[i].step_index = bytestream2_get_le16u(&gb);
+        }
+
+        for (n = nb_samples >> (1 - st); n > 0; n--) {
+            int byte = bytestream2_get_byteu(&gb);
+            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte & 0x0F, 6);
+            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte >> 4,   6);
+        }
+        break;
     case AV_CODEC_ID_ADPCM_IMA_AMV:
         c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
         c->status[0].step_index = bytestream2_get_byteu(&gb);
@@ -1796,6 +1809,7 @@  ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1,       sample_fmts_s16p, adpcm_ea_r1,
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2,       sample_fmts_s16p, adpcm_ea_r2,       "ADPCM Electronic Arts R2");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3,       sample_fmts_s16p, adpcm_ea_r3,       "ADPCM Electronic Arts R3");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS,      sample_fmts_s16p, adpcm_ea_xas,      "ADPCM Electronic Arts XAS");
+ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ACORN,   sample_fmts_s16,  adpcm_ima_acorn,   "ADPCM IMA Acorn Replay");
 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_DAT4,    sample_fmts_s16,  adpcm_ima_dat4,    "ADPCM IMA Eurocom DAT4");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d2f9a39ce5..78177a1255 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -592,6 +592,7 @@  extern AVCodec ff_adpcm_g726_encoder;
 extern AVCodec ff_adpcm_g726_decoder;
 extern AVCodec ff_adpcm_g726le_encoder;
 extern AVCodec ff_adpcm_g726le_decoder;
+extern AVCodec ff_adpcm_ima_acorn_decoder;
 extern AVCodec ff_adpcm_ima_amv_decoder;
 extern AVCodec ff_adpcm_ima_apc_decoder;
 extern AVCodec ff_adpcm_ima_dat4_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 586bbbca4e..f2e8f27c75 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -542,6 +542,7 @@  enum AVCodecID {
     AV_CODEC_ID_ADPCM_IMA_DAT4,
     AV_CODEC_ID_ADPCM_MTAF,
     AV_CODEC_ID_ADPCM_AGM,
+    AV_CODEC_ID_ADPCM_IMA_ACORN,
 
     /* AMR */
     AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 4d033c20ff..dc39b50e33 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2276,6 +2276,13 @@  static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("ADPCM AmuseGraphics Movie AGM"),
         .props     = AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_ADPCM_IMA_ACORN,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "adpcm_ima_acorn",
+        .long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Acorn Replay"),
+        .props     = AV_CODEC_PROP_LOSSY,
+    },
 
     /* AMR */
     {
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index cc04b73471..6ad7ead502 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1613,6 +1613,7 @@  static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
             case AV_CODEC_ID_ADPCM_DTK:
                 return frame_bytes / (16 * ch) * 28;
             case AV_CODEC_ID_ADPCM_4XM:
+            case AV_CODEC_ID_ADPCM_IMA_ACORN:
             case AV_CODEC_ID_ADPCM_IMA_DAT4:
             case AV_CODEC_ID_ADPCM_IMA_ISS:
                 return (frame_bytes - 4 * ch) * 2 / ch;