From c43d77c163d91cbe4eb1f8be1e3b3afca107faeb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= <mans@mansr.com>
Date: Fri, 9 Jul 2010 16:06:05 +0000
Subject: [PATCH] tiny_psnr: skip wav headers on input files

The byte count printed excludes the header, and offsets are applied
after the the headers are skipped.

Reference files updated to reflect new output.  Some stddev/psnr values
have changed slightly due to headers no longer being compared.

Originally committed as revision 24143 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 tests/ref/acodec/adpcm_ima_qt  |  2 +-
 tests/ref/acodec/adpcm_ima_wav |  2 +-
 tests/ref/acodec/adpcm_ms      |  2 +-
 tests/ref/acodec/adpcm_swf     |  2 +-
 tests/ref/acodec/adpcm_yam     |  2 +-
 tests/ref/acodec/alac          |  2 +-
 tests/ref/acodec/flac          |  2 +-
 tests/ref/acodec/g726          |  2 +-
 tests/ref/acodec/mp2           |  4 ++--
 tests/ref/acodec/pcm           | 36 +++++++++++++++++-----------------
 tests/ref/acodec/wmav1         |  4 ++--
 tests/ref/acodec/wmav2         |  4 ++--
 tests/tiny_psnr.c              | 23 +++++++++++++++++++---
 13 files changed, 52 insertions(+), 35 deletions(-)

diff --git a/tests/ref/acodec/adpcm_ima_qt b/tests/ref/acodec/adpcm_ima_qt
index f096e07b68c..6e4415660e2 100644
--- a/tests/ref/acodec/adpcm_ima_qt
+++ b/tests/ref/acodec/adpcm_ima_qt
@@ -1,4 +1,4 @@
 3c06fd2f7831e3e8735b936e23ca220c *./tests/data/acodec/adpcm_qt.aiff
 281252 ./tests/data/acodec/adpcm_qt.aiff
 9580492803ba1c1a3746367b24b751c8 *./tests/data/adpcm_ima_qt.acodec.out.wav
-stddev:  914.63 PSNR: 37.10 MAXDIFF:34026 bytes:  1058604/  1058444
+stddev:  914.65 PSNR: 37.10 MAXDIFF:34026 bytes:  1058560/  1058400
diff --git a/tests/ref/acodec/adpcm_ima_wav b/tests/ref/acodec/adpcm_ima_wav
index 9d4494bea08..29f5836fd90 100644
--- a/tests/ref/acodec/adpcm_ima_wav
+++ b/tests/ref/acodec/adpcm_ima_wav
@@ -1,4 +1,4 @@
 56b75c3a6dacedcf2ce7b0586aa33594 *./tests/data/acodec/adpcm_ima.wav
 267324 ./tests/data/acodec/adpcm_ima.wav
 78a2af1c895792d0c221d127bdd48ece *./tests/data/adpcm_ima_wav.acodec.out.wav
-stddev:  903.51 PSNR: 37.21 MAXDIFF:34026 bytes:  1061792/  1058444
+stddev:  903.51 PSNR: 37.21 MAXDIFF:34026 bytes:  1061748/  1058400
diff --git a/tests/ref/acodec/adpcm_ms b/tests/ref/acodec/adpcm_ms
index 1fdf053ed22..65d2a6ca65f 100644
--- a/tests/ref/acodec/adpcm_ms
+++ b/tests/ref/acodec/adpcm_ms
@@ -1,4 +1,4 @@
 a407b87daeef5b25dfb6c5b3f519e9c1 *./tests/data/acodec/adpcm_ms.wav
 268378 ./tests/data/acodec/adpcm_ms.wav
 7be370f937c51e8a967e6a3d08d5156a *./tests/data/adpcm_ms.acodec.out.wav
-stddev: 1050.00 PSNR: 35.91 MAXDIFF:29806 bytes:  1060620/  1058444
+stddev: 1050.01 PSNR: 35.91 MAXDIFF:29806 bytes:  1060576/  1058400
diff --git a/tests/ref/acodec/adpcm_swf b/tests/ref/acodec/adpcm_swf
index 8e0274cb773..27a5da518c6 100644
--- a/tests/ref/acodec/adpcm_swf
+++ b/tests/ref/acodec/adpcm_swf
@@ -1,4 +1,4 @@
 42d4639866ed4d692eaf126228a4fa2a *./tests/data/acodec/adpcm_swf.flv
 269166 ./tests/data/acodec/adpcm_swf.flv
 628089745a7059ae4055c2515b6d668b *./tests/data/adpcm_swf.acodec.out.wav
