[xiph-commits] r17701 - trunk/squishyball

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Dec 1 12:58:31 PST 2010


Author: xiphmont
Date: 2010-12-01 12:58:30 -0800 (Wed, 01 Dec 2010)
New Revision: 17701

Modified:
   trunk/squishyball/audio.c
   trunk/squishyball/main.c
   trunk/squishyball/main.h
   trunk/squishyball/squishyball.1
Log:
Add clipping check as -C


Modified: trunk/squishyball/audio.c
===================================================================
--- trunk/squishyball/audio.c	2010-12-01 19:59:04 UTC (rev 17700)
+++ trunk/squishyball/audio.c	2010-12-01 20:58:30 UTC (rev 17701)
@@ -47,6 +47,91 @@
   return 0;
 }
 
+void check_warn_clipping(pcm_t *pcm){
+  int i,j;
+  int bps = (pcm->bits==-32 ? 4 : (pcm->bits+7)>>3);
+  int cpf = pcm->ch;
+  int bpf = cpf*bps;
+  int s = pcm->size/bpf;
+  int flag[cpf];
+  size_t count=0;
+  unsigned char *d = pcm->data;
+
+  memset(flag,0,sizeof(flag));
+
+  switch(pcm->bits){
+  case 16:
+    for(i=0;i<s;i++)
+      for(j=0;j<cpf;j++){
+        short v = d[0] | (d[1]<<8);
+        if(v==-32768 || v==32767)
+          flag[j]++;
+        else{
+          if(flag[j]>1)count+=flag[j];
+          flag[j]=0;
+        }
+        d+=2;
+      }
+    for(j=0;j<cpf;j++)
+      if(flag[j]>1)count+=flag[j];
+    break;
+  case 24:
+    for(i=0;i<s;i++)
+      for(j=0;j<cpf;j++){
+        int v = ((d[0]<<8) | (d[1]<<16) | (d[2]<<24))>>8;
+        if(v==-8388608 || v==8388607)
+          flag[j]++;
+        else{
+          if(flag[j]>1)count+=flag[j];
+          flag[j]=0;
+        }
+        d+=3;
+      }
+    for(j=0;j<cpf;j++)
+      if(flag[j]>1)count+=flag[j];
+    break;
+  case -32:
+    {
+      union {
+        float f;
+        unsigned char c[4];
+      } m;
+
+      if(host_is_big_endian()){
+        for(i=0;i<s;i++)
+          for(j=0;j<cpf;j++){
+            m.c[0]=d[3];
+            m.c[1]=d[2];
+          m.c[2]=d[1];
+          m.c[3]=d[0];
+          if(m.f<-1. || m.f>=1.)
+            count++;
+          d+=4;
+          }
+      }else{
+        for(i=0;i<s;i++)
+          for(j=0;j<cpf;j++){
+            m.c[0]=d[0];
+            m.c[1]=d[1];
+            m.c[2]=d[2];
+            m.c[3]=d[3];
+          if(m.f<-1. || m.f>=1.)
+            count++;
+          d+=4;
+          }
+      }
+    }
+    break;
+  }
+
+  if(count){
+    if(bps==4)
+      fprintf(stderr,"CLIPPING WARNING: %ld clipped samples in %s.\n",(long)count,pcm->path);
+    else
+      fprintf(stderr,"CLIPPING WARNING: %ld probably clipped samples in %s.\n",(long)count,pcm->path);
+  }
+}
+
 static inline float triangle_ditherval(float *save){
   float r = rand()/(float)RAND_MAX-.5f;
   float ret = *save-r;

Modified: trunk/squishyball/main.c
===================================================================
--- trunk/squishyball/main.c	2010-12-01 19:59:04 UTC (rev 17700)
+++ trunk/squishyball/main.c	2010-12-01 20:58:30 UTC (rev 17701)
@@ -48,13 +48,14 @@
 #define MAXFILES 10
 int sb_verbose=0;
 
-char *short_options="abcd:De:hn:rRs:tvVxBMSg";
+char *short_options="abcd:De:hn:rRs:tvVxBMSgC";
 
 struct option long_options[] = {
   {"ab",no_argument,0,'a'},
   {"abx",no_argument,0,'b'},
   {"beep-flip",no_argument,0,'B'},
   {"casual",no_argument,0,'c'},
+  {"clip-check",no_argument,0,'C'},
   {"device",required_argument,0,'d'},
   {"force-dither",no_argument,0,'D'},
   {"end-time",no_argument,0,'e'},
@@ -79,7 +80,7 @@
           "\nXiph Squishyball %s\n"
           "perform sample comparison testing on the command line\n\n"
           "USAGE:\n"
-          "  squishyball [options] fileA [fileB [[-c] fileN...]]\n\n"
+          "  squishyball [options] fileA [fileB [fileN...]] [> results.txt]\n\n"
           "OPTIONS:\n"
           "  -a --ab                : Perform A/B test\n"
           "  -b --abx               : Perform A/B/X test\n"
@@ -88,6 +89,7 @@
           "  -c --casual            : casual mode; load up to ten\n"
           "                           samples for non-randomized\n"
           "                           comparison without trials (default).\n"
+          "  -C --clip-check        : Check loaded samples for clipping.\n"
           "  -d --device <N|dev>    : If a number, output to Nth\n"
           "                           sound device.  If a device name,\n"
           "                           use output driver/device matching\n"
@@ -348,6 +350,7 @@
   int test_mode=3;
   int test_files;
   char *device=NULL;
+  int clip_check=0;
   int force_dither=0;
   int force_truncate=0;
   int restart_mode=0;
@@ -446,6 +449,9 @@
     case 'g':
       running_score=1;
       break;
+    case 'C':
+      clip_check=1;
+      break;
     default:
       usage(stderr);
       exit(1);
@@ -481,6 +487,8 @@
   outbits=16;
   for(i=0;i<test_files;i++){
     pcm[i]=load_audio_file(argv[optind+i]);
+    if(clip_check)
+      check_warn_clipping(pcm[i]);
     if(!pcm[i])exit(2);
 
     if(!pcm[i]->dither && force_dither)pcm[i]->dither=1;

Modified: trunk/squishyball/main.h
===================================================================
--- trunk/squishyball/main.h	2010-12-01 19:59:04 UTC (rev 17700)
+++ trunk/squishyball/main.h	2010-12-01 20:58:30 UTC (rev 17701)
@@ -43,6 +43,7 @@
 
 extern pcm_t *load_audio_file(char *path);
 extern void free_pcm(pcm_t *pcm);
+void check_warn_clipping(pcm_t *pcm);
 
 extern void convert_to_16(pcm_t *pcm);
 extern void convert_to_24(pcm_t *pcm);

Modified: trunk/squishyball/squishyball.1
===================================================================
--- trunk/squishyball/squishyball.1	2010-12-01 19:59:04 UTC (rev 17700)
+++ trunk/squishyball/squishyball.1	2010-12-01 20:58:30 UTC (rev 17701)
@@ -8,7 +8,7 @@
 
 .SH SYNOPSIS
 .B squishyball
-[\fIoptions\fR] fileA [fileB [[\fB-c\fR] \fIfileN...\fR]] [> results.txt]
+[\fIoptions\fR] fileA [fileB [\fIfileN...\fR]] [> results.txt]
 
 .SH DESCRIPTION
 .B squishyball
@@ -72,6 +72,10 @@
 .SH OTHER OPTIONS
 .IP "\fB-B --beep-flip"
 Mark transitions between samples with a short beep.
+.IP "\fB-C --clip-check"
+Check input samples for clipping.  Floating point samples can be
+checked accurately. Integer samples are checked heuristically; two or
+more consecutive full-range samples in a channel are counted as clipped.
 .IP "\fB-d --device \fIN\fR|\fIdevice"
 If a number, output to Nth available sound device.  If a device name,
 use output device matching that device name.  The backend audio driver is



More information about the commits mailing list