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

Michael Smith msmith at xiph.org
Sat Nov 4 02:04:58 PST 2000



msmith      00/11/04 02:04:58

  Modified:    oggenc   audio.c encode.c encode.h oggenc.c
  Log:
  Changes for the new vorbisenc API.
  Misc. bugfixes for really obscure bugs.
  New version number for beta3.

Revision  Changes    Path
1.2       +6 -3      vorbis-tools/oggenc/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio.c	2000/09/07 00:57:46	1.1
+++ audio.c	2000/11/04 10:04:58	1.2
@@ -45,11 +45,14 @@
                         {
                                 /* seek failed. Do it the hard way */
                                 unsigned char buf2[1024];
-				int seek_needed = *len;
+				int seek_needed = *len, seeked;
                                 while(seek_needed>0)
                                 {
-					fread(buf2,1,seek_needed>1024?1024:seek_needed,in);
-					seek_needed -= 1024;
+					seeked = fread(buf2,1,seek_needed>1024?1024:seek_needed,in);
+					if(!seeked)
+						return 0; /* Couldn't read more, can't read file */
+					else
+						seek_needed -= seeked;
                                 }
                         }
                         buf[4] = 0;

1.6       +26 -8     vorbis-tools/oggenc/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- encode.c	2000/09/27 14:16:01	1.5
+++ encode.c	2000/11/04 10:04:58	1.6
@@ -14,7 +14,7 @@
 #include <math.h>
 
 #include "platform.h"
-#include <vorbis/codec.h>
+#include <vorbis/vorbisenc.h>
 #include "encode.h"
 
 
@@ -32,10 +32,12 @@
 
         vorbis_dsp_state vd;
         vorbis_block     vb;
+	vorbis_info      vi;
 
         long samplesdone=0;
     int eos;
         long bytes_written = 0, packetsdone=0;
+	double time_elapsed;
 
         TIMER *timer;
 
@@ -43,11 +45,17 @@
         /* get start time. */
         timer = timer_start();
 
+	/* Have vorbisenc choose a mode for us */
+	vorbis_info_init(&vi);
+	vorbis_encode_init(&vi, opt->channels, opt->rate, -1, 
+			opt->bitrate*1000, -1);
+
+
         /* Now, set up the analysis engine, stream encoder, and other
            preparation before the encoding begins.
          */
 
-	vorbis_analysis_init(&vd,opt->mode);
+	vorbis_analysis_init(&vd,&vi);
         vorbis_block_init(&vd,&vb);
 
         ogg_stream_init(&os, opt->serialno);
@@ -94,7 +102,7 @@
                         samplesdone += samples_read;
 
                         /* Call progress update every 10 pages */
-			if(!opt->quiet && packetsdone>=10)
+			if(packetsdone>=10)
                         {
                                 double time;
 
@@ -144,12 +152,10 @@
 
         vorbis_block_clear(&vb);
         vorbis_dsp_clear(&vd);
+	vorbis_info_clear(&vi);
 
-	if(!opt->quiet)
-	{
-		double time_elapsed = timer_time(timer);
-		opt->end_encode(opt->filename, time_elapsed, opt->rate, samplesdone, bytes_written);
-	}
+	time_elapsed = timer_time(timer);
+	opt->end_encode(opt->filename, time_elapsed, opt->rate, samplesdone, bytes_written);
 
         timer_clear(timer);
 
@@ -211,5 +217,17 @@
         fprintf(stderr, "\tAverage bitrate: %.1f kb/s\n\n", 
                 8./1000.*((double)bytes/((double)samples/(double)rate)));
 }
+
+void final_statistics_null(char *fn, double time, int rate, long samples, 
+		long bytes)
+{
+	/* Don't do anything, this is just a placeholder function for quiet mode */
+}
+
+void update_statistics_null(char *fn, long total, long done, double time)
+{
+	/* So is this */
+}
+
 
 

1.3       +5 -11     vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- encode.h	2000/09/07 15:10:49	1.2
+++ encode.h	2000/11/04 10:04:58	1.3
@@ -19,17 +19,12 @@
 
 void update_statistics_full(char *fn, long total, long done, double time);
 void update_statistics_notime(char *fn, long total, long done, double time);
+void update_statistics_null(char *fn, long total, long done, double time);
 void final_statistics(char *fn, double time, int rate, long total_samples,
                 long bytes);
+void final_statistics_null(char *fn, double time, int rate, long total_samples,
+		long bytes);
 
-typedef struct _taglist
-{
-	char *tag;
-	char *contents;
-
-	struct _taglist *next;
-} taglist;
-	
 typedef struct
 {
         char **title;
@@ -50,13 +45,12 @@
 
         char *namefmt;
         char *outfile;
-	int modenum;
+	int kbps;
 } oe_options;
 
 typedef struct
 {
         vorbis_comment *comments;
-	vorbis_info    *mode;
         long serialno;
 
         audio_read_func read_samples;
@@ -68,9 +62,9 @@
         long total_samples_per_channel;
         int channels;
         long rate;
+	int bitrate;
 
         FILE *out;
-	int quiet;
         char *filename;
 } oe_enc_opt;
 

1.3       +15 -55    vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- oggenc.c	2000/09/07 15:10:49	1.2
+++ oggenc.c	2000/11/04 10:04:58	1.3
@@ -17,11 +17,10 @@
 #include <time.h>
 
 #include "platform.h"