-stddev:  933.65 PSNR: 36.93 MAXDIFF:51119 bytes:  1065004/  1058444
+stddev:  933.58 PSNR: 36.93 MAXDIFF:51119 bytes:  1064960/  1058400
diff --git a/tests/ref/acodec/adpcm_yam b/tests/ref/acodec/adpcm_yam
index 48e21742774..d7076e721c2 100644
--- a/tests/ref/acodec/adpcm_yam
+++ b/tests/ref/acodec/adpcm_yam
@@ -1,4 +1,4 @@
 2546d72df736b5ffa1557e8c9c9ef788 *./tests/data/acodec/adpcm_yam.wav
 266296 ./tests/data/acodec/adpcm_yam.wav
 c80c847a53a0fee17a88fa889ec34a4e *./tests/data/adpcm_yam.acodec.out.wav
-stddev: 1247.64 PSNR: 34.41 MAXDIFF:39895 bytes:  1065004/  1058444
+stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes:  1064960/  1058400
diff --git a/tests/ref/acodec/alac b/tests/ref/acodec/alac
index 039cf14029f..1f4b264b870 100644
--- a/tests/ref/acodec/alac
+++ b/tests/ref/acodec/alac
@@ -1,4 +1,4 @@
 c68f649777ab8e7c9a0f1f221451d3ad *./tests/data/acodec/alac.m4a
 389386 ./tests/data/acodec/alac.m4a
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/alac.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
diff --git a/tests/ref/acodec/flac b/tests/ref/acodec/flac
index 5214cc676ca..e9d7cfc0a82 100644
--- a/tests/ref/acodec/flac
+++ b/tests/ref/acodec/flac
@@ -1,4 +1,4 @@
 151eef9097f944726968bec48649f00a *./tests/data/acodec/flac.flac
 361582 ./tests/data/acodec/flac.flac
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/flac.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
diff --git a/tests/ref/acodec/g726 b/tests/ref/acodec/g726
index 1d5475242b6..e0399bf23fd 100644
--- a/tests/ref/acodec/g726
+++ b/tests/ref/acodec/g726
@@ -1,4 +1,4 @@
 5d8cce28f83dd33c3c7eaf43a5db5294 *./tests/data/acodec/g726.wav
 24082 ./tests/data/acodec/g726.wav
 4f1ba1af75dee64625a1c852e6cd01d3 *./tests/data/g726.acodec.out.wav
-stddev: 8506.46 PSNR: 17.73 MAXDIFF:36208 bytes:    96148/  1058444
+stddev: 8504.69 PSNR: 17.74 MAXDIFF:31645 bytes:    96104/  1058400
diff --git a/tests/ref/acodec/mp2 b/tests/ref/acodec/mp2
index 3b80e5476f6..df21be2bd74 100644
--- a/tests/ref/acodec/mp2
+++ b/tests/ref/acodec/mp2
@@ -1,5 +1,5 @@
 f6eb0a205350bbd7fb1028a01c7ae8aa *./tests/data/acodec/mp2.mp2
 96130 ./tests/data/acodec/mp2.mp2
 74c7b6b15a001add199619fafe4059a1 *./tests/data/mp2.acodec.out.wav
-stddev: 9315.80 PSNR: 16.94 MAXDIFF:65388 bytes:  1059884/  1058444
-stddev: 4385.25 PSNR: 23.49 MAXDIFF:52631 bytes:  1057960/  1058444
+stddev: 9315.99 PSNR: 16.94 MAXDIFF:65388 bytes:  1059840/  1058400
+stddev: 4384.33 PSNR: 23.49 MAXDIFF:52631 bytes:  1057916/  1058400
diff --git a/tests/ref/acodec/pcm b/tests/ref/acodec/pcm
index b37b05497d8..1d876e4acac 100644
--- a/tests/ref/acodec/pcm
+++ b/tests/ref/acodec/pcm
@@ -1,72 +1,72 @@
 89f5b8dd97e0dddbe59af0d44fd229f3 *./tests/data/acodec/pcm_alaw.wav
 529256 ./tests/data/acodec/pcm_alaw.wav
 0568b0b9a72e31559e150e7e09d301cd *./tests/data/pcm.acodec.out.wav
