fix clipping (a little)

This commit is contained in:
Glenn Maynard
2003-01-01 09:13:48 +00:00
parent 3d8c4d9fc7
commit 234edae41a
+9 -3
View File
@@ -256,8 +256,14 @@ void SoundMixBuffer::write(const Sint16 *buf, unsigned size)
/* Scale volume: */
samp = Sint32(samp * vol);
/* Add and clip: */
mixbuf[pos] = clamp(mixbuf[pos] + samp, INT_MIN, INT_MAX);
/* Add and clip. Can't use clamp() here--we're clamping to
* the min and max of Sint32. */
if(samp > 0 && mixbuf[pos] + samp < mixbuf[pos])
mixbuf[pos] = INT_MAX;
else if(samp < 0 && mixbuf[pos] + samp > mixbuf[pos])
mixbuf[pos] = INT_MIN;
else
mixbuf[pos] = mixbuf[pos] + samp;
}
}
@@ -266,7 +272,7 @@ void SoundMixBuffer::read(Sint16 *buf)
for(unsigned pos = 0; pos < mixbuf.size(); ++pos)
{
/* XXX: dither */
Sint32 out = (mixbuf[pos] + 0) / 32768;
Sint32 out = (mixbuf[pos]) / 32768;
out = clamp(out, -32768, 32767);
buf[pos] = Sint16(out);
}