[FFmpeg-devel] [PATCH] Build extradata in adpcm_ms encoder

Daniel Verkamp daniel
Wed Oct 21 22:50:28 CEST 2009


Hi,

This is a fix for issue #1244 (Microsoft ADPCM's riff header does not
include SamplesPerBlock and aCoef).

The addition of comments for AdaptCoeff1/2 is not really a related
change, but it took me several minutes to figure out why these
coefficients did not match the expected values, so I think it's
useful.  The change that introduced this was r14173.

Test regression files are also updated so make test passes.

I tested an encoded file with the version of WMP that ships with
Windows 7 (RTM), and it works.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
>From 0c72158a0c7ef5959b523cd77246af3a819fd421 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Wed, 21 Oct 2009 16:44:07 -0400
Subject: [PATCH] Build extradata in adpcm_ms encoder

Fixes issue #1244
---
 libavcodec/adpcm.c            |   14 ++++++++++
 tests/rotozoom.regression.ref |    4 +-
 tests/seek.regression.ref     |   54 ++++++++++++++++++++--------------------
 tests/vsynth.regression.ref   |    4 +-
 4 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 13f20b4..6abe184 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -86,10 +86,12 @@ static const int AdaptationTable[] = {
         768, 614, 512, 409, 307, 230, 230, 230
 };
 
+/** Divided by 4 to fit in 8-bit integers */
 static const uint8_t AdaptCoeff1[] = {
         64, 128, 0, 48, 60, 115, 98
 };
 
+/** Divided by 4 to fit in 8-bit integers */
 static const int8_t AdaptCoeff2[] = {
         0, -64, 0, 16, 0, -52, -58
 };