-stddev:  101.67 PSNR: 56.19 MAXDIFF:  515 bytes:  1058444/  1058444
+stddev:  101.67 PSNR: 56.19 MAXDIFF:  515 bytes:  1058400/  1058400
 f443a8eeb1647ec1eeb8370c939e52d4 *./tests/data/acodec/pcm_mulaw.wav
 529256 ./tests/data/acodec/pcm_mulaw.wav
 1c3eeaa8814ebd4916780dff80ed6dc5 *./tests/data/pcm.acodec.out.wav
-stddev:  103.38 PSNR: 56.04 MAXDIFF:  644 bytes:  1058444/  1058444
+stddev:  103.38 PSNR: 56.04 MAXDIFF:  644 bytes:  1058400/  1058400
 b7936d7170e0efefb379349d81aed360 *./tests/data/acodec/pcm_s8.mov
 530837 ./tests/data/acodec/pcm_s8.mov
 652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav
-stddev:  147.89 PSNR: 52.93 MAXDIFF:  255 bytes:  1058444/  1058444
+stddev:  147.89 PSNR: 52.93 MAXDIFF:  255 bytes:  1058400/  1058400
 98cadb3502dbdc99e6e077c28b1a036c *./tests/data/acodec/pcm_u8.wav
 529244 ./tests/data/acodec/pcm_u8.wav
 652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav
-stddev:  147.89 PSNR: 52.93 MAXDIFF:  255 bytes:  1058444/  1058444
+stddev:  147.89 PSNR: 52.93 MAXDIFF:  255 bytes:  1058400/  1058400
 c42b9c04305455250366c84e17c1023f *./tests/data/acodec/pcm_s16be.mov
 1060037 ./tests/data/acodec/pcm_s16be.mov
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/acodec/pcm_s16le.wav
 1058444 ./tests/data/acodec/pcm_s16le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 352a6bcf51d0f3ca4bf27c423a3d4d14 *./tests/data/acodec/pcm_s16be.mkv
  1060650 ./tests/data/acodec/pcm_s16be.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 2c089d83b2699c02c9358415e00a9707 *./tests/data/acodec/pcm_s16le.mkv
  1060650 ./tests/data/acodec/pcm_s16le.mkv
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 07ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov
 1589237 ./tests/data/acodec/pcm_s24be.mov
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 a85380fb79b0d4fff38e24ac1e34bb94 *./tests/data/acodec/pcm_s24le.wav
 1587668 ./tests/data/acodec/pcm_s24le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 d7792f0343cd66fda8b50b569e2bcc48 *./tests/data/acodec/pcm_s32be.mov
 2118437 ./tests/data/acodec/pcm_s32be.mov
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 da6ed80f4f40f0082577dea80827e014 *./tests/data/acodec/pcm_s32le.wav
 2116868 ./tests/data/acodec/pcm_s32le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 118ff3dc83c62ce9ce669eef57e55bb2 *./tests/data/acodec/pcm_f32be.au
 2116824 ./tests/data/acodec/pcm_f32be.au
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 46f44f86a18984a832206ab9e29a79f2 *./tests/data/acodec/pcm_f32le.wav
 2116880 ./tests/data/acodec/pcm_f32le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 8112296b1ed94f72f20d04b1a54850a7 *./tests/data/acodec/pcm_f64be.au
 4233624 ./tests/data/acodec/pcm_f64be.au
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 ba17c6d1a270e1333e981f239bf7eb45 *./tests/data/acodec/pcm_f64le.wav
 4233680 ./tests/data/acodec/pcm_f64le.wav
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058444/  1058444
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
 8c74234928ed425b1171211a89f67ead *./tests/data/acodec/pcm_zork.wav
 529256 ./tests/data/acodec/pcm_zork.wav
 864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.acodec.out.wav
