[xiph-cvs] cvs commit: vorbis-tools/oggenc/man oggenc.1

Michael Smith msmith at xiph.org
Sun May 27 02:49:37 PDT 2001



msmith      01/05/27 02:49:36

  Modified:    oggenc   audio.c audio.h encode.h oggenc.c
               oggenc/man oggenc.1
  Log:
  Add raw mode options and 8 bit support, contributed by
  Victoria E. Lease <vlease at floofy-skirts.org>
  
  Add to manpage and clarify raw mode use.

Revision  Changes    Path
1.11      +53 -31    vorbis-tools/oggenc/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- audio.c	2001/03/03 06:04:25	1.10
+++ audio.c	2001/05/27 09:49:35	1.11
@@ -297,6 +297,7 @@
                 aiff->f = in;
                 aiff->samplesread = 0;
                 aiff->channels = format.channels;
+		aiff->samplesize = format.samplesize;
                 aiff->totalsamples = format.totalframes;
                 aiff->bigendian = 1;
 
@@ -419,6 +420,7 @@
                 wav->bigendian = 0;
                 wav->channels = format.channels; /* This is in several places. The price
                                                                                         of trying to abstract stuff. */
+		wav->samplesize = format.samplesize;
 
                 if(len)
                 {
@@ -456,58 +458,60 @@
 long wav_read(void *in, float **buffer, int samples)
 {
         wavfile *f = (wavfile *)in;
-	signed char *buf = alloca(samples*2*f->channels);
-	long bytes_read = fread(buf, 1, samples*2*f->channels, f->f);
+	int sampbyte = f->samplesize / 8;
+	signed char *buf = alloca(samples*sampbyte*f->channels);
+	long bytes_read = fread(buf, 1, samples*sampbyte*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);
+			bytes_read/(sampbyte*f->channels) > f->totalsamples) 
+		bytes_read = sampbyte*f->channels*(f->totalsamples - f->samplesread);
+
+	realsamples = bytes_read/(sampbyte*f->channels);
         f->samplesread += realsamples;
                 
-	if(!f->bigendian)
+	if(f->samplesize==8)
         {
+		unsigned char *bufu = (unsigned char *)buf;
                 for(i = 0; i < realsamples; i++)
                 {
                         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;
+				buffer[j][i] = ( (int)(bufu[i*f->channels + j + 1]) - 128 ) 
+					/ 255.0f ;
                         }
                 }
         }
         else
         {
-		for(i = 0; i < realsamples; i++)
+		if(!f->bigendian)
                 {
-			for(j=0; j < f->channels; j++)
+			for(i = 0; i < realsamples; i++)
                         {
-				buffer[j][i]=((buf[i*2*f->channels + 2*j]<<8) |
-						      (buf[i*2*f->channels + 2*j + 1] & 0xff))/32768.0f;
+				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;
+				}
                         }
                 }
+		else
+		{
+			for(i = 0; i < realsamples; i++)
+			{
+				for(j=0; j < f->channels; j++)
+				{
+					buffer[j][i]=((buf[i*2*f->channels + 2*j]<<8) |
+							      (buf[i*2*f->channels + 2*j + 1] & 0xff))/32768.0f;
+				}
+			}
+		}
         }
 
         return realsamples;
 }
 
