shithub: opus-tools

Download patch

ref: dd0c7a7a4b588c8bf33ef7cb2a273a2694466599
parent: 74968644182334ede7044baf7717fa5da62b7f36
author: Mark Harris <[email protected]>
date: Sat Feb 8 11:41:33 EST 2014

Fix 8-bit AIFF input.

AIFF uses signed pcm for all sizes, whereas WAV is unsigned for 8-bit
and signed for other sizes.  For backward compatibility, continue to
use the WAV convention for raw input.

Signed-off-by: Gregory Maxwell <[email protected]>

--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -388,6 +388,7 @@
         aiff->samplesize = format.samplesize;
         aiff->totalsamples = format.totalframes;
         aiff->bigendian = bigendian;
+        aiff->unsigned8bit = 0;
 
         if(aiff->channels>3)
           fprintf(stderr,"WARNING: AIFF[-C] files with greater than three channels use\n"
@@ -586,6 +587,7 @@
         wav->f = in;
         wav->samplesread = 0;
         wav->bigendian = 0;
+        wav->unsigned8bit = format.samplesize == 8;
         wav->channels = format.channels; /* This is in several places. The price
                                             of trying to abstract stuff. */
         wav->samplesize = format.samplesize;
@@ -676,14 +678,27 @@
 
     if(f->samplesize==8)
     {
-        unsigned char *bufu = (unsigned char *)buf;
-        for(i = 0; i < realsamples; i++)
+        if(f->unsigned8bit)
         {
-            for(j=0; j < f->channels; j++)
+            unsigned char *bufu = (unsigned char *)buf;
+            for(i = 0; i < realsamples; i++)
             {
-                buffer[i*f->channels+j]=((int)(bufu[i*f->channels + ch_permute[j]])-128)/128.0f;
+                for(j=0; j < f->channels; j++)
+                {
+                    buffer[i*f->channels+j]=((int)(bufu[i*f->channels + ch_permute[j]])-128)/128.0f;
+                }
             }
         }
+        else
+        {
+            for(i = 0; i < realsamples; i++)
+            {
+                for(j=0; j < f->channels; j++)
+                {
+                    buffer[i*f->channels+j]=buf[i*f->channels + ch_permute[j]]/128.0f;
+                }
+            }
+        }
     }
     else if(f->samplesize==16)
     {
@@ -788,6 +803,7 @@
     wav->f =             in;
     wav->samplesread =   0;
     wav->bigendian =     opt->endianness;
+    wav->unsigned8bit =  format.samplesize == 8;
     wav->channels =      format.channels;
     wav->samplesize =    opt->samplesize;
     wav->totalsamples =  0;
--- a/src/opusenc.h
+++ b/src/opusenc.h
@@ -76,6 +76,7 @@
     opus_int64 samplesread;
     FILE *f;
     short bigendian;
+    short unsigned8bit;
     int *channel_permute;
 } wavfile;