-stddev:  633.10 PSNR: 40.30 MAXDIFF:32768 bytes:  1058444/  1058444
+stddev:  633.11 PSNR: 40.30 MAXDIFF:32768 bytes:  1058400/  1058400
 8168a5c1343553ef027541830f2cb879 *./tests/data/acodec/pcm_s24daud.302
 10368730 ./tests/data/acodec/pcm_s24daud.302
 f552afadfdfcd6348a07095da6382de5 *./tests/data/pcm.acodec.out.wav
-stddev: 9415.16 PSNR: 16.85 MAXDIFF:51900 bytes:  6911864/  1058444
+stddev: 9416.28 PSNR: 16.85 MAXDIFF:42744 bytes:  6911796/  1058400
diff --git a/tests/ref/acodec/wmav1 b/tests/ref/acodec/wmav1
index fcf4424144e..916e4a8ab61 100644
--- a/tests/ref/acodec/wmav1
+++ b/tests/ref/acodec/wmav1
@@ -1,4 +1,4 @@
 26a7f6b0f0b7181df8df3fa589f6bf81 *./tests/data/acodec/wmav1.asf
 106004 ./tests/data/acodec/wmav1.asf
-stddev:12245.27 PSNR: 14.57 MAXDIFF:65521 bytes:  1065004/  1058444
-stddev: 2097.78 PSNR: 29.89 MAXDIFF:27658 bytes:  1056812/  1058444
+stddev:12245.52 PSNR: 14.57 MAXDIFF:65521 bytes:  1064960/  1058400
+stddev: 2095.89 PSNR: 29.90 MAXDIFF:27658 bytes:  1056768/  1058400
diff --git a/tests/ref/acodec/wmav2 b/tests/ref/acodec/wmav2
index 001d9395bc4..622b6fcc369 100644
--- a/tests/ref/acodec/wmav2
+++ b/tests/ref/acodec/wmav2
@@ -1,4 +1,4 @@
 7c6c0cb692af01b312ae345723674b5f *./tests/data/acodec/wmav2.asf
 106044 ./tests/data/acodec/wmav2.asf
-stddev:12249.69 PSNR: 14.57 MAXDIFF:65521 bytes:  1065004/  1058444
-stddev: 2091.12 PSNR: 29.92 MAXDIFF:27650 bytes:  1056812/  1058444
+stddev:12249.93 PSNR: 14.57 MAXDIFF:65521 bytes:  1064960/  1058400
+stddev: 2089.21 PSNR: 29.93 MAXDIFF:27650 bytes:  1056768/  1058400
diff --git a/tests/tiny_psnr.c b/tests/tiny_psnr.c
index 66b6747af34..681fd139516 100644
--- a/tests/tiny_psnr.c
+++ b/tests/tiny_psnr.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <inttypes.h>
 #include <assert.h>
 
@@ -117,8 +118,7 @@ int main(int argc,char* argv[]){
 
     if(argc<3){
         printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n");
-        printf("For WAV files use the following:\n");
-        printf("./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\n");
+        printf("WAV headers are skipped automatically.\n");
         return -1;
     }
 
@@ -128,7 +128,24 @@ int main(int argc,char* argv[]){
         fprintf(stderr, "Could not open input files.\n");
         return -1;
     }
-    fseek(f[shift<0], shift < 0 ? -shift : shift, SEEK_SET);
+
+    for (i = 0; i < 2; i++) {
+        uint8_t *p = buf[i];
+        fread(p, 1, 12, f[i]);
+        if (!memcmp(p,   "RIFF", 4) &&
+            !memcmp(p+8, "WAVE", 4)) {
+            fread(p, 1, 8, f[i]);
+            while (memcmp(p, "data", 4)) {
+                int s = p[4] | p[5]<<8 | p[6]<<16 | p[7]<<24;
+                fseek(f[i], s, SEEK_CUR);
+                fread(p, 1, 8, f[i]);
+            }
+        } else {
+            fseek(f[i], -12, SEEK_CUR);
+        }
+    }
+
+    fseek(f[shift<0], shift < 0 ? -shift : shift, SEEK_CUR);
 
     fseek(f[0],skip_bytes,SEEK_CUR);
     fseek(f[1],skip_bytes,SEEK_CUR);
-- 
GitLab