| @@ -1,5 +1,5 @@ |
| 1 | 1 | /* |
| 2 | | −** Copyright (C) 2002-2009 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 2 | +** Copyright (C) 2002-2010 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 |
| @@ -39,7 +39,7 @@ static double apply_gain (float * data, long frames, int channels, double max, d · 33 unmodified lines |
| 39 | 39 | |
| 40 | 40 | int |
| 41 | 41 | main (int argc, char *argv []) |
| 42 | | −{ SNDFILE *infile, *outfile ; |
| 42 | +{ SNDFILE *infile, *outfile = NULL ; |
| 43 | 43 | SF_INFO sfinfo ; |
| 44 | 44 | |
| 45 | 45 | sf_count_t count ; |
| @@ -137,28 +137,31 @@ main (int argc, char *argv []) · 91 unmodified lines |
| 137 | 137 | /* Delete the output file length to zero if already exists. */ |
| 138 | 138 | remove (argv [argc - 1]) ; |
| 139 | 139 | |
| 140 | | − if ((outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL) |
| 141 | | − { printf ("Error : Not able to open output file '%s'\n", argv [argc - 1]) ; |
| 142 | | − sf_close (infile) ; |
| 143 | | − exit (1) ; |
| 144 | | − } ; |
| 145 | | − |
| 146 | | − if (max_speed) |
| 147 | | − { /* This is mainly for the comparison program tests/src-evaluate.c */ |
| 148 | | − sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; |
| 149 | | − } |
| 150 | | − else |
| 151 | | − { /* Update the file header after every write. */ |
| 152 | | − sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; |
| 153 | | − } ; |
| 154 | | − |
| 155 | | − sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ; |
| 156 | | − |
| 157 | 140 | printf ("Output file : %s\n", argv [argc - 1]) ; |
| 158 | 141 | printf ("Sample Rate : %d\n", sfinfo.samplerate) ; |
| 159 | 142 | |
| 160 | 143 | do |
| 144 | + { sf_close (outfile) ; |
| 145 | + |
| 146 | + if ((outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL) |
| 147 | + { printf ("Error : Not able to open output file '%s'\n", argv [argc - 1]) ; |
| 148 | + sf_close (infile) ; |
| 149 | + exit (1) ; |
| 150 | + } ; |
| 151 | + |
| 152 | + if (max_speed) |
| 153 | + { /* This is mainly for the comparison program tests/src-evaluate.c */ |
| 154 | + sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; |
| 155 | + } |
| 156 | + else |
| 157 | + { /* Update the file header after every write. */ |
| 158 | + sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; |
| 159 | + } ; |
| 160 | + |
| 161 | + sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ; |
| 162 | + |
| 161 | 163 | count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ; |
| 164 | + } |
| 162 | 165 | while (count < 0) ; |
| 163 | 166 | |
| 164 | 167 | printf ("Output Frames : %ld\n\n", (long) count) ; |
| @@ -239,8 +242,6 @@ sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double sr · 74 unmodified lines |
| 239 | 242 | if (max > 1.0) |
| 240 | 243 | { *gain = 1.0 / max ; |
| 241 | 244 | printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ; |
| 242 | | − output_count = 0 ; |
| 243 | | − sf_command (outfile, SFC_FILE_TRUNCATE, &output_count, sizeof (output_count)) ; |
| 244 | 245 | return -1 ; |
| 245 | 246 | } ; |
| 246 | 247 | |