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 @@
12010-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
12009-12-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>82009-12-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
2 9
3 * doc/win32.html10 * doc/win32.html
examples/sndfile-resample.c+22−21
@@ -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** This program is free software; you can redistribute it and/or modify4** 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 by5** 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
40int40int
41main (int argc, char *argv [])41main (int argc, char *argv [])
42{ SNDFILE *infile, *outfile ;42{ SNDFILE *infile, *outfile = NULL ;
43 SF_INFO sfinfo ;43 SF_INFO sfinfo ;
44 44
45 sf_count_t count ;45 sf_count_t count ;
@@ -137,28 +137,31 @@ main (int argc, char *argv []) · 91 unmodified lines
137 /* Delete the output file length to zero if already exists. */137 /* Delete the output file length to zero if already exists. */
138 remove (argv [argc - 1]) ;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 printf ("Output file : %s\n", argv [argc - 1]) ;140 printf ("Output file : %s\n", argv [argc - 1]) ;
158 printf ("Sample Rate : %d\n", sfinfo.samplerate) ;141 printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
159 142
160 do143 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 count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ;163 count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ;
164 }
162 while (count < 0) ;165 while (count < 0) ;
163 166
164 printf ("Output Frames : %ld\n\n", (long) count) ;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 if (max > 1.0)242 if (max > 1.0)
240 { *gain = 1.0 / max ;243 { *gain = 1.0 / max ;
241 printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ;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 return -1 ;245 return -1 ;
245 } ;246 } ;
246 247

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