@@ -152,6 +154,8 @@ typedef struct ADPCMContext {
 #if CONFIG_ENCODERS
 static av_cold int adpcm_encode_init(AVCodecContext *avctx)
 {
+    uint8_t *extradata;
+    int i;
     if (avctx->channels > 2)
         return -1; /* only stereo or mono =) */
 
@@ -175,6 +179,16 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
                                                              /* and we have 7 bytes per channel overhead */
         avctx->block_align = BLKSIZE;
+        avctx->extradata_size = 32;
+        extradata = avctx->extradata = av_malloc(avctx->extradata_size);
+        if (!extradata)
+            return AVERROR(ENOMEM);
+        bytestream_put_le16(&extradata, avctx->frame_size);
+        bytestream_put_le16(&extradata, 7); /* wNumCoef */
+        for (i = 0; i < 7; i++) {
+            bytestream_put_le16(&extradata, AdaptCoeff1[i] * 4);
+            bytestream_put_le16(&extradata, AdaptCoeff2[i] * 4);
+        }
         break;
     case CODEC_ID_ADPCM_YAMAHA:
         avctx->frame_size = BLKSIZE * avctx->channels;
diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref
index a6dd7da..a089d91 100644
--- a/tests/rotozoom.regression.ref
+++ b/tests/rotozoom.regression.ref
@@ -201,8 +201,8 @@ stddev:  903.51 PSNR: 37.20 bytes:  1061792/  1058444
 281252 ./tests/data/a-adpcm_qt.aiff
 9580492803ba1c1a3746367b24b751c8 *./tests/data/adpcm_ima_qt.rotozoom.out.wav
 stddev:  914.63 PSNR: 37.09 bytes:  1058604/  1058444
-9f813f0cc8b2c05821a31828eadf1188 *./tests/data/a-adpcm_ms.wav
-268344 ./tests/data/a-adpcm_ms.wav
+a407b87daeef5b25dfb6c5b3f519e9c1 *./tests/data/a-adpcm_ms.wav
+268378 ./tests/data/a-adpcm_ms.wav
 7be370f937c51e8a967e6a3d08d5156a *./tests/data/adpcm_ms.rotozoom.out.wav
 stddev: 1050.00 PSNR: 35.90 bytes:  1060620/  1058444
 2546d72df736b5ffa1557e8c9c9ef788 *./tests/data/a-adpcm_yam.wav
diff --git a/tests/seek.regression.ref b/tests/seek.regression.ref
index 57674f1..9601073 100644
--- a/tests/seek.regression.ref
+++ b/tests/seek.regression.ref
@@ -151,59 +151,59 @@ ret: 0         st:-1 flags:1  ts:-0.645825
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     72 size:  4080
 ----------------
 tests/data/a-adpcm_ms.wav
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos:  29752 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos:  29786 size:  4096
 ret: 0         st: 0 flags:0  ts: 0.788345
-ret: 0         st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos:  13368 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos:  13402 size:  4096
 ret: 0         st: 0 flags:1  ts:-0.317506
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st:-1 flags:0  ts: 2.576668
-ret: 0         st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos:  42040 size:  4096
+ret: 0         st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos:  42074 size:  4096
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos:  22584 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos:  22618 size:  4096
 ret: 0         st: 0 flags:0  ts: 0.365011
-ret: 0         st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos:   6200 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos:   6234 size:  4096
 ret: 0         st: 0 flags:1  ts:-0.740839
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st:-1 flags:0  ts: 2.153336
-ret: 0         st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos:  34872 size:  4096
+ret: 0         st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos:  34906 size:  4096
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos:  16440 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos:  16474 size:  4096
 ret: 0         st: 0 flags:0  ts:-0.058322
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st: 0 flags:1  ts: 2.835828
-ret: 0         st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos:  45112 size:  4096
+ret: 0         st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos:  45146 size:  4096
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos:  28728 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos:  28762 size:  4096
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos:   9272 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos:   9306 size:  4096
 ret: 0         st: 0 flags:0  ts:-0.481655
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st: 0 flags:1  ts: 2.412494
-ret: 0         st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos:  37944 size:  4096
+ret: 0         st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos:  37978 size:  4096
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos:  21560 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos:  21594 size:  4096
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos:   3128 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos:   3162 size:  4096
 ret: 0         st: 0 flags:0  ts:-0.904989
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st: 0 flags:1  ts: 1.989184
-ret: 0         st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos:  31800 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos:  31834 size:  4096
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos:  14392 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos:  14426 size:  4096
 ret: 0         st:-1 flags:1  ts:-0.222493
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ret: 0         st: 0 flags:0  ts: 2.671678
-ret: 0         st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos:  43064 size:  4096
+ret: 0         st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos:  43098 size:  4096
 ret: 0         st: 0 flags:1  ts: 1.565850
-ret: 0         st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos:  24632 size:  4096
+ret: 0         st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos:  24666 size:  4096
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos:   8248 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos:   8282 size:  4096
 ret: 0         st:-1 flags:1  ts:-0.645825
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     56 size:  4096
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     90 size:  4096
 ----------------
 tests/data/a-adpcm_swf.flv
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    208 size:  2053
diff --git a/tests/vsynth.regression.ref b/tests/vsynth.regression.ref
index 971abb4..0b14ee3 100644
--- a/tests/vsynth.regression.ref
+++ b/tests/vsynth.regression.ref
@@ -201,8 +201,8 @@ stddev:  903.51 PSNR: 37.20 bytes:  1061792/  1058444
 281252 ./tests/data/a-adpcm_qt.aiff
 9580492803ba1c1a3746367b24b751c8 *./tests/data/adpcm_ima_qt.vsynth.out.wav
 stddev:  914.63 PSNR: 37.09 bytes:  1058604/  1058444
-9f813f0cc8b2c05821a31828eadf1188 *./tests/data/a-adpcm_ms.wav
-268344 ./tests/data/a-adpcm_ms.wav
+a407b87daeef5b25dfb6c5b3f519e9c1 *./tests/data/a-adpcm_ms.wav
+268378 ./tests/data/a-adpcm_ms.wav
 7be370f937c51e8a967e6a3d08d5156a *./tests/data/adpcm_ms.vsynth.out.wav
 stddev: 1050.00 PSNR: 35.90 bytes:  1060620/  1058444
 2546d72df736b5ffa1557e8c9c9ef788 *./tests/data/a-adpcm_yam.wav
-- 
1.6.4.2



More information about the ffmpeg-devel mailing list