[FFmpeg-cvslog] avcodec: add WADY DPCM decoder

Paul B Mahol git at videolan.org
Tue Jan 24 17:56:33 EET 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Jan 21 12:21:44 2023 +0100| [c5a545cff864366c22487b47a2e605a06464790e] | committer: Paul B Mahol

avcodec: add WADY DPCM decoder

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5a545cff864366c22487b47a2e605a06464790e
---

 Changelog               |  1 +
 libavcodec/Makefile     |  1 +
 libavcodec/allcodecs.c  |  1 +
 libavcodec/codec_desc.c |  7 +++++++
 libavcodec/codec_id.h   |  1 +
 libavcodec/dpcm.c       | 45 +++++++++++++++++++++++++++++++++++++++++++--
 libavcodec/utils.c      |  1 +
 libavcodec/version.h    |  2 +-
 8 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 5c01e8365e..c50ebf9951 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ version <next>:
 - corr video filter
 - adrc audio filter
 - afdelaysrc audio filter
+- WADY DPCM decoder
 
 
 version 5.1:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 651d302442..2ad4400a81 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -774,6 +774,7 @@ OBJS-$(CONFIG_VPLAYER_DECODER)         += textdec.o ass.o
 OBJS-$(CONFIG_VP9_V4L2M2M_DECODER)     += v4l2_m2m_dec.o
 OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
 OBJS-$(CONFIG_VQC_DECODER)             += vqcdec.o
+OBJS-$(CONFIG_WADY_DPCM_DECODER)       += dpcm.o
 OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o wavpackdata.o dsd.o
 OBJS-$(CONFIG_WAVPACK_ENCODER)         += wavpackdata.o wavpackenc.o
 OBJS-$(CONFIG_WBMP_DECODER)            += wbmpdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b009848a44..46aaa89e99 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -628,6 +628,7 @@ extern const FFCodec ff_roq_dpcm_decoder;
 extern const FFCodec ff_sdx2_dpcm_decoder;
 extern const FFCodec ff_sol_dpcm_decoder;
 extern const FFCodec ff_xan_dpcm_decoder;
+extern const FFCodec ff_wady_dpcm_decoder;
 
 /* ADPCM codecs */
 extern const FFCodec ff_adpcm_4xm_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 24a0433dba..2272232ed6 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2619,6 +2619,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("DPCM Xilam DERF"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_WADY_DPCM,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "wady_dpcm",
+        .long_name = NULL_IF_CONFIG_SMALL("DPCM Marble WADY"),
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+    },
 
     /* audio codecs */
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index f436a2b624..5ec3fd4b30 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -430,6 +430,7 @@ enum AVCodecID {
     AV_CODEC_ID_SDX2_DPCM,
     AV_CODEC_ID_GREMLIN_DPCM,
     AV_CODEC_ID_DERF_DPCM,
+    AV_CODEC_ID_WADY_DPCM,
 
     /* audio codecs */
     AV_CODEC_ID_MP2 = 0x15000,
diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index 2425f84eb9..2420647bc0 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -45,7 +45,8 @@
 
 typedef struct DPCMContext {
     int16_t array[256];
-    int sample[2];                  ///< previous sample (for SOL_DPCM)
+    int sample[2];                  ///< previous sample (for SOL_DPCM and WADY_DPCM)
+    int scale;                      ///< scale for WADY_DPCM
     const int8_t *sol_table;        ///< delta table for SOL_DPCM
 } DPCMContext;
 
@@ -126,6 +127,24 @@ static const int16_t sol_table_16[128] = {
     0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
 };
 
+static const int16_t wady_table[128] = {
+    0,   2,   4,   6,   8,   10,  12,  15,
+    18,  21,  24,  28,  32,  36,  40,  44,
+    49,  54,  59,  64,  70,  76,  82,  88,
+    95,  102, 109, 116, 124, 132, 140, 148,
+    160, 170, 180, 190, 200, 210, 220, 230,
+    240, 255, 270, 285, 300, 320, 340, 360,
+    380, 400, 425, 450, 475, 500, 525, 550,
+    580, 610, 650, 700, 750, 800, 900, 1000,
+    -0,  -2,  -4,  -6,  -8,  -10, -12, -15,
+    -18, -21, -24, -28, -32, -36, -40, -44,
+    -49, -54, -59, -64, -70, -76, -82, -88,
+    -95, -102,-109,-116,-124,-132,-140,-148,
+    -160,-170,-180,-190,-200,-210,-220,-230,
+    -240,-255,-270,-285,-300,-320,-340,-360,
+    -380,-400,-425,-450,-475,-500,-525,-550,
+    -580,-610,-650,-700,-750,-800,-900,-1000,
+};
 
 static av_cold int dpcm_decode_init(AVCodecContext *avctx)
 {
@@ -139,7 +158,7 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
 
     s->sample[0] = s->sample[1] = 0;
 
-    switch(avctx->codec->id) {
+    switch (avctx->codec->id) {
 
     case AV_CODEC_ID_ROQ_DPCM:
         /* initialize square table */
@@ -193,6 +212,10 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
         }
         break;
 
+    case AV_CODEC_ID_WADY_DPCM:
+        s->scale = (avctx->extradata && avctx->extradata_size > 0) ? avctx->extradata[0] : 1;
+        break;
+
     default:
         break;
     }
@@ -239,6 +262,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         else
             out = buf_size;
         break;
+    case AV_CODEC_ID_WADY_DPCM:
     case AV_CODEC_ID_DERF_DPCM:
     case AV_CODEC_ID_GREMLIN_DPCM:
     case AV_CODEC_ID_SDX2_DPCM:
@@ -401,6 +425,22 @@ static int dpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         }
         }
         break;
+
+    case AV_CODEC_ID_WADY_DPCM: {
+        int idx = 0;
+
+        while (output_samples < samples_end) {
+            const uint8_t n = bytestream2_get_byteu(&gb);
+
+            if (n & 0x80)
+                s->sample[idx] = sign_extend((n & 0x7f) << 9, 16);
+            else
+                s->sample[idx] += s->scale * wady_table[n & 0x7f];
+            *output_samples++ = av_clip_int16(s->sample[idx]);
+            idx ^= stereo;
+        }
+        }
+        break;
     }
 
     *got_frame_ptr = 1;
@@ -427,3 +467,4 @@ DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM,       roq_dpcm,       "DPCM id RoQ");
 DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM,      sdx2_dpcm,      "DPCM Squareroot-Delta-Exact");
 DPCM_DECODER(AV_CODEC_ID_SOL_DPCM,       sol_dpcm,       "DPCM Sol");
 DPCM_DECODER(AV_CODEC_ID_XAN_DPCM,       xan_dpcm,       "DPCM Xan");
+DPCM_DECODER(AV_CODEC_ID_WADY_DPCM,      wady_dpcm,      "DPCM Marble WADY");
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2b63a498b9..27ab92c9ce 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -515,6 +515,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
     case AV_CODEC_ID_PCM_U8:
     case AV_CODEC_ID_SDX2_DPCM:
     case AV_CODEC_ID_DERF_DPCM:
+    case AV_CODEC_ID_WADY_DPCM:
         return 8;
     case AV_CODEC_ID_PCM_S16BE:
     case AV_CODEC_ID_PCM_S16BE_PLANAR:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 6b8a1dbb79..dfd3d5d7e5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  56
+#define LIBAVCODEC_VERSION_MINOR  57
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list