-#include <vorbis/modes.h>
 #include "encode.h"
 #include "audio.h"
 
-#define VERSION_STRING "OggEnc v0.5\n"
+#define VERSION_STRING "OggEnc v0.5 (libvorbis beta3)\n"
 #define CHUNK 4096 /* We do reads, etc. in multiples of this */
 
 /* Define supported formats here */
@@ -41,7 +40,7 @@
         {"output",1,0,'o'},
         {"version",0,0,'v'},
         {"raw",0,0,'r'},
-	{"mode",1,0,'m'},
+	{"bitrate",1,0,'b'},
         {"date",1,0,'d'},
         {"tracknum",1,0,'N'},
         {NULL,0,0,0}
@@ -52,12 +51,11 @@
 void build_comments(vorbis_comment *vc, oe_options *opt, int filenum, 
                 char **artist, char **album, char **title, char **tracknum, char **date);
 void usage(void);
-vorbis_info *choose_mode(int modenum, int channels);
 
 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,0}; /* Default values */
+		0,0, NULL,NULL,160}; /* Default values */
         int i;
 
         char **infiles;
@@ -116,7 +114,6 @@
                 /* Set various encoding defaults */
 
                 enc_opts.serialno = nextserial++;
-		enc_opts.quiet = opt.quiet;
                 enc_opts.progress_update = update_statistics_full;
                 enc_opts.end_encode = final_statistics;
                 
@@ -200,6 +197,7 @@
                 enc_opts.out = out;
                 enc_opts.comments = &vc;
                 enc_opts.filename = out_fn;
+		enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
 
                 /* Now, we need to select an input audio format */
 
@@ -228,17 +226,18 @@
                         continue;
                 }
 
-		enc_opts.mode = choose_mode(opt.modenum, enc_opts.channels);
                 if(!enc_opts.total_samples_per_channel)
                         enc_opts.progress_update = update_statistics_notime;
 
-		if(!opt.quiet)
-			fprintf(stderr, "Encoding using encoder mode %d\n", opt.modenum?opt.modenum:3);
+		if(opt.quiet)
+		{
+			enc_opts.progress_update = update_statistics_null;
+			enc_opts.end_encode = final_statistics_null;
+		}
 
                 oe_encode(&enc_opts);
 
                 if(out_fn) free(out_fn);
-		free(enc_opts.mode);
                 vorbis_comment_clear(&vc);
                 if(!opt.rawmode)
                         formats[j].close_func(enc_opts.readdata);
@@ -266,8 +265,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"
-		" -m, --mode           Select encoding mode, takes an argument between 1 and 6\n"
-		"                      The default is mode 3. Higher numbers are higher quality.\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 160kbps\n"
                 "\n"
                 " Naming:\n"
                 " -o, --output=fn      Write file to fn (only valid in single-file mode)\n"
@@ -373,7 +373,7 @@
         int ret;
         int option_index = 1;
 
-	while((ret = getopt_long(argc, argv, "a:c:d:hl:m:n:N:o:qrt:v", 
+	while((ret = getopt_long(argc, argv, "a:b:c:d:hl:n:N:o:qrt:v", 
                                         long_options, &option_index)) != -1)
         {
                 switch(ret)
@@ -402,8 +402,8 @@
                                 opt->title = realloc(opt->title, (++opt->title_count)*sizeof(char *));
                                 opt->title[opt->title_count - 1] = strdup(optarg);
                                 break;
-			case 'm':
-				opt->modenum = atoi(optarg);
+			case 'b':
+				opt->kbps = atoi(optarg);
                                 break;
                         case 'n':
                                 if(opt->namefmt)
@@ -517,44 +517,4 @@
         }
 }
 
-vorbis_info *choose_mode(int modenum, int channels)
-{
-	vorbis_info *mode = malloc(sizeof(vorbis_info));
-
-	if(modenum > 6 || modenum < 0)
-		fprintf(stderr, "Warning: Unrecognised mode (choose from 1-6), defaulting to mode B (3)\n");
-
-	switch(modenum)
-	{
-	case 0:
-		memcpy(mode, &info_B, sizeof(vorbis_info)); /* Default */
-		break;
-	case 1:
-		fprintf(stderr, "Warning: mode AA (1) is not yet implemented. Increasing to mode A (2)\n");
-		memcpy(mode, &info_A, sizeof(vorbis_info)); 
-		break;
-	case 2:
-		memcpy(mode, &info_A, sizeof(vorbis_info)); 
-		break;
-	case 3:
-		memcpy(mode, &info_B, sizeof(vorbis_info)); 
-		break;
-	case 4:
-		memcpy(mode, &info_C, sizeof(vorbis_info)); 
-		break;
-	case 5:
-		memcpy(mode, &info_D, sizeof(vorbis_info)); 
-		break;
-	case 6:
-		memcpy(mode, &info_E, sizeof(vorbis_info)); 
-		break;
-	default:
-		memcpy(mode, &info_B, sizeof(vorbis_info)); 
-	}
-
-	if(channels ==1)
-		mode->channels = 1; /* Edit the mode struct to reflect 
-							   mono rather than stereo */
-	return mode;
-}
 

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