History

examples/sndfile-resample.c : Add a --no-normalize cmd line option.

Erik de Castro Lopo committed 14 years ago

Commit 2b99b481 parent 756dc2c2 files · +17 −5Browse files

Unified · Split

2 files
  1. ChangeLog +6 −0
  2. examples/sndfile-resample.c +11 −5
ChangeLog+6−0
@@ -1,3 +1,9 @@
1+2012-10-07 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
2+
3+ * examples/sndfile-resample.c
4+ Add a --no-normalize cmd line option. Thanks to Adriano Moura for the
5+ patch.
6+
17 2012-09-28 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
28
39 * tests/varispeed_test.c
examples/sndfile-resample.c+11−5
@@ -1,5 +1,5 @@
11 /*
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>
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
@@ -34,7 +34,7 @@ · 28 unmodified lines
3434 #define BUFFER_LEN 4096 /*-(1<<16)-*/
3535
3636 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) ;
3838 static double apply_gain (float * data, long frames, int channels, double max, double gain) ;
3939
4040 int
@@ -42,6 +42,7 @@ main (int argc, char *argv []) · 1 unmodified line
4242 { SNDFILE *infile, *outfile = NULL ;
4343 SF_INFO sfinfo ;
4444
45+ int normalize = 1 ;
4546 sf_count_t count ;
4647 double src_ratio = -1.0, gain = 1.0 ;
4748 int new_sample_rate = -1, k, converter, max_speed = SF_FALSE ;
@@ -69,6 +70,8 @@ main (int argc, char *argv []) · 21 unmodified lines
6970 for (k = 1 ; k < argc - 2 ; k++)
7071 { if (strcmp (argv [k], "--max-speed") == 0)
7172 max_speed = SF_TRUE ;
73+ else if (strcmp (argv [k], "--no-normalize") == 0)
74+ normalize = 0 ;
7275 else if (strcmp (argv [k], "-to") == 0)
7376 { k ++ ;
7477 new_sample_rate = atoi (argv [k]) ;
@@ -160,7 +163,7 @@ main (int argc, char *argv []) · 85 unmodified lines
160163
161164 sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
162165
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) ;
164167 }
165168 while (count < 0) ;
166169
@@ -176,7 +179,7 @@ main (int argc, char *argv []) · 9 unmodified lines
176179 */
177180
178181 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)
180183 { static float input [BUFFER_LEN] ;
181184 static float output [BUFFER_LEN] ;
182185
@@ -239,7 +242,7 @@ sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double sr · 56 unmodified lines
239242
240243 src_delete (src_state) ;
241244
242− if (max > 1.0)
245+ if (normalize && max > 1.0)
243246 { *gain = 1.0 / max ;
244247 printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ;
245248 return -1 ;
@@ -301,6 +304,9 @@ usage_exit (const char *progname) · 55 unmodified lines
301304 for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++)
302305 printf (" %d : %s%s\n", k, cptr, k == DEFAULT_CONVERTER ? " (default)" : "") ;
303306
307+ puts ("\n"
308+ " The --no-normalize option disables clipping check and normalization.") ;
309+
304310 puts ("") ;
305311
306312 exit (1) ;

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