shithub: riscv

Download patch

ref: f7ab9fb52a0d50db3e5de67e74f1654ad374ae59
parent: 7fc78023587e6cb238d5fa16f5acafb4078c6798
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Mar 3 09:45:14 EST 2014

pcmconv: revert previous change, fix dither clipping

previous change had forgot how dithering works... m(

we *really* add a random signal when *reducing* the number
of bits. just make sure we do not overflow like in
mixin().

--- a/sys/src/cmd/audio/pcmconv/pcmconv.c
+++ b/sys/src/cmd/audio/pcmconv/pcmconv.c
@@ -209,12 +209,13 @@
 {
 	static ulong prnd;
 
-	if(ibits >= 32 || ibits >= obits)
+	if(ibits >= 32 || obits >= ibits)
 		return;
 
 	while(count--){
 		prnd = (prnd*0x19660dL + 0x3c6ef35fL) & 0xffffffffL;
-		*y++ += ((int)prnd) >> ibits;
+		*y = clip((vlong)*y + ((int)prnd >> ibits));
+		y++;
 	}
 }