[xiph-commits] r17024 - trunk/vorbis/test

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Mar 24 21:45:53 PDT 2010


Author: xiphmont
Date: 2010-03-24 21:45:53 -0700 (Wed, 24 Mar 2010)
New Revision: 17024

Modified:
   trunk/vorbis/test/test.c
   trunk/vorbis/test/write_read.c
   trunk/vorbis/test/write_read.h
Log:
Test 1 through 8 channels, all quality levels, all main sample rates.  This caught another codebook error in the 
16kHz books



Modified: trunk/vorbis/test/test.c
===================================================================
--- trunk/vorbis/test/test.c	2010-03-25 03:58:42 UTC (rev 17023)
+++ trunk/vorbis/test/test.c	2010-03-25 04:45:53 UTC (rev 17024)
@@ -38,32 +38,36 @@
   int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
   unsigned k ;
   int errors = 0 ;
-  float q=-.05;
+  int ch;
 
   gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
 
-  while(q<1.){
-    for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
-      char filename [64] ;
-      snprintf (filename, sizeof (filename), "vorbis_q%.1f_%u.ogg", q*10,sample_rates [k]);
+  for(ch=1;ch<=8;ch++){
+    float q=-.05;
+    printf("\nTesting %d channel%s\n\n",ch,ch==1?"":"s");
+    while(q<1.){
+      for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
+        char filename [64] ;
+        snprintf (filename, sizeof (filename), "vorbis_%dch_q%.1f_%u.ogg", ch,q*10,sample_rates [k]);
 
-      printf ("    %-20s : ", filename);
-      fflush (stdout);
+        printf ("    %-20s : ", filename);
+        fflush (stdout);
 
-      /* Set to know value. */
-      set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
+        /* Set to know value. */
+        set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
 
-      write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out));
-      read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
+        write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out),ch);
+        read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
 
-      if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
-        errors ++ ;
-      else {
-        puts ("ok");
-        remove (filename);
+        if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
+          errors ++ ;
+        else {
+          puts ("ok");
+          remove (filename);
+        }
       }
+      q+=.1;
     }
-    q+=.1;
   }
 
   if (errors)

Modified: trunk/vorbis/test/write_read.c
===================================================================
--- trunk/vorbis/test/write_read.c	2010-03-25 03:58:42 UTC (rev 17023)
+++ trunk/vorbis/test/write_read.c	2010-03-25 04:45:53 UTC (rev 17024)
@@ -29,7 +29,7 @@
 /* The following function is basically a hacked version of the code in
  * examples/encoder_example.c */
 void
