shithub: drawterm

Download patch

ref: cad9e2e30c31838b06878de59d54fe5a8132961a
parent: 9f65f57c73f7c9d80a89ad43195ae4c2fcf9ffbe
author: Eli Cohen <[email protected]>
date: Sun Jan 30 20:29:07 EST 2022

devaudio patch for alsa and ORDWR

--- a/kern/devaudio-alsa.c
+++ b/kern/devaudio-alsa.c
@@ -76,16 +76,19 @@
 audiodevwrite(void *v, int n)
 {
 	snd_pcm_sframes_t frames;
-	int tot, m;
+	int tot, m, fr;
 
 	for(tot = 0; tot < n; tot += m){
+		fr = (n-tot)/4;
 		do {
-			frames = snd_pcm_writei(playback, v+tot, (n-tot)/4);
-		} while(frames == -EAGAIN);
+			frames = snd_pcm_writei(playback, v+tot, fr);
+			if (frames < 0 && snd_pcm_recover(playback, frames, 0) == 0)
+				frames = fr;
+			if (frames < 0)
+				break;
+		} while(frames != fr);
 		if (frames < 0)
-			frames = snd_pcm_recover(playback, frames, 0);
-		if (frames < 0)
-			error((char*)snd_strerror(frames));
+			error("snd_pcm_writei");
 		m = frames*4;
 	}
 
@@ -100,9 +103,11 @@
 	do {
 		frames = snd_pcm_readi(capture, v, n/4);
 	} while(frames == -EAGAIN);
-
+	if (frames < 0 && snd_pcm_recover(capture, frames, 0) == 0)
+		frames = n/4;
 	if (frames < 0)
-		error((char*)snd_strerror(frames));
+		error("snd_pcm_readi");
 
 	return frames*4;
 }
+
--- a/kern/devaudio.c
+++ b/kern/devaudio.c
@@ -14,6 +14,7 @@
 	Aclosed		= 0,
 	Aread,
 	Awrite,
+	Ardwr,
 
 	Speed		= 44100,
 	Ncmd		= 50,		/* max volume command words */
@@ -31,7 +32,7 @@
 {
 	QLock	lk;
 	Rendez	vous;
-	int	amode;		/* Aclosed/Aread/Awrite for /audio */
+	int	amode;		/* Aclosed/Aread/Awrite/Ardwr for /audio */
 } audio;
 
 #define aqlock(a) qlock(&(a)->lk)
@@ -114,6 +115,8 @@
 		amode = Awrite;
 		if((omode&7) == OREAD)
 			amode = Aread;
+		else if((omode&7) == ORDWR)
+			amode = Ardwr;
 		aqlock(&audio);
 		if(waserror()){
 			aqunlock(&audio);
@@ -178,7 +181,7 @@
 		return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
 
 	case Qaudio:
-		if(audio.amode != Aread)
+		if(audio.amode != Aread && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){
@@ -324,7 +327,7 @@
 		break;
 
 	case Qaudio:
-		if(audio.amode != Awrite)
+		if(audio.amode != Awrite && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){