[xiph-commits] r11666 - trunk/vorbis-tools/oggdec

msmith at svn.xiph.org msmith at svn.xiph.org
Thu Jun 29 04:46:14 PDT 2006


Author: msmith
Date: 2006-06-29 04:46:12 -0700 (Thu, 29 Jun 2006)
New Revision: 11666

Modified:
   trunk/vorbis-tools/oggdec/oggdec.c
Log:
Remap > 2 channel files to correct wav channel ordering when writing wav data
out


Modified: trunk/vorbis-tools/oggdec/oggdec.c
===================================================================
--- trunk/vorbis-tools/oggdec/oggdec.c	2006-06-29 11:00:57 UTC (rev 11665)
+++ trunk/vorbis-tools/oggdec/oggdec.c	2006-06-29 11:46:12 UTC (rev 11666)
@@ -216,11 +216,34 @@
     return out;
 }
 
+static void
+permute_channels(char *in, char *out, int len, int channels, int bytespersample)
+{
+    int permute[6][6] = {{0}, {0,1}, {0,2,1}, {0,1,2,3}, {0,1,2,3,4}, 
+        {0,2,1,5,3,4}};
+    int i,j,k;
+    int samples = len/channels/bytespersample;
+
+    /* Can't handle, don't try */
+    if (channels > 6)
+        return;
+
+    for (i=0; i < samples; i++) {
+        for (j=0; j < channels; j++) {
+            for (k=0; k < bytespersample; k++) {
+                out[i*bytespersample*channels + 
+                    bytespersample*permute[channels-1][j] + k] = 
+                    in[i*bytespersample*channels + bytespersample*j + k];
+            }
+        }
+    }
+}
+
 static int decode_file(FILE *in, FILE *out, char *infile, char *outfile)
 {
     OggVorbis_File vf;
     int bs = 0;
-    char buf[8192];
+    char buf[8192], outbuf[8192];
     int buflen = 8192;
     unsigned int written = 0;
     int ret;
@@ -282,12 +305,17 @@
 
         if(ret < 0 ) {
            if( !quiet ) {
-               fprintf(stderr, "Warning: hole in data\n");
+               fprintf(stderr, "Warning: hole in data (%d)\n", ret);
            }
             continue;
         }
 
-        if(fwrite(buf, 1, ret, out) != ret) {
+        if(channels > 2 && !raw) {
+          /* Then permute! */
+          permute_channels(buf, outbuf, ret, channels, bits/8);
+        }
+
+        if(fwrite(outbuf, 1, ret, out) != ret) {
             fprintf(stderr, "Error writing to file: %s\n", strerror(errno));
             ov_clear(&vf);
             return 1;



More information about the commits mailing list