-long raw_read_stereo(void *in, float **buffer, int samples)
-{
-	signed char *buf = alloca(samples*4);
-	long bytes_read = fread(buf,1,samples*4, (FILE *)in);
-	int i;
-
-	for(i=0;i<bytes_read/4; i++)
-	{
-		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_ieee_read(void *in, float **buffer, int samples)
 {
         wavfile *f = (wavfile *)in;
@@ -540,10 +544,28 @@
 
 int raw_open(FILE *in, oe_enc_opt *opt)
 {
-	opt->rate = 44100; /* we assume this */
-	opt->channels = 2;
-	opt->readdata = (void *)in;
-	opt->read_samples = raw_read_stereo; /* it's the same, currently */
+	wav_fmt format; /* fake wave header ;) */
+	wavfile *wav = malloc(sizeof(wavfile));
+
+	if(opt->rate != 44100)
+		fprintf(stderr,"Warning: Vorbis is currently untuned for input\n"
+				       "at other than 44.1kHz, quality may be degraded.\n");
+
+	/* construct fake wav header ;) */
+	format.format =      2; 
+	format.channels =    opt->channels;
+	format.samplerate =  opt->rate;
+	format.samplesize =  opt->samplesize;
+	format.bytespersec = opt->channels * opt->rate * opt->samplesize / 8;
+	format.align =       format.bytespersec;
+	wav->f =             in;
+	wav->samplesread =   0;
+	wav->bigendian =     0;
+	wav->channels =      format.channels;
+	wav->samplesize =    opt->samplesize;
+
+	opt->read_samples = wav_read;
+	opt->readdata = (void *)wav;
         opt->total_samples_per_channel = 0; /* raw mode, don't bother */
         return 1;
 }

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

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- audio.h	2001/02/19 08:36:53	1.5
+++ audio.h	2001/05/27 09:49:35	1.6
@@ -27,6 +27,7 @@
 
 typedef struct {
         short channels;
+	short samplesize;
         long totalsamples;
         long samplesread;
         FILE *f;

1.7       +5 -0      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- encode.h	2000/12/24 06:34:44	1.6
+++ encode.h	2001/05/27 09:49:35	1.7
@@ -43,7 +43,11 @@
         int date_count;
 
         int quiet;
+
         int rawmode;
+	int raw_samplesize;
+	int raw_samplerate;
+	int raw_channels;
 
         char *namefmt;
         char *outfile;
@@ -66,6 +70,7 @@
         long total_samples_per_channel;
         int channels;
         long rate;
+	int samplesize;
         int bitrate;
 
         FILE *out;

1.14      +51 -2     vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- oggenc.c	2001/02/20 08:12:50	1.13
+++ oggenc.c	2001/05/27 09:49:35	1.14
@@ -35,6 +35,9 @@
         {"output",1,0,'o'},
         {"version",0,0,'v'},
         {"raw",0,0,'r'},
+	{"raw-bits",1,0,'B'},
+	{"raw-chan",1,0,'C'},
+	{"raw-rate",1,0,'R'},
         {"bitrate",1,0,'b'},
         {"date",1,0,'d'},
         {"tracknum",1,0,'N'},
@@ -51,7 +54,7 @@
 int main(int argc, char **argv)
 {
         oe_options opt = {NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 
-		0,0, NULL,NULL,128,0}; /* Default values */
+		0, 0,16,44100,2, NULL,NULL,128,0}; /* Default values */
         int i;
 
         char **infiles;
@@ -149,6 +152,9 @@
 
                 if(opt.rawmode)
                 {
+			enc_opts.rate=opt.raw_samplerate;
+			enc_opts.channels=opt.raw_channels;
+			enc_opts.samplesize=opt.raw_samplesize;
                         raw_open(in, &enc_opts);
                         foundformat=1;
                 }
@@ -266,6 +272,9 @@
                 " -q, --quiet          Produce no output to stderr\n"
                 " -h, --help           Print this help text\n"
                 " -r, --raw            Raw mode. Input files are read directly as PCM data\n"
+		" -B, --raw-bits=n     Set bits/sample for raw input. Default is 16\n"
+		" -C, --raw-chan=n     Set number of channels for raw input. Default is 2\n"
+		" -R, --raw-rate=n     Set samples/sec for raw input. Default is 44100\n"
                 " -b, --bitrate        Choose a bitrate to encode at. Internally,\n"
                 "                      a mode approximating this value is chosen.\n"
                 "                      Takes an argument in kbps. Default is 128kbps\n"
@@ -377,7 +386,7 @@
         int ret;
         int option_index = 1;
 
-	while((ret = getopt_long(argc, argv, "a:b:c:d:hl:n:N:o:qrs:t:v", 
+	while((ret = getopt_long(argc, argv, "a:b:B:c:C:d:hl:n:N:o:qrR:s:t:v", 
                                         long_options, &option_index)) != -1)
         {
                 switch(ret)
@@ -445,9 +454,49 @@
                                 fprintf(stderr, VERSION_STRING);
                                 exit(0);
                                 break;
+			case 'B':
+				if (opt->rawmode != 1)
+				{
+					opt->rawmode = 1;
+					fprintf(stderr, "WARNING: Raw bits/sample specified for non-raw data. Assuming input is raw.\n");
+				}
+				if(sscanf(optarg, "%u", &opt->raw_samplesize) != 1)
+				{
+					opt->raw_samplesize = 16; /* Failed, so just set to 16 */
+					fprintf(stderr, "WARNING: Invalid bits/sample specified, assuming 16.\n");
+				}
+				if((opt->raw_samplesize != 8) && (opt->raw_samplesize != 16))
+				{
+					fprintf(stderr, "WARNING: Invalid bits/sample specified, assuming 16.\n");
+				}
+				break;
+			case 'C':
+				if (opt->rawmode != 1)
+				{
+					opt->rawmode = 1;
+					fprintf(stderr, "WARNING: Raw channel count specified for non-raw data. Assuming input is raw.\n");
+				}
+				if(sscanf(optarg, "%u", &opt->raw_channels) != 1)
+				{
+					opt->raw_channels = 2; /* Failed, so just set to 2 */
+					fprintf(stderr, "WARNING: Invalid channel count specified, assuming 2.\n");
+				}
+				break;
                         case 'N':
                                 opt->tracknum = realloc(opt->tracknum, (++opt->track_count)*sizeof(char *));
                                 opt->tracknum[opt->track_count - 1] = strdup(optarg);
+				break;
+			case 'R':
+				if (opt->rawmode != 1)
+				{
+					opt->rawmode = 1;
+					fprintf(stderr, "WARNING: Raw samplerate specified for non-raw data. Assuming input is raw.\n");
+				}
+				if(sscanf(optarg, "%u", &opt->raw_samplerate) != 1)
+				{
+					opt->raw_samplerate = 44100; /* Failed, so just set to 44100 */
+					fprintf(stderr, "WARNING: Invalid samplerate specified, assuming 44100.\n");
+				}
                                 break;
                         case '?':
                                 fprintf(stderr, "WARNING: Unknown option specified, ignoring->\n");

1.4       +9 -2      vorbis-tools/oggenc/man/oggenc.1

Index: oggenc.1
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/man/oggenc.1,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- oggenc.1	2001/02/26 05:42:25	1.3
+++ oggenc.1	2001/05/27 09:49:36	1.4
@@ -63,8 +63,15 @@
 .IP "-h, --help"
 Show command help.
 .IP "-r, --raw"
-Assume input data is raw 44.1 kHz, 16 bit, little-endian audio data with no
-header information.
+Assume input data is raw little-endian audio data with no
+header information. If other options are not specified, defaults to 44.1kHz
+stereo 16 bit. See next three options for how to change this.
+.IP "-B n, --raw-bits=n"
+Sets raw input bits/sample rate. Default is 16
+.IP "-C n, --raw-chan=n"
+Sets raw input number of channels. Default is 2
+.IP "-R n, --raw-rate=n"
+Sets raw input samplerate. Default is 44100
 .IP "-q, --quiet"
 Quiet mode.  No messages are displayed.
 .IP "-b n, --bitrate=n"

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