shithub: pplay

Download patch

ref: 6007fd6a5b76b5e0ff6679add328b7e4768b04d9
parent: 3615c3b7feb6c1144ebb939d4d107ab87961e6a9
author: qwx <qwx@sciops.net>
date: Tue Nov 29 13:29:31 EST 2022

logic for sample drawing pixel width

--- a/draw.c
+++ b/draw.c
@@ -25,6 +25,7 @@
 static usize T;
 static uchar *sbuf;
 static usize sbufsz;
+static int sampwidth = 1;
 
 static Image *
 eallocimage(Rectangle r, int repl, ulong col)
@@ -75,9 +76,9 @@
 end:
 		recvul(drawc);
 again:
-		if(sbufsz < T){
-			sbuf = erealloc(sbuf, T, sbufsz);
-			sbufsz = T;
+		if(sbufsz < T * sampwidth){
+			sbuf = erealloc(sbuf, T * sampwidth, sbufsz);
+			sbufsz = T * sampwidth;
 		}
 		lockdisplay(display);
 		draw(viewbg, viewbg->r, col[Cbg], nil, ZP);
@@ -91,7 +92,7 @@
 				qunlock(&lsync);
 				goto again;
 			}
-			n = m < T ? m : T;
+			n = m < T * sampwidth ? m : T * sampwidth;
 			p = getbuf(d, n, sbuf, &n);
 			qunlock(&lsync);
 			if(p == nil){
@@ -116,13 +117,13 @@
 					else if(s > rmax)
 						rmax = s;
 				}
-				p += 4;
+				p += 4 * sampwidth;
 			}
 			m -= n;
 			l = Rect(x, bgscalyl - lmax / bgscalf,
-				x+1, bgscalyl - lmin / bgscalf);
+				x+sampwidth, bgscalyl - lmin / bgscalf);
 			r = Rect(x, bgscalyr - rmax / bgscalf,
-				x+1, bgscalyr - rmin / bgscalf);
+				x+sampwidth, bgscalyr - rmin / bgscalf);
 			lockdisplay(display);
 			draw(viewbg, l, col[Csamp], nil, ZP);
 			if(stereo)