ref: 92610d83ab8b0e82dec73bd5b1b6709751f52d8d
parent: 5585cd29fb01e4d2848c0a3fe2d87b40687ce807
author: Sigrid Haflínudóttir <[email protected]>
date: Wed May 13 03:55:59 EDT 2020
piper: mixer: limit output
--- a/piper/piper.c
+++ b/piper/piper.c
@@ -187,7 +187,7 @@
{
int i, j, n;
s16int *pcm;
- float *out, *x;
+ float *out, *x, f;
pcm = malloc(2*Bufframes*sizeof(*pcm));
out = malloc(Bufframes*sizeof(*out));
@@ -205,7 +205,12 @@
}
qunlock(&grouplock);
for (n = 0; n < Bufframes; n++) {
- pcm[n*2+0] = pcm[n*2+1] = out[n] * 8192.0 * vol;
+ f = out[n] * 8192.0 * vol;
+ if (f > 32767.0)
+ f = 32767.0;
+ else if (f < -32767.0)
+ f = -32767.0;
+ pcm[n*2+0] = pcm[n*2+1] = f;
}
if (write(audio, pcm, 2*Bufframes*sizeof(*pcm)) < 0)
break;