shithub: libsamplerate

Download patch

ref: d3d8f77ddf7e099e59514a5df50466b2f1714be3
parent: 09cb4069319a83ab89e6cf9992ac99cb57ab0ae4
author: evpobr <evpobr@gmail.com>
date: Mon Oct 19 04:46:42 EDT 2020

Fix MSVC compiler warnings

--- a/examples/audio_out.c
+++ b/examples/audio_out.c
@@ -11,6 +11,12 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifdef _WIN32
+#define WIN32_LEAN_AN_MEAN
+#include <windows.h>
+#include <mmsystem.h>
+#endif
+
 #include "src_config.h"
 
 #include "audio_out.h"
@@ -647,9 +653,6 @@
 
 #if (defined (_WIN32) || defined (WIN32))
 
-#include <windows.h>
-#include <mmsystem.h>
-
 #define	WIN32_BUFFER_LEN	(1<<15)
 #define	WIN32_MAGIC			MAKE_MAGIC ('W', 'i', 'n', '3', '2', 's', 'u', 'x')
 
@@ -678,7 +681,7 @@
 static void win32_close (AUDIO_OUT *audio_out) ;
 
 static DWORD CALLBACK
-	win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2) ;
+	win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD_PTR data, DWORD_PTR param1, DWORD_PTR param2) ;
 
 static AUDIO_OUT*
 win32_open (int channels, int samplerate)
@@ -701,7 +704,7 @@
 
 	wf.nChannels = channels ;
 	wf.nSamplesPerSec = samplerate ;
-	wf.nBlockAlign = channels * sizeof (short) ;
+	wf.nBlockAlign = (WORD) (channels * sizeof (short)) ;
 
 	wf.wFormatTag = WAVE_FORMAT_PCM ;
 	wf.cbSize = 0 ;
@@ -708,8 +711,8 @@
 	wf.wBitsPerSample = 16 ;
 	wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec ;
 
-	error = waveOutOpen (&(win32_out->hwave), WAVE_MAPPER, &wf, (DWORD) win32_audio_out_callback,
-							(DWORD) win32_out, CALLBACK_FUNCTION) ;
+	error = waveOutOpen (&(win32_out->hwave), WAVE_MAPPER, &wf, (DWORD_PTR) win32_audio_out_callback,
+							(DWORD_PTR) win32_out, CALLBACK_FUNCTION) ;
 	if (error)
 	{	puts ("waveOutOpen failed.") ;
 		free (win32_out) ;
@@ -718,7 +721,7 @@
 
 	waveOutPause (win32_out->hwave) ;
 
-	return (WIN32_AUDIO_OUT *) win32_out ;
+	return (AUDIO_OUT *) win32_out ;
 } /* win32_open */
 
 static void
@@ -765,8 +768,8 @@
 	waveOutRestart (win32_out->hwave) ;
 
 	/* Fake 2 calls to the callback function to queue up enough audio. */
-	win32_audio_out_callback (0, MM_WOM_DONE, (DWORD) win32_out, 0, 0) ;
-	win32_audio_out_callback (0, MM_WOM_DONE, (DWORD) win32_out, 0, 0) ;
+	win32_audio_out_callback (0, MM_WOM_DONE, (DWORD_PTR) win32_out, 0, 0) ;
+	win32_audio_out_callback (0, MM_WOM_DONE, (DWORD_PTR) win32_out, 0, 0) ;
 
 	/* Wait for playback to finish. The callback notifies us when all
 	** wave data has been played.
@@ -805,7 +808,7 @@
 } /* win32_close */
 
 static DWORD CALLBACK
