shithub: riscv

Download patch

ref: a60001871e67311f413affdca45039f1734b206a
parent: 7b36a7e1a9056bc8046d161c81aee008854daadf
author: cinap_lenrek <[email protected]>
date: Wed Nov 6 17:18:36 EST 2013

mp3dec: fix volume for mp3dec

the libmad samples need to be scaled properly. the
previous assumption was that it is 32 bits, but it
really is MAD_F_FRACTBITS + sign bit and rest used
for overflow.

thanks eekee!

--- a/sys/src/cmd/audio/mp3dec/main.c
+++ b/sys/src/cmd/audio/mp3dec/main.c
@@ -46,7 +46,7 @@
 
 		rate = pcm->samplerate;
 		chans = pcm->channels;
-		snprint(fmt, sizeof(fmt), "s32r%dc%d", rate, chans);
+		snprint(fmt, sizeof(fmt), "s%dr%dc%d", MAD_F_FRACBITS+1, rate, chans);
 
 		if(ifd >= 0){
 			close(ifd);
@@ -82,6 +82,13 @@
 		p = buf + j*4;
 		for(i=0; i < pcm->length; i++){
 			v = *s++;
+
+			/* clipping */
+			if(v >= MAD_F_ONE)
+				v = MAD_F_ONE-1;
+			else if(v < -MAD_F_ONE)
+				v = -MAD_F_ONE;
+
 			p[0] = v, v>>=8;
 			p[1] = v, v>>=8;
 			p[2] = v, v>>=8;