shithub: libsamplerate

Download patch

ref: a95c161b3967786bee7d3f5da84f3df5ee34363c
parent: f5b513c8637df5630f4bc4bb647d18a614575e41
author: Erik de Castro Lopo <erikd@miles>
date: Wed Sep 15 04:02:49 EDT 2004

Add an expected_peaks parameter to function calculate_snr() and fix knock on effects.

--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -59,7 +59,7 @@
 
 	printf ("Time       : %5.2f secs.\n", (1.0 * clock_time) / CLOCKS_PER_SEC) ;
 	printf ("Throughput : %d samples/sec\n", (int) floor (src_data.output_frames_gen / ((1.0 * clock_time) / CLOCKS_PER_SEC))) ;
-	printf ("SNR        : %6.2f dB\n", calculate_snr (output, SNR_LEN)) ;
+	printf ("SNR        : %6.2f dB\n", calculate_snr (output, SNR_LEN, 1)) ;
 
 	return 0 ;
 } /* main */
--- a/tests/calc_snr.c
+++ b/tests/calc_snr.c
@@ -35,7 +35,7 @@
 
 static void log_mag_spectrum (double *input, int len, double *magnitude) ;
 static void smooth_mag_spectrum (double *magnitude, int len) ;
-static double find_snr (const double *magnitude, int len) ;
+static double find_snr (const double *magnitude, int len, int expected_peaks) ;
 
 typedef struct
 {	double	peak ;
@@ -43,7 +43,7 @@
 } PEAK_DATA ;
 
 double
-calculate_snr (float *data, int len)
+calculate_snr (float *data, int len, int expected_peaks)
 {	static double magnitude [MAX_SPEC_LEN] ;
 	static double datacopy [MAX_SPEC_LEN] ;
 
@@ -67,7 +67,7 @@
 	log_mag_spectrum (datacopy, len, magnitude) ;
 	smooth_mag_spectrum (magnitude, len / 2) ;
 
-	snr = find_snr (magnitude, len) ;
+	snr = find_snr (magnitude, len, expected_peaks) ;
 
 	return snr ;
 } /* calculate_snr */
@@ -144,7 +144,7 @@
 } /* peak_compare */
 
 static double
-find_snr (const double *magnitude, int len)
+find_snr (const double *magnitude, int len, int expected_peaks)
 {	PEAK_DATA peaks [MAX_PEAKS] ;
 
 	int		k, peak_count = 0 ;
@@ -168,8 +168,8 @@
 			} ;
 		} ;
 
-	if (peak_count < MAX_PEAKS / 2)
-	{	printf ("\n%s : line %d : bad peak_count (%d).\n\n", __FILE__, __LINE__, peak_count) ;
+	if (peak_count < expected_peaks)
+	{	printf ("\n%s : line %d : bad peak_count (%d), expected %d.\n\n", __FILE__, __LINE__, peak_count, expected_peaks) ;
 		return -1.0 ;
 		} ;
 
--- a/tests/calc_snr.h
+++ b/tests/calc_snr.h
@@ -16,7 +16,7 @@
 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */
 
-double calculate_snr (float *data, int len) ;
+double calculate_snr (float *data, int len, int expected_peaks) ;
 /*
 ** 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/multi_channel_test.c
+++ b/tests/multi_channel_test.c
@@ -139,7 +139,7 @@
 	deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
 
 	for (ch = 0 ; ch < channel_count ; ch++)
-	{	snr = calculate_snr (output_serial + ch * frames, frames) ;
+	{	snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
 		if (snr < target_snr)
 		{	printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
 			save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
@@ -234,7 +234,7 @@
 	deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
 
 	for (ch = 0 ; ch < channel_count ; ch++)
-	{	snr = calculate_snr (output_serial + ch * frames, frames) ;
+	{	snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
 		if (snr < target_snr)
 		{	printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
 			save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
@@ -351,7 +351,7 @@
 	deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
 
 	for (ch = 0 ; ch < channel_count ; ch++)
-	{	snr = calculate_snr (output_serial + ch * frames, frames) ;
+	{	snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
 		if (snr < target_snr)
 		{	printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
 			save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
--- a/tests/snr_bw_test.c
+++ b/tests/snr_bw_test.c
@@ -298,7 +298,7 @@
 		} ;
 
 	/* Calculate signal-to-noise ratio. */
-	snr = calculate_snr (output, src_data.output_frames_gen) ;
+	snr = calculate_snr (output, src_data.output_frames_gen, test_data->pass_band_peaks) ;
 
 	if (snr < 0.0)
 	{	/* An error occurred. */
--- a/tests/src-evaluate.c
+++ b/tests/src-evaluate.c
@@ -287,7 +287,7 @@
 } /* generate_source_wav */
 
 static double
-measure_destination_wav (char *filename, int *output_samples)
+measure_destination_wav (char *filename, int *output_samples, int expected_peaks)
 {	static float buffer [124000] ;
 
 	SNDFILE *sndfile ;
@@ -318,7 +318,7 @@
 
 	sf_close (sndfile) ;
 
-	snr = calculate_snr (buffer, sfinfo.frames) ;
+	snr = calculate_snr (buffer, sfinfo.frames, expected_peaks) ;
 
 	return snr ;
 } /* measure_desination_wav */
@@ -359,7 +359,7 @@
 		if ((retval = system (command)) != 0)
 			printf ("system returned %d\n", retval) ;
 
-		snr = measure_destination_wav ("destination.wav", &sample_count) ;
+		snr = measure_destination_wav ("destination.wav", &sample_count, snr_test->pass_band_peaks) ;
 
 		*output_samples += sample_count ;
 
@@ -394,8 +394,8 @@
 		exit (1) ;
 		} ;
 
-	if (sfinfo.frames > ARRAY_LEN (data) || sfinfo.frames < ARRAY_LEN (data) - 100)
-	{	printf ("Line %d : bad frame count.\n", __LINE__) ;
+	if (sfinfo.frames > ARRAY_LEN (data) + 4 || sfinfo.frames < ARRAY_LEN (data) - 100)
+	{	printf ("Line %d : bad frame count (got %d, expected %d).\n", __LINE__, (int) sfinfo.frames, ARRAY_LEN (data)) ;
 		exit (1) ;
 		} ;