-win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD data, DWORD param1, DWORD param2)
+win32_audio_out_callback (HWAVEOUT hwave, UINT msg, DWORD_PTR data, DWORD_PTR param1, DWORD_PTR param2)
 {	WIN32_AUDIO_OUT	*win32_out ;
 	int		read_count, frame_count, k ;
 	short	*sptr ;
@@ -836,7 +839,7 @@
 	sptr = (short*) win32_out->whdr [win32_out->current].lpData ;
 
 	for (k = 0 ; k < read_count ; k++)
-		sptr [k] = lrint (32767.0 * win32_out->float_buffer [k]) ;
+		sptr [k] = (short) lrint (32767.0 * win32_out->float_buffer [k]) ;
 
 	if (read_count > 0)
 	{	/* Fix buffer length is only a partial block. */
--- a/examples/timewarp-file.c
+++ b/examples/timewarp-file.c
@@ -139,7 +139,7 @@
 
 		/* If the input buffer is empty, refill it. */
 		if (src_data.input_frames == 0)
-		{	src_data.input_frames = sf_readf_float (infile, input, INPUT_STEP_SIZE) ;
+		{	src_data.input_frames = (long) sf_readf_float (infile, input, INPUT_STEP_SIZE) ;
 			input_count += src_data.input_frames ;
 			src_data.data_in = input ;
 
--- a/examples/varispeed-play.c
+++ b/examples/varispeed-play.c
@@ -174,7 +174,7 @@
 	for (read_frames = 0 ; read_frames < input_frames ; )
 	{	sf_count_t position ;
 
-		read_frames += sf_readf_float (data->sndfile, data->buffer + read_frames * data->sfinfo.channels, input_frames - read_frames) ;
+		read_frames += (int) sf_readf_float (data->sndfile, data->buffer + read_frames * data->sfinfo.channels, input_frames - read_frames) ;
 
 		position = sf_seek (data->sndfile, 0, SEEK_CUR) ;
 
--- a/src/fastest_coeffs.h
+++ b/src/fastest_coeffs.h
@@ -15,6 +15,11 @@
 **  increment        : 128
 */
 
+#ifdef _MSC_VER
+#pragma warning (push)
+#pragma warning (disable: 4305)
+#endif
+
 static const struct fastest_coeffs_s
 {	int increment ;
 	coeff_t coeffs [2464] ;
@@ -2487,3 +2492,7 @@
  0.0	/* Need a final zero coefficient */
 }
 } ; /* fastest_coeffs */
+
+#ifdef _MSC_VER
+#pragma warning (pop)
+#endif
--- a/src/high_qual_coeffs.h
+++ b/src/high_qual_coeffs.h
@@ -15,6 +15,11 @@
 **   increment        : 2381
 */
 
+#ifdef _MSC_VER
+#pragma warning (push)
+#pragma warning (disable: 4305)
+#endif
+
 static const struct slow_high_qual_coeffs_s
 {	int increment ;
 	coeff_t coeffs [340239] ;
@@ -340263,3 +340268,6 @@
 }
 } ; /* high_qual_coeffs */
 
+#ifdef _MSC_VER
+#pragma warning (pop)
+#endif
--- a/src/mid_qual_coeffs.h
+++ b/src/mid_qual_coeffs.h
@@ -15,6 +15,11 @@
 **   increment        : 491
 */
 
+#ifdef _MSC_VER
+#pragma warning (push)
+#pragma warning (disable: 4305)
+#endif
+
 static const struct slow_mid_qual_coeffs_s
 {	int increment ;
 	coeff_t coeffs [22438] ;
@@ -22462,3 +22467,6 @@
 }
 } ; /* mid_qual_coeffs */
 
+#ifdef _MSC_VER
+#pragma warning (pop)
+#endif
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -479,8 +479,8 @@
 		}
 	while (filter_index > MAKE_INCREMENT_T (0)) ;
 
-	output [0] = scale * (left [0] + right [0]) ;
-	output [1] = scale * (left [1] + right [1]) ;
+	output [0] = (float) (scale * (left [0] + right [0])) ;
+	output [1] = (float) (scale * (left [1] + right [1])) ;
 } /* calc_output_stereo */
 
 static int
@@ -632,10 +632,10 @@
 		}
 	while (filter_index > MAKE_INCREMENT_T (0)) ;
 