-write_vorbis_data_or_die (const char *filename, int srate, float q, const float * data, int count)
+write_vorbis_data_or_die (const char *filename, int srate, float q, const float * data, int count, int ch)
 {
   FILE * file ;
   ogg_stream_state os;
@@ -51,7 +51,7 @@
 
   vorbis_info_init (&vi);
 
-  ret = vorbis_encode_init_vbr (&vi,1,srate,q);
+  ret = vorbis_encode_init_vbr (&vi,ch,srate,q);
   if (ret) {
     printf ("vorbis_encode_init_vbr return %d\n", ret) ;
     exit (1) ;
@@ -88,8 +88,10 @@
   {
     /* expose the buffer to submit data */
     float **buffer = vorbis_analysis_buffer (&vd,count);
+    int i;
 
-    memcpy (buffer [0], data, count * sizeof (float)) ;
+    for(i=0;i<ch;i++)
+      memcpy (buffer [i], data, count * sizeof (float)) ;
 
     /* tell the library how much we actually submitted */
     vorbis_analysis_wrote (&vd,count);
@@ -155,12 +157,14 @@
   ogg_sync_init (&oy);
 
   {
-    buffer = ogg_sync_buffer (&oy,4096);
-    bytes = fread (buffer,1,4096,file);
+    /* fragile!  Assumes all of our headers will fit in the first 8kB,
+       which currently they will */
+    buffer = ogg_sync_buffer (&oy,8192);
+    bytes = fread (buffer,1,8192,file);
     ogg_sync_wrote (&oy,bytes);
 
     if(ogg_sync_pageout (&oy,&og) != 1) {
-      if(bytes < 4096) {
+      if(bytes < 8192) {
         printf ("Out of data.\n") ;
           goto done_decode ;
       }
@@ -192,86 +196,82 @@
     i = 0;
     while ( i < 2) {
       while (i < 2) {
+
         int result = ogg_sync_pageout (&oy,&og);
         if(result == 0)
           break;
         if(result==1) {
           ogg_stream_pagein(&os,&og);
 
-        while (i < 2) {
-          result = ogg_stream_packetout (&os,&op);
-          if (result == 0)
-            goto done_decode;
-          if (result < 0) {
-            fprintf (stderr,"Corrupt secondary header.  Exiting.\n");
-            exit(1);
+          while (i < 2) {
+            result = ogg_stream_packetout (&os,&op);
+            if (result == 0) break;
+            if (result < 0) {
+              fprintf (stderr,"Corrupt secondary header.  Exiting.\n");
+              exit(1);
+            }
+            vorbis_synthesis_headerin (&vi,&vc,&op);
+            i++;
           }
-        vorbis_synthesis_headerin (&vi,&vc,&op);
-        i++;
         }
       }
+
+      buffer = ogg_sync_buffer (&oy,4096);
+      bytes = fread (buffer,1,4096,file);
+      if (bytes == 0 && i < 2) {
+        fprintf (stderr,"End of file before finding all Vorbis headers!\n");
+        exit (1);
+      }
+
+      ogg_sync_wrote (&oy,bytes);
     }
 
-    buffer = ogg_sync_buffer (&oy,4096);
-    bytes = fread (buffer,1,4096,file);
-    if (bytes == 0 && i < 2) {
-      fprintf (stderr,"End of file before finding all Vorbis headers!\n");
-      exit (1);
+    if (vi.rate != srate) {
+      printf ("\n\nError : File '%s' has sample rate of %ld when it should be %d.\n\n", filename, vi.rate, srate);
+      exit (1) ;
     }
 
-    ogg_sync_wrote (&oy,bytes);
-  }
+    vorbis_synthesis_init (&vd,&vi);
+    vorbis_block_init (&vd,&vb);
 
-  if (vi.rate != srate) {
-    printf ("\n\nError : File '%s' has sample rate of %ld when it should be %d.\n\n", filename, vi.rate, srate);
-    exit (1) ;
-  }
-  if (vi.channels != 1) {
-    printf ("\n\nError : File '%s' has %d channels, but should be mono.\n\n", filename, vi.channels);
-    exit (1) ;
-  }
+    while(!eos) {
+      while (!eos) {
+        int result = ogg_sync_pageout (&oy,&og);
+        if (result == 0)
+          break;
+        if (result < 0) {
+          fprintf (stderr,"Corrupt or missing data in bitstream; "
+                   "continuing...\n");
+        } else {
+          ogg_stream_pagein (&os,&og);
+          while (1) {
+            result = ogg_stream_packetout (&os,&op);
 
-  vorbis_synthesis_init (&vd,&vi);
-  vorbis_block_init (&vd,&vb);
-
-  while(!eos) {
-    while (!eos) {
-      int result = ogg_sync_pageout (&oy,&og);
-      if (result == 0)
-        break;
-      if (result < 0) {
-        fprintf (stderr,"Corrupt or missing data in bitstream; "
-            "continuing...\n");
-      } else {
-        ogg_stream_pagein (&os,&og);
-        while (1) {
-          result = ogg_stream_packetout (&os,&op);
-
-          if (result == 0)
-            break;
-          if (result < 0) {
-            /* no reason to complain; already complained above */
-          } else {
+            if (result == 0)
+              break;
+            if (result < 0) {
+              /* no reason to complain; already complained above */
+            } else {
               float **pcm;
-            int samples;
+              int samples;
 
-            if (vorbis_synthesis (&vb,&op) == 0)
-              vorbis_synthesis_blockin(&vd,&vb);
-            while ((samples = vorbis_synthesis_pcmout (&vd,&pcm)) > 0 && read_total < count) {
-              int bout = samples < count ? samples : count;
-              bout = read_total + bout > count ? count - read_total : bout;
+              if (vorbis_synthesis (&vb,&op) == 0)
+                vorbis_synthesis_blockin(&vd,&vb);
+              while ((samples = vorbis_synthesis_pcmout (&vd,&pcm)) > 0 && read_total < count) {
+                int bout = samples < count ? samples : count;
+                bout = read_total + bout > count ? count - read_total : bout;
 
-              memcpy (data + read_total, pcm[0], bout * sizeof (float)) ;
+                memcpy (data + read_total, pcm[0], bout * sizeof (float)) ;
 
-              vorbis_synthesis_read (&vd,bout);
-              read_total += bout ;
+                vorbis_synthesis_read (&vd,bout);
+                read_total += bout ;
+              }
             }
           }
-        }
 
-        if (ogg_page_eos (&og)) eos = 1;
+          if (ogg_page_eos (&og)) eos = 1;
+        }
       }
-    }
 
       if (!eos) {
         buffer = ogg_sync_buffer (&oy,4096);
@@ -287,7 +287,6 @@
     vorbis_dsp_clear (&vd);
     vorbis_comment_clear (&vc);
     vorbis_info_clear (&vi);
-
   }
 done_decode:
 

Modified: trunk/vorbis/test/write_read.h
===================================================================
--- trunk/vorbis/test/write_read.h	2010-03-25 03:58:42 UTC (rev 17023)
+++ trunk/vorbis/test/write_read.h	2010-03-25 04:45:53 UTC (rev 17024)
@@ -18,7 +18,7 @@
 /* Write supplied data to an Ogg/Vorbis file with specified filename at
  * specified sample rate. Assumes a single channel of audio. */
 void write_vorbis_data_or_die (const char *filename, int srate, float q,
-                        const float * data, int count) ;
+                               const float * data, int count, int ch) ;
 
 /* Read given Ogg/Vorbis file into data specified data array. This
  * function is basically the inverse of the one above. Again, assumes



More information about the commits mailing list