| @@ -1,5 +1,5 @@ |
| 1 | 1 | /* |
| 2 | | −** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 2 | +** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 3 | 3 | ** |
| 4 | 4 | ** This program is free software; you can redistribute it and/or modify |
| 5 | 5 | ** it under the terms of the GNU General Public License as published by |
| @@ -34,7 +34,7 @@ · 28 unmodified lines |
| 34 | 34 | #define BUFFER_LEN 4096 /*-(1<<16)-*/ |
| 35 | 35 | |
| 36 | 36 | static void usage_exit (const char *progname) ; |
| 37 | | −static sf_count_t sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain) ; |
| 37 | +static sf_count_t sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain, int normalize) ; |
| 38 | 38 | static double apply_gain (float * data, long frames, int channels, double max, double gain) ; |
| 39 | 39 | |
| 40 | 40 | int |
| @@ -42,6 +42,7 @@ main (int argc, char *argv []) · 1 unmodified line |
| 42 | 42 | { SNDFILE *infile, *outfile = NULL ; |
| 43 | 43 | SF_INFO sfinfo ; |
| 44 | 44 | |
| 45 | + int normalize = 1 ; |
| 45 | 46 | sf_count_t count ; |
| 46 | 47 | double src_ratio = -1.0, gain = 1.0 ; |
| 47 | 48 | int new_sample_rate = -1, k, converter, max_speed = SF_FALSE ; |
| @@ -69,6 +70,8 @@ main (int argc, char *argv []) · 21 unmodified lines |
| 69 | 70 | for (k = 1 ; k < argc - 2 ; k++) |
| 70 | 71 | { if (strcmp (argv [k], "--max-speed") == 0) |
| 71 | 72 | max_speed = SF_TRUE ; |
| 73 | + else if (strcmp (argv [k], "--no-normalize") == 0) |
| 74 | + normalize = 0 ; |
| 72 | 75 | else if (strcmp (argv [k], "-to") == 0) |
| 73 | 76 | { k ++ ; |
| 74 | 77 | new_sample_rate = atoi (argv [k]) ; |
| @@ -160,7 +163,7 @@ main (int argc, char *argv []) · 85 unmodified lines |
| 160 | 163 | |
| 161 | 164 | sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ; |
| 162 | 165 | |
| 163 | | − count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ; |
| 166 | + count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain, normalize) ; |
| 164 | 167 | } |
| 165 | 168 | while (count < 0) ; |
| 166 | 169 | |
| @@ -176,7 +179,7 @@ main (int argc, char *argv []) · 9 unmodified lines |
| 176 | 179 | */ |
| 177 | 180 | |
| 178 | 181 | static sf_count_t |
| 179 | | −sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain) |
| 182 | +sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain, int normalize) |
| 180 | 183 | { static float input [BUFFER_LEN] ; |
| 181 | 184 | static float output [BUFFER_LEN] ; |
| 182 | 185 | |
| @@ -239,7 +242,7 @@ sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double sr · 56 unmodified lines |
| 239 | 242 | |
| 240 | 243 | src_delete (src_state) ; |
| 241 | 244 | |
| 242 | | − if (max > 1.0) |
| 245 | + if (normalize && max > 1.0) |
| 243 | 246 | { *gain = 1.0 / max ; |
| 244 | 247 | printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ; |
| 245 | 248 | return -1 ; |
| @@ -301,6 +304,9 @@ usage_exit (const char *progname) · 55 unmodified lines |
| 301 | 304 | for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++) |
| 302 | 305 | printf (" %d : %s%s\n", k, cptr, k == DEFAULT_CONVERTER ? " (default)" : "") ; |
| 303 | 306 | |
| 307 | + puts ("\n" |
| 308 | + " The --no-normalize option disables clipping check and normalization.") ; |
| 309 | + |
| 304 | 310 | puts ("") ; |
| 305 | 311 | |
| 306 | 312 | exit (1) ; |