shithub: libsamplerate

Download patch

ref: 3548f633b3e621138f345d87f863837a36b32910
parent: f4c054e28b42ba0ae708f61a1de232a81a8ebd96
author: Erik de Castro Lopo <erikd@coltrane>
date: Wed Sep 15 05:23:29 EDT 2004

Add a max parameter to gen_windowed sines() and fix code whcih uses it.

--- a/examples/sndfile-resample.c
+++ b/examples/sndfile-resample.c
@@ -315,6 +315,7 @@
 } /* main */
 
 #endif
+
 /*
 ** Do not edit or modify anything in this comment block.
 ** The arch-tag line is a file identity tag for the GNU Arch 
@@ -322,4 +323,3 @@
 **
 ** arch-tag: 4bb75515-3b00-4e31-bc37-35f3659e61cb
 */
-
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -24,7 +24,7 @@
 
 	memset (input, 0, sizeof (input)) ;
 	freq = 0.01 ;
-	gen_windowed_sines (input, SNR_LEN, &freq, 1) ;
+	gen_windowed_sines (1, &freq, 1.0, input, SNR_LEN) ;
 
 
 	src_data.data_in = input ;
--- a/tests/multi_channel_test.c
+++ b/tests/multi_channel_test.c
@@ -106,7 +106,7 @@
 	/* Calculate channel_count separate windowed sine waves. */
 	for (ch = 0 ; ch < channel_count ; ch++)
 	{	freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
-		gen_windowed_sines (input_serial + ch * frames, frames, &freq, 1) ;
+		gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
 		} ;
 
 	/* Interleave the data in preparation for SRC. */
@@ -176,7 +176,7 @@
 	/* Calculate channel_count separate windowed sine waves. */
 	for (ch = 0 ; ch < channel_count ; ch++)
 	{	freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
-		gen_windowed_sines (input_serial + ch * frames, frames, &freq, 1) ;
+		gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
 		} ;
 
 	/* Interleave the data in preparation for SRC. */
@@ -303,7 +303,7 @@
 	/* Calculate channel_count separate windowed sine waves. */
 	for (ch = 0 ; ch < channel_count ; ch++)
 	{	freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
-		gen_windowed_sines (input_serial + ch * frames, frames, &freq, 1) ;
+		gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
 		} ;
 
 	/* Interleave the data in preparation for SRC. */
--- a/tests/snr_bw_test.c
+++ b/tests/snr_bw_test.c
@@ -239,7 +239,7 @@
 	memset (output, 0, sizeof (output)) ;
 
 	/* Generate input data array. */
-	gen_windowed_sines (data, input_len, test_data->freqs, test_data->freq_count) ;
+	gen_windowed_sines (test_data->freq_count, test_data->freqs, 1.0, data, input_len) ;
 
 	/* Perform sample rate conversion. */
 	if ((src_state = src_new (converter, 1, &error)) == NULL)
@@ -344,7 +344,7 @@
 	double 		output_peak ;
 	int			error ;
 
-	gen_windowed_sines (input, BUFFER_LEN, &freq, 1) ;
+	gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
 
 	src_data.end_of_input = 1 ; /* Only one buffer worth of input. */
 
--- a/tests/src-evaluate.c
+++ b/tests/src-evaluate.c
@@ -276,7 +276,7 @@
 
 	sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
 
-	gen_windowed_sines (buffer, ARRAY_LEN (buffer), freqs, freq_count) ;
+	gen_windowed_sines (freq_count, freqs, 1.0, buffer, ARRAY_LEN (buffer)) ;
 
 	if (sf_write_float (sndfile, buffer, ARRAY_LEN (buffer)) != ARRAY_LEN (buffer))
 	{	printf ("Line %d : sf_write_float short write.\n", __LINE__) ;
--- a/tests/util.c
+++ b/tests/util.c
@@ -27,34 +27,34 @@
 #endif
 
 void
-gen_windowed_sines (float *data, int data_len, double *freqs, int freq_count)
+gen_windowed_sines (int freq_count, double *freqs, double max, float *output, int output_len)
 {	int 	k, freq ;
 	double	amplitude, phase ;
 
-	amplitude = 1.0 / freq_count ;
+	amplitude = max / freq_count ;
 
-	for (k = 0 ; k < data_len ; k++)
-		data [k] = 0.0 ;
+	for (k = 0 ; k < output_len ; k++)
+		output [k] = 0.0 ;
 
 	for (freq = 0 ; freq < freq_count ; freq++)
 	{	phase = 0.9 * M_PI / freq_count ;
 
 		if (freqs [freq] <= 0.0 || freqs [freq] >= 0.5)
-		{	printf ("\n" __FILE__ " : Error : freq [%d] == %g is out of range. Should be < 0.5.\n", freq, freqs [freq]) ;
+		{	printf ("\n%s : Error : freq [%d] == %g is out of range. Should be < 0.5.\n", __FILE__, freq, freqs [freq]) ;
 			exit (1) ;
 			} ;
 
-		for (k = 0 ; k < data_len ; k++)
-			data [k] += amplitude * sin (freqs [freq] * (2 * k) * M_PI + phase) ;
+		for (k = 0 ; k < output_len ; k++)
+			output [k] += amplitude * sin (freqs [freq] * (2 * k) * M_PI + phase) ;
 		} ;
 
 	/* Apply Hanning Window. */
-	for (k = 0 ; k < data_len ; k++)
-		data [k] *= 0.5 - 0.5 * cos ((2 * k) * M_PI / (data_len - 1)) ;
+	for (k = 0 ; k < output_len ; k++)
+		output [k] *= 0.5 - 0.5 * cos ((2 * k) * M_PI / (output_len - 1)) ;
 
-	/*	data [k] *= 0.3635819 - 0.4891775 * cos ((2 * k) * M_PI / (data_len - 1))
-					+ 0.1365995 * cos ((4 * k) * M_PI / (data_len - 1))
-					- 0.0106411 * cos ((6 * k) * M_PI / (data_len - 1)) ;
+	/*	data [k] *= 0.3635819 - 0.4891775 * cos ((2 * k) * M_PI / (output_len - 1))
+					+ 0.1365995 * cos ((4 * k) * M_PI / (output_len - 1))
+					- 0.0106411 * cos ((6 * k) * M_PI / (output_len - 1)) ;
 		*/
 
 	return ;
@@ -153,6 +153,7 @@
 	dummy = malloc (1) ;
 	free (dummy) ;
 } /* force_efence_banner */
+
 /*
 ** Do not edit or modify anything in this comment block.
 ** The arch-tag line is a file identity tag for the GNU Arch 
--- a/tests/util.h
+++ b/tests/util.h
@@ -22,7 +22,7 @@
 
 #define	ARRAY_LEN(x)	((int) (sizeof (x) / sizeof ((x) [0])))
 
-void gen_windowed_sines (float *data, int data_len, double *freqs, int freq_count) ;
+void gen_windowed_sines (int freq_count, double *freqs, double max, float *output, int output_len) ;
 
 void save_oct_float (char *filename, float *input, int in_len, float *output, int out_len) ;
 void save_oct_double (char *filename, double *input, int in_len, double *output, int out_len) ;