Blame patches/libsndfile-1.2.0.local.patch

589402
diff -ru libsndfile-1.0.28.orig/programs/sndfile-play.c libsndfile-1.0.28/programs/sndfile-play.c
589402
--- libsndfile-1.0.28.orig/programs/sndfile-play.c	2017-04-01 09:18:02.000000000 +0200
589402
+++ libsndfile-1.0.28/programs/sndfile-play.c	2020-11-11 13:46:51.824586591 +0100
589402
@@ -71,10 +71,31 @@
589402
 	#include <sys/ioctl.h>
589402
 	#include <sys/audioio.h>
589402
 
589402
-#elif (OS_IS_WIN32 == 1)
589402
+#elif (OS_IS_WIN32 == 1) || defined(__midipix__)
589402
+	#include <pthread.h>
589402
 	#include <windows.h>
589402
 	#include <mmsystem.h>
589402
 
589402
+#ifndef INFINITE
589402
+#define INFINITE 0xffffffff
589402
+#endif
589402
+
589402
+#ifndef CALLBACK_FUNCTION
589402
+#define CALLBACK_FUNCTION (uint32_t)0x00030000
589402
+#endif
589402
+
589402
+#ifndef WAVE_MAPPER
589402
+#define WAVE_MAPPER ((UINT)-1)
589402
+#endif
589402
+
589402
+#ifndef WAVE_FORMAT_PCM
589402
+#define WAVE_FORMAT_PCM 1
589402
+#endif
589402
+
589402
+#ifndef MM_WOM_DONE
589402
+#define MM_WOM_DONE 0x3BD
589402
+#endif
589402
+
589402
 #endif
589402
 
589402
 #define	SIGNED_SIZEOF(x)	((int) sizeof (x))
589402
@@ -482,15 +503,16 @@
589402
 **  point to data instead of short*. It plain sucks!
589402
 */
589402
 
589402
-#if (OS_IS_WIN32 == 1)
589402
+#if (OS_IS_WIN32 == 1) || defined(__midipix__)
589402
 
589402
 #define	WIN32_BUFFER_LEN	(1 << 15)
589402
 
589402
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER ;
589402
+
589402
 typedef struct
589402
 {	HWAVEOUT	hwave ;
589402
 	WAVEHDR		whdr [2] ;
589402
 
589402
-	CRITICAL_SECTION	mutex ;		/* to control access to BuffersInUSe */
589402
 	HANDLE		Event ;			/* signal that a buffer is free */
589402
 
589402
 	short		buffer [WIN32_BUFFER_LEN / sizeof (short)] ;
589402
@@ -524,9 +546,9 @@
589402
 		waveOutWrite (audio_data->hwave, (LPWAVEHDR) &(audio_data->whdr [audio_data->current]), sizeof (WAVEHDR)) ;
589402
 
589402
 		/* count another buffer in use */
589402
-		EnterCriticalSection (&audio_data->mutex) ;
589402
+		pthread_mutex_lock (&mutex) ;
589402
 		audio_data->BuffersInUse ++ ;
589402
-		LeaveCriticalSection (&audio_data->mutex) ;
589402
+		pthread_mutex_unlock (&mutex) ;
589402
 
589402
 		/* use the other buffer next time */
589402
 		audio_data->current = (audio_data->current + 1) % 2 ;
589402
@@ -556,9 +578,9 @@
589402
 
589402
 	/* let main loop know a buffer is free */
589402
 	if (msg == MM_WOM_DONE)
589402
-	{	EnterCriticalSection (&audio_data->mutex) ;
589402
+	{	pthread_mutex_lock (&mutex) ;
589402
 		audio_data->BuffersInUse -- ;
589402
-		LeaveCriticalSection (&audio_data->mutex) ;
589402
+		pthread_mutex_unlock (&mutex) ;
589402
 		SetEvent (audio_data->Event) ;
589402
 		} ;
589402
 
589402
@@ -586,7 +608,6 @@
589402
 		audio_data.remaining = audio_data.sfinfo.frames * audio_data.sfinfo.channels ;
589402
 		audio_data.current = 0 ;
589402
 
589402
-		InitializeCriticalSection (&audio_data.mutex) ;
589402
 		audio_data.Event = CreateEvent (0, FALSE, FALSE, 0) ;
589402
 
589402
 		wf.nChannels = audio_data.sfinfo.channels ;
589402
@@ -655,8 +676,6 @@
589402
 		waveOutClose (audio_data.hwave) ;
589402
 		audio_data.hwave = 0 ;
589402
 
589402
-		DeleteCriticalSection (&audio_data.mutex) ;
589402
-
589402
 		sf_close (audio_data.sndfile) ;
589402
 		} ;
589402
 
589402
@@ -848,7 +867,7 @@
589402
 	sndio_play (argc, argv) ;
589402
 #elif (defined (sun) && defined (unix))
589402
 	solaris_play (argc, argv) ;
589402
-#elif (OS_IS_WIN32 == 1)
589402
+#elif (OS_IS_WIN32 == 1) || defined(__midipix__)
589402
 	win32_play (argc, argv) ;
589402
 #elif (defined (__MACH__) && defined (__APPLE__))
589402
 	printf ("OS X 10.8 and later have a new Audio API.\n") ;