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