From ad38d5330c5087e5c608c751b2d3b2e1b09ac45b Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 1 May 2020 20:43:54 +0000
Subject: [PATCH] Ignore the result of snd_pcm_drain() rather than waiting for
 it to work. Call snd_pcm_prepare() before every sample.

Should fix bug #2
https://sourceforge.net/p/syncterm/tickets/2/
---
 src/xpdev/xpbeep.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c
index d711b93cf6..f4943406bd 100644
--- a/src/xpdev/xpbeep.c
+++ b/src/xpdev/xpbeep.c
@@ -633,10 +633,8 @@ xptone_complete_locked(void)
 
 #ifdef USE_ALSA_SOUND
 	if(handle_type==SOUND_DEVICE_ALSA) {
-		if(!alsa_device_open_failed) {
-			while(alsa_api->snd_pcm_drain(playback_handle))
-				SLEEP(1);
-		}
+		if(!alsa_device_open_failed)
+			alsa_api->snd_pcm_drain(playback_handle);
 	}
 #endif
 
@@ -825,6 +823,7 @@ do_xp_play_sample(const unsigned char *sampo, size_t sz, int *freed)
 		int ret;
 		int written=0;
 
+		alsa_api->snd_pcm_prepare(playback_handle);
 		while(written < sz) {
 			ret=alsa_api->snd_pcm_writei(playback_handle, samp+written, sz-written);
 			if(ret < 0) {
-- 
GitLab