-	output [0] = scale * (left [0] + right [0]) ;
-	output [1] = scale * (left [1] + right [1]) ;
-	output [2] = scale * (left [2] + right [2]) ;
-	output [3] = scale * (left [3] + right [3]) ;
+	output [0] = (float) (scale * (left [0] + right [0])) ;
+	output [1] = (float) (scale * (left [1] + right [1])) ;
+	output [2] = (float) (scale * (left [2] + right [2])) ;
+	output [3] = (float) (scale * (left [3] + right [3])) ;
 } /* calc_output_quad */
 
 static int
@@ -791,12 +791,12 @@
 		}
 	while (filter_index > MAKE_INCREMENT_T (0)) ;
 
-	output [0] = scale * (left [0] + right [0]) ;
-	output [1] = scale * (left [1] + right [1]) ;
-	output [2] = scale * (left [2] + right [2]) ;
-	output [3] = scale * (left [3] + right [3]) ;
-	output [4] = scale * (left [4] + right [4]) ;
-	output [5] = scale * (left [5] + right [5]) ;
+	output [0] = (float) (scale * (left [0] + right [0])) ;
+	output [1] = (float) (scale * (left [1] + right [1])) ;
+	output [2] = (float) (scale * (left [2] + right [2])) ;
+	output [3] = (float) (scale * (left [3] + right [3])) ;
+	output [4] = (float) (scale * (left [4] + right [4])) ;
+	output [5] = (float) (scale * (left [5] + right [5])) ;
 } /* calc_output_hex */
 
 static int
@@ -1031,35 +1031,35 @@
 		switch (ch % 8)
 		{	default :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 7 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 6 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 5 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 4 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 3 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 2 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 				/* Falls through. */
 			case 1 :
 				ch -- ;
-				output [ch] = scale * (left [ch] + right [ch]) ;
+				output [ch] = (float) (scale * (left [ch] + right [ch])) ;
 			} ;
 		}
 	while (ch > 0) ;
