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

Michael Smith msmith at xiph.org
Mon Feb 19 00:36:53 PST 2001



msmith      01/02/19 00:36:53

  Modified:    oggenc   audio.c audio.h
  Log:
  Type 3 (floating point PCM) wav reading code.
  Thanks to 'kode54' for this.

Revision  Changes    Path
1.9       +51 -7     vorbis-tools/oggenc/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- audio.c	2001/01/15 13:27:32	1.8
+++ audio.c	2001/02/19 08:36:52	1.9
@@ -336,6 +336,7 @@
 {
         unsigned char buf[16];
         unsigned int len;
+	int samplesize;
         wav_fmt format;
         wavfile *wav = malloc(sizeof(wavfile));
 
@@ -370,10 +371,29 @@
         if(!find_wav_chunk(in, "data", &len))
                 return 0; /* EOF */
 
-	if( format.format == 1 &&
-		format.align == format.channels*2 && /* We could deal with this one pretty easily */
-		format.samplesize == 16)
+	if(format.format == 1)
         {
+		samplesize = 2;
+		opt->read_samples = wav_read;
+	}
+	else if(format.format == 3)
+	{
+		samplesize = 4;
+		opt->read_samples = wav_ieee_read;
+	}
+	else
+	{
+		fprintf(stderr, 
+				"ERROR: Wav file is unsupported type (must be standard PCM\n"
+				" or type 3 floating point PCM\n");
+		return 0;
+	}
+
+
+
+	if( format.align == format.channels*samplesize &&
+		format.samplesize == 8*samplesize)
+	{
                 if(format.samplerate != 44100)
                         fprintf(stderr, "Warning: Vorbis is currently not tuned for input\n"
                                                         " at other than 44.1kHz. Quality may be somewhat\n"
@@ -382,7 +402,6 @@
                    now we want to find the size of the file */
                 opt->rate = format.samplerate;
                 opt->channels = format.channels;
-		opt->read_samples = wav_read;
 
                 wav->f = in;
                 wav->samplesread = 0;
@@ -392,8 +411,8 @@
 
                 if(len)
                 {
-			opt->total_samples_per_channel = len/(format.channels*2);
-			wav->totalsamples = len/(format.channels*2);
+			opt->total_samples_per_channel = len/(format.channels*samplesize);
+			wav->totalsamples = len/(format.channels*samplesize);
                 }
                 else
                 {
@@ -416,7 +435,9 @@
         }
         else
         {
-		fprintf(stderr, "ERROR: Wav file is unsupported subformat (must be 44.1kHz/16bit, this is %f/%dbit, %s)\n", (double)format.samplerate/1000, format.samplesize, (format.channels ==1)?"mono":"stereo");
+		fprintf(stderr, 
+				"ERROR: Wav file is unsupported subformat (must be 16 bit PCM\n"
+				"or floating point PCM\n");
                 return 0;
         }
 }
@@ -475,6 +496,29 @@
 
         return bytes_read/4;
 }
+
+long wav_ieee_read(void *in, float **buffer, int samples)
+{
+	wavfile *f = (wavfile *)in;
+	float *buf = alloca(samples*4*f->channels); /* de-interleave buffer */
+	long bytes_read = fread(buf,1,samples*4*f->channels, f->f);
+	int i,j;
+	long realsamples;
+
+
+	if(f->totalsamples && f->samplesread +
+			bytes_read/(4*f->channels) > f->totalsamples)
+		bytes_read = 4*f->channels*(f->totalsamples - f->samplesread);
+	realsamples = bytes_read/(4*f->channels);
+	f->samplesread += realsamples;
+
+	for(i=0; i < realsamples; i++)
+		for(j=0; j < f->channels; j++)
+			buffer[j][i] = buf[i*f->channels + j];
+
+	return realsamples;
+}
+
 
 void wav_close(void *info)
 {

1.5       +1 -0      vorbis-tools/oggenc/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- audio.h	2001/01/15 13:27:32	1.4
+++ audio.h	2001/02/19 08:36:53	1.5
@@ -55,6 +55,7 @@
 void raw_close(void *);
 
 long wav_read(void *, float **buffer, int samples);
+long wav_ieee_read(void *, float **buffer, int samples);
 long raw_read_stereo(void *, float **buffer, int samples);
 
 #endif /* __AUDIO_H */

--- >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