code: plan9front

Download patch

ref: c613e336df8eed2b952acf2cb28e865e92e2daf7
parent: 3d5dca521797b5a91ebc4281fbaf58211bb4f40f
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Apr 2 21:46:50 EDT 2024

libpcm: fix pcmratio - forgot to adjust for output frame size

--- a/sys/src/libpcm/conv.c
+++ b/sys/src/libpcm/conv.c
@@ -715,13 +715,14 @@
 int
 pcmratio(Pcmconv *c, int insz)
 {
-	int outsz;
+	int outsz, fsz;
 
-	if(insz < c->idesc.framesz)
+	fsz = c->idesc.framesz;
+	if(insz < fsz)
 		goto Bad;
-	insz /= c->idesc.framesz;
-	outsz = ((uvlong)insz * ((uvlong)c->odesc.rate<<Np)/c->idesc.rate) >> Np;
-	if(outsz > 1)
+	insz = (insz + fsz)/fsz;
+	outsz = ((uvlong)insz * c->odesc.framesz * ((uvlong)c->odesc.rate<<Np)/c->idesc.rate) >> Np;
+	if(outsz >= c->odesc.framesz)
 		return outsz;
 Bad:
 	werrstr("invalid buffer size: %d", insz);