diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c
index bd535458f2cf8cfac83e02b8542508e2a59e1116..3ef8b18e8f3a37955ffa5fdf6a841858a933885a 100644
--- a/src/xpdev/xpbeep.c
+++ b/src/xpdev/xpbeep.c
@@ -152,11 +152,9 @@ void SineBeep(double freq, DWORD duration)
 		goto abrt;
 	if(waveOutWrite(waveOut, &wh, sizeof(wh))!=MMSYSERR_NOERROR)
 		goto abrt;
-	while(!(wh.dwFlags&WHDR_DONE))
-		SLEEP(1);
 abrt:
-	waveOutUnprepareHeader(waveOut, &wh, sizeof(wh));
-	waveOutReset(waveOut);
+	while(waveOutUnprepareHeader(waveOut, &wh, sizeof(wh))==WAVERR_STILLPLAYING)
+		SLEEP(1);
 	waveOutClose(waveOut);
 }