fix clipping (a little)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user