Commit 7706a8c2 authored by Michael Smith's avatar Michael Smith

--scale option, to allow scaling the input (to help with clipping inputs,

mostly).

svn path=/trunk/vorbis-tools/; revision=4089
parent 87bb0d8e
......@@ -588,7 +588,7 @@ typedef struct {
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;
......@@ -664,13 +664,56 @@ void clear_resample(oe_enc_opt *opt) {
free(rs);
}
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);
......
......@@ -9,6 +9,8 @@ int setup_resample(oe_enc_opt *opt);
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
{
......
......@@ -78,10 +78,11 @@ typedef struct
/* 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 @@ typedef struct
int min_bitrate;
int max_bitrate;
float quality;
int quality_set;
int quality_set;
adv_opt *advopt;
int advopt_count;
......
......@@ -58,6 +58,7 @@ struct option long_options[] = {
{"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 @@ int main(int argc, char **argv)
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 @@ int main(int argc, char **argv)
}
}
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 @@ int main(int argc, char **argv)
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 @@ static void parse_options(int argc, char **argv, oe_options *opt)
{
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")) {
......@@ -590,6 +599,14 @@ static void parse_options(int argc, char **argv, oe_options *opt)
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);
char *val;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment