[xiph-cvs] cvs commit: vorbis-tools/oggenc audio.c audio.h platform.h

Michael Smith msmith at xiph.org
Fri Dec 29 21:04:42 PST 2000



msmith      00/12/29 21:04:42

  Modified:    oggenc   audio.c audio.h platform.h
  Log:
  Cleanup some audio code (allows > 2 channel wav files now, if they exist).
  Solaris include fix.

Revision  Changes    Path
1.7       +23 -37    vorbis-tools/oggenc/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- audio.c	2000/12/24 06:17:40	1.6
+++ audio.c	2000/12/30 05:04:41	1.7
@@ -168,7 +168,6 @@
                 return 0; /* EOF */
 
         if( format.format == 1 &&
-		(format.channels == 2 || format.channels == 1) &&
                 format.align == format.channels*2 && /* We could deal with this one pretty easily */
                 format.samplesize == 16)
         {
@@ -180,13 +179,12 @@
                    now we want to find the size of the file */
                 opt->rate = format.samplerate;
                 opt->channels = format.channels;
-		if(opt->channels ==2)
-			opt->read_samples = wav_read_stereo;
-		else
-			opt->read_samples = wav_read_mono;
+		opt->read_samples = wav_read;
 
                 wav->f = in;
                 wav->samplesread = 0;
+		wav->channels = format.channels; /* This is in several places. The price
+											of trying to abstract stuff. */
 
                 if(len)
                 {
@@ -219,25 +217,31 @@
         }
 }
 
-long wav_read_stereo(void *in, float **buffer, int samples)
+long wav_read(void *in, float **buffer, int samples)
 {
-	signed char *buf = alloca(samples*4);
         wavfile *f = (wavfile *)in;
-	long bytes_read = fread(buf, 1, samples*4, f->f);
-	int i;
-
-	if(f->totalsamples && f->samplesread + bytes_read/4 > f->totalsamples)
-		bytes_read = 4*(f->totalsamples - f->samplesread);
-	f->samplesread += bytes_read/4;
+	signed char *buf = alloca(samples*2*f->channels);
+	long bytes_read = fread(buf, 1, samples*2*f->channels, f->f);
+	int i,j;
+	long realsamples;
+
+	if(f->totalsamples && f->samplesread + 
+			bytes_read/(2*f->channels) > f->totalsamples) 
+		bytes_read = 2*f->channels*(f->totalsamples - f->samplesread);
+	realsamples = bytes_read/(2*f->channels);
+	f->samplesread += realsamples;
                 
 
-	for(i = 0; i < bytes_read/4; i++)
+	for(i = 0; i < realsamples; i++)
         {
-		buffer[0][i] = ((buf[i*4+1]<<8) | (((int)buf[i*4]) & 0xff))/32768.0;
-		buffer[1][i] = ((buf[i*4+3]<<8) | (((int)buf[i*4+2]) & 0xff))/32768.0;
+		for(j=0; j < f->channels; j++)
+		{
+			buffer[j][i] = ((buf[i*2*f->channels + 2*j + 1]<<8) |
+					        (buf[i*2*f->channels + 2*j] & 0xff))/32768.0f;
+		}
         }
 
-	return bytes_read/4;
+	return realsamples;
 }
 
 long raw_read_stereo(void *in, float **buffer, int samples)
@@ -248,29 +252,11 @@
 
         for(i=0;i<bytes_read/4; i++)
         {
-		buffer[0][i] = ((buf[i*4+1]<<8) | (((int)buf[i*4]) & 0xff))/32768.0;
-		buffer[1][i] = ((buf[i*4+3]<<8) | (((int)buf[i*4+2]) & 0xff))/32768.0;
+		buffer[0][i] = ((buf[i*4+1]<<8) | (((int)buf[i*4]) & 0xff))/32768.0f;
+		buffer[1][i] = ((buf[i*4+3]<<8) | (((int)buf[i*4+2]) & 0xff))/32768.0f;
         }
 
         return bytes_read/4;
-}
-
-long wav_read_mono(void *in, float **buffer, int samples)
-{
-	signed char *buf = alloca(samples*2);
-	wavfile *f = (wavfile *)in;
-	long bytes_read = fread(buf, 1, samples*2, f->f);
-	int i;
-
-	if(f->totalsamples && f->samplesread + bytes_read/2 > f->totalsamples)
-		bytes_read = 2*(f->totalsamples - f->samplesread);
-	f->samplesread += bytes_read/2;
-
-
-	for(i=0;i<bytes_read/2; i++)
-		buffer[0][i] = ((buf[i*2+1]<<8) | (((int)buf[i*2]) & 0xff))/32768.0;
-
-	return bytes_read/2;
 }
 
 void wav_close(void *info)

1.3       +2 -2      vorbis-tools/oggenc/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- audio.h	2000/11/30 06:04:45	1.2
+++ audio.h	2000/12/30 05:04:41	1.3
@@ -26,6 +26,7 @@
 } wav_fmt;
 
 typedef struct {
+	int channels;
         long totalsamples;
         long samplesread;
         FILE *f;
@@ -39,8 +40,7 @@
 void wav_close(void *);
 void raw_close(void *);
 
-long wav_read_stereo(void *, float **buffer, int samples);
-long wav_read_mono(void *, float **buffer, int samples);
+long wav_read(void *, float **buffer, int samples);
 long raw_read_stereo(void *, float **buffer, int samples);
 
 #endif /* __AUDIO_H */

1.3       +1 -0      vorbis-tools/oggenc/platform.h

Index: platform.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/platform.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- platform.h	2000/12/24 06:17:40	1.2
+++ platform.h	2000/12/30 05:04:41	1.3
@@ -5,6 +5,7 @@
 
 #ifdef __sun__ /* Right way to do this? */
 #include <alloca.h>
+#include <malloc.h>
 #endif
 
 #ifdef __OS2__

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list