shithub: riscv

Download patch

ref: fade7acea6378225a2c6e3c66b6f00f99063411a
parent: 908a7524eec1bbefc431041dfdf805f585d7f255
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Jun 16 13:22:59 EDT 2023

zuke: apply clipping after replay gain (some cases found in track mode)

--- a/sys/src/cmd/audio/zuke/zuke.c
+++ b/sys/src/cmd/audio/zuke/zuke.c
@@ -673,6 +673,16 @@
 	return 0;
 }
 
+static int
+clip16(int v)
+{
+	if(v > 0x7fff)
+		return 0x7fff;
+	if(v < -0x8000)
+		return -0x8000;
+	return v;
+}
+
 static void
 gain(double g, char *buf, long n)
 {
@@ -680,8 +690,8 @@
 
 	if(g != 1.0)
 		for(f = (s16int*)buf; n >= 4; n -= 4){
-			*f = g * *f++;
-			*f = g * *f++;
+			*f++ = clip16(*f * g);
+			*f++ = clip16(*f * g);
 		}
 }