--- a/tests/float_short_test.c
+++ b/tests/float_short_test.c
@@ -45,16 +45,16 @@
 float_to_short_test (void)
 {
 	static float fpos [] =
-	{	0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3,
+	{	0.95f, 0.99f, 1.0f, 1.01f, 1.1f, 2.0f, 11.1f, 111.1f, 2222.2f, 33333.3f,
 		// Some "almost 1" as corner cases
-		32767.0 / 32768.0, (32767.0 + 0.4) / 32768.0, (32767. + 0.5) / 32768.0,
-		(32767.0 + 0.6) / 32768.0, (32767.0 + 0.9) / 32768.0,
+		(float) (32767.0 / 32768.0), (float) ((32767.0 + 0.4) / 32768.0), (float) ((32767. + 0.5) / 32768.0),
+		(float) ((32767.0 + 0.6) / 32768.0), (float) ((32767.0 + 0.9) / 32768.0),
 		} ;
 	static float fneg [] =
-	{	-0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3,
+	{	-0.95f, -0.99f, -1.0f, -1.01f, -1.1f, -2.0f, -11.1f, -111.1f, -2222.2f, -33333.3f,
 		// Some "almost 1" as corner cases
-		-32767.0 / 32768.0, -(32767.0 + 0.4) / 32768.0, -(32767.0 + 0.5) / 32768.0,
-		-(32767.0 + 0.6) / 32768.0, -(32767.0 + 0.9) / 32768.0,
+		(float) (-32767.0 / 32768.0), (float) (-(32767.0 + 0.4) / 32768.0), (float) (-(32767.0 + 0.5) / 32768.0),
+		(float) (-(32767.0 + 0.6) / 32768.0), (float) (-(32767.0 + 0.9) / 32768.0),
 		} ;
 
 	static short out [MAX (ARRAY_LEN (fpos), ARRAY_LEN (fneg))] ;
@@ -122,10 +122,10 @@
 float_to_int_test (void)
 {
 	static float fpos [] =
-	{	0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3
+	{	0.95f, 0.99f, 1.0f, 1.01f, 1.1f, 2.0f, 11.1f, 111.1f, 2222.2f, 33333.3f
 		} ;
 	static float fneg [] =
-	{	-0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3
+	{	-0.95f, -0.99f, -1.0f, -1.01f, -1.1f, -2.0f, -11.1f, -111.1f, -2222.2f, -33333.3f
 		} ;
 
 	static int out [MAX (ARRAY_LEN (fpos), ARRAY_LEN (fneg))] ;
--- a/tests/misc_test.c
+++ b/tests/misc_test.c
@@ -152,7 +152,7 @@
 		exit (1) ;
 		} ;
 
-	data.data_in = (float *) 0xdeadbeef ;
+	data.data_in = (float *) (size_t) 0xdeadbeef ;
 	data.input_frames = 0 ;
 	data.data_out = out ;
 	data.output_frames = ARRAY_LEN (out) ;
--- a/tests/multichan_throughput_test.c
+++ b/tests/multichan_throughput_test.c
@@ -13,6 +13,11 @@
 #include <unistd.h>
 #include <math.h>
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
 #include <samplerate.h>
 
 #include "src_config.h"
@@ -43,7 +48,11 @@
 
 	src_data.src_ratio = 0.99 ;
 
+#ifndef _WIN32
 	sleep (2) ;
+#else
+	Sleep (2000) ;
+#endif
 
 	start_time = clock () ;
 
@@ -139,7 +148,11 @@
 			puts ("") ;
 
 			/* Let the CPU cool down. We might be running on a laptop. */
+#ifndef _WIN32
 			sleep (10) ;
+#else
+			Sleep (10000) ;
+#endif
 			} ;
 
 		puts (
--- a/tests/termination_test.c
+++ b/tests/termination_test.c
@@ -182,7 +182,7 @@
 	fflush (stdout) ;
 
 /* Erik */
-for (k = 0 ; k < LONG_BUFFER_LEN ; k++) input [k] = k * 1.0 ;
+for (k = 0 ; k < LONG_BUFFER_LEN ; k++) input [k] = k * 1.0f ;
 
 	/* Calculate maximun input and output lengths. */
 	if (src_ratio >= 1.0)
--- a/tests/throughput_test.c
+++ b/tests/throughput_test.c
@@ -13,6 +13,11 @@
 #include <unistd.h>
 #include <math.h>
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
 #include <samplerate.h>
 
 #include "src_config.h"
@@ -43,7 +48,11 @@
 
 	src_data.src_ratio = 0.99 ;
 
+#ifndef _WIN32
 	sleep (2) ;
+#else
+	Sleep (2000) ;
+#endif
 
 	start_time = clock () ;
 
@@ -133,7 +142,11 @@
 		puts ("") ;
 
 		/* Let the CPU cool down. We might be running on a laptop. */
+#ifndef _WIN32
 		sleep (10) ;
+#else
+		Sleep (10000) ;
+#endif
 		} ;
 
 	printf ("\n    CPU name : %s\n", get_cpu_name ()) ;
--- a/tests/util.c
+++ b/tests/util.c
@@ -37,12 +37,12 @@
 			} ;
 
 		for (k = 0 ; k < output_len ; k++)
-			output [k] += amplitude * sin (freqs [freq] * (2 * k) * M_PI + phase) ;
+			output [k] = (float) (output [k] + (amplitude * sin (freqs [freq] * (2 * k) * M_PI + phase))) ;
 		} ;
 
 	/* Apply Hanning Window. */
 	for (k = 0 ; k < output_len ; k++)
-		output [k] *= 0.5 - 0.5 * cos ((2 * k) * M_PI / (output_len - 1)) ;
+		output [k] = (float) (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 / (output_len - 1))
 					+ 0.1365995 * cos ((4 * k) * M_PI / (output_len - 1))