shithub: pplay

Download patch

ref: 1997896377424f52ad5f70c9b6597b878b7d24d7
parent: d0a1ce234992b233df513abe9c2eb84d95b9a33e
author: qwx <qwx@sciops.net>
date: Thu Feb 6 17:02:58 EST 2020

drawsamps: fix overshooting bin at the end of a batch and simplify some

--- a/draw.c
+++ b/draw.c
@@ -40,12 +40,16 @@
 
 	if(bgofs >= viewe)
 		return;
-	if(!file){
+	n = viewe - bgofs;
+	if(n > sizeof bgbuf)
+		n = sizeof bgbuf;
+	if(n > T)
+		n -= n % T;
+	if(!file)
 		p = pcmbuf + bgofs;
-		n = viewe - bgofs < sizeof bgbuf ? viewe - bgofs : sizeof bgbuf;
-	}else{
+	else{
 		seek(ifd, bgofs, 0);
-		n = read(ifd, bgbuf, sizeof bgbuf);
+		n = read(ifd, bgbuf, n);
 		seek(ifd, seekp, 0);
 		p = bgbuf;
 	}
@@ -52,7 +56,7 @@
 	e = p + n;
 	x = (bgofs - views) / T;
 	while(p < e){
-		n = filesz - bgofs < T ? filesz - bgofs : T;
+		n = T;
 		if(n > e - p)
 			n -= n - (e - p);
 		bgofs += n;