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

Michael Smith msmith at xiph.org
Thu Nov 7 02:18:32 PST 2002



msmith      02/11/07 05:18:32

  Modified:    oggenc   audio.c audio.h encode.h oggenc.c
  Log:
  --scale option, to allow scaling the input (to help with clipping inputs,
  mostly).

Revision  Changes    Path
1.29      +45 -2     vorbis-tools/oggenc/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- audio.c	7 Nov 2002 09:21:54 -0000	1.28
+++ audio.c	7 Nov 2002 10:18:32 -0000	1.29
@@ -588,7 +588,7 @@
     int done;
 } resampler;
 
-long read_resampled(void *d, float **buffer, int samples)
+static long read_resampled(void *d, float **buffer, int samples)
 {
     resampler *rs = d;
     long in_samples;
@@ -667,10 +667,53 @@
 typedef struct {
     audio_read_func real_reader;
     void *real_readdata;
+    int channels;
+    float scale_factor;
+} scaler;
+
+static long read_scaler(void *data, float **buffer, int samples) {
+    scaler *d = data;
+    long in_samples = d->real_reader(d->real_readdata, buffer, samples);
+    int i,j;
+
+    for(i=0; i < d->channels; i++) {
+        for(j=0; j < in_samples; j++) {
+            buffer[i][j] *= d->scale_factor;
+        }
+    }
+
+    return in_samples;
+}
+
+
+void setup_scaler(oe_enc_opt *opt, float scale) {
+    scaler *d = calloc(1, sizeof(scaler));
+
+    d->real_reader = opt->read_samples;
+    d->real_readdata = opt->readdata;
+
+    opt->read_samples = read_scaler;
+    opt->readdata = d;
+    d->channels = opt->channels;
+    d->scale_factor = scale;
+}
+
+void clear_scaler(oe_enc_opt *opt) {
+    scaler *d = opt->readdata;
+
+    opt->read_samples = d->real_reader;
+    opt->readdata = d->real_readdata;
+
+    free(d);
+}
+
+typedef struct {
+    audio_read_func real_reader;
+    void *real_readdata;
     float **bufs;
 } downmix;
 
-long read_downmix(void *data, float **buffer, int samples)
+static long read_downmix(void *data, float **buffer, int samples)
 {
     downmix *d = data;
     long in_samples = d->real_reader(d->real_readdata, d->bufs, samples);

<p><p>1.8       +2 -0      vorbis-tools/oggenc/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/audio.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- audio.h	30 May 2002 12:13:22 -0000	1.7
+++ audio.h	7 Nov 2002 10:18:32 -0000	1.8
@@ -9,6 +9,8 @@
 void clear_resample(oe_enc_opt *opt);
 void setup_downmix(oe_enc_opt *opt);
 void clear_downmix(oe_enc_opt *opt);
+void setup_scaler(oe_enc_opt *opt, float scale);
+void clear_scaler(oe_enc_opt *opt);
 
 typedef struct
 {

<p><p>1.22      +3 -2      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- encode.h	12 Jul 2002 02:55:11 -0000	1.21
+++ encode.h	7 Nov 2002 10:18:32 -0000	1.22
@@ -78,10 +78,11 @@
 
         /* Float from 0 to 1 (low->high) */
         float quality;
-        int   quality_set;
+    int quality_set;
 
     int resamplefreq;
     int downmix;
+    float scale;
 
         unsigned int serial;
 } oe_options;
@@ -112,7 +113,7 @@
         int min_bitrate;
         int max_bitrate;
         float quality;
-        int quality_set;
+    int quality_set;
     adv_opt *advopt;
     int advopt_count;
 

<p><p>1.68      +24 -7     vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- oggenc.c	10 Aug 2002 16:53:23 -0000	1.67
+++ oggenc.c	7 Nov 2002 10:18:32 -0000	1.68
@@ -58,6 +58,7 @@
     {"managed", 0, 0, 0},
     {"resample",1,0,0},
     {"downmix", 0,0,0},
+    {"scale", 1, 0, 0}, 
     {"advanced-encode-option", 1, 0, 0},
         {NULL,0,0,0}
 };
@@ -77,7 +78,7 @@
         oe_options opt = {NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 
                           0, NULL, 0, NULL, 0, NULL, 0, 0, 0,16,44100,2, 0, NULL,
                           DEFAULT_NAMEFMT_REMOVE, DEFAULT_NAMEFMT_REPLACE, 
-			  NULL, 0, -1,-1,-1,.3,-1,0, 0,0}; 
+			  NULL, 0, -1,-1,-1,.3,-1,0, 0,0.f, 0}; 
 
         int i;
 
@@ -323,6 +324,12 @@
             }
         }
 
+        if(opt.scale > 0.f) {
+            setup_scaler(&enc_opts, opt.scale);
+            if(!opt.quiet)
+                fprintf(stderr, _("Scaling input to %f\n"), opt.scale);
+        }
+
 
                 if(!enc_opts.total_samples_per_channel)
                         enc_opts.progress_update = update_statistics_notime;
@@ -337,6 +344,8 @@
                 if(oe_encode(&enc_opts))
                         errors++;
 
+        if(opt.scale > 0)
+            clear_scaler(&enc_opts);
         if(opt.downmix)
             clear_downmix(&enc_opts);
         if(opt.resamplefreq)
@@ -556,12 +565,12 @@
                 {
                         case 0:
                 if(!strcmp(long_options[option_index].name, "managed")) {
-		  if(!opt->managed){
-                    if(!opt->quiet)
-		      fprintf(stderr, 
-			      _("Enabling bitrate management engine\n"));
-                    opt->managed = 1;
-		  }
+		            if(!opt->managed){
+                        if(!opt->quiet)
+            		        fprintf(stderr, 
+                                    _("Enabling bitrate management engine\n"));
+                        opt->managed = 1;
+        		    }
                 }
                 else if(!strcmp(long_options[option_index].name, 
                             "raw-endianness")) {
@@ -589,6 +598,14 @@
                 }
                 else if(!strcmp(long_options[option_index].name, "downmix")) {
                     opt->downmix = 1;
+                }
+                else if(!strcmp(long_options[option_index].name, "scale")) {
+                    opt->scale = atof(optarg);
+				    if(sscanf(optarg, "%f", &opt->scale) != 1) {
+                        opt->scale = 0;
+                        fprintf(stderr, _("Warning: Couldn't parse scaling factor \"%s\"\n"), 
+                                optarg);
+                    }
                 }
                 else if(!strcmp(long_options[option_index].name, "advanced-encode-option")) {
                     char *arg = strdup(optarg);

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