History

Prevent creation of double length output files when conversion is restarted due to clipping of the output when the format is FLAC. This problem arises due to libsndfile's in ability to seek in a FLAC file during write.

Erik de Castro Lopo committed 16 years ago

Commit 19b5adc1 parent 5b237382 files · +29 −21Browse files

Unified · Split

2 files
  1. ChangeLog +7 −0
  2. examples/sndfile-resample.c +22 −21
ChangeLog+7−0
@@ -1,3 +1,10 @@
1+2010-01-10 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
2+
3+ * examples/sndfile-resample.c
4+ Prevent creation of double length output files when conversion is restarted
5+ due to clipping of the output when the format is FLAC. This problem arises
6+ due to libsndfile's in ability to seek in a FLAC file during write.
7+
18 2009-12-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
29
310 * doc/win32.html
examples/sndfile-resample.c+22−21
@@ -1,5 +1,5 @@
11 /*
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>
33 **
44 ** This program is free software; you can redistribute it and/or modify
55 ** 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
3939
4040 int
4141 main (int argc, char *argv [])
42−{ SNDFILE *infile, *outfile ;
42+{ SNDFILE *infile, *outfile = NULL ;
4343 SF_INFO sfinfo ;
4444
4545 sf_count_t count ;
@@ -137,28 +137,31 @@ main (int argc, char *argv []) · 91 unmodified lines
137137 /* Delete the output file length to zero if already exists. */
138138 remove (argv [argc - 1]) ;
139139
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−
157140 printf ("Output file : %s\n", argv [argc - 1]) ;
158141 printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
159142
160143 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+
161163 count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ;
164+ }
162165 while (count < 0) ;
163166
164167 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
239242 if (max > 1.0)
240243 { *gain = 1.0 / max ;
241244 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)) ;
244245 return -1 ;
245246 } ;
246247

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t