Try mixing differently; this might help sound quality for people

using the fallback sound drivers.
This commit is contained in:
Glenn Maynard
2003-03-07 19:28:34 +00:00
parent 3d74bb6bcd
commit 2dc8e1f59f
+2 -21
View File
@@ -306,32 +306,13 @@ void SoundMixBuffer::write(const Sint16 *buf, unsigned size)
}
for(unsigned pos = 0; pos < size; ++pos)
{
Sint32 samp = buf[pos] * 32768;
/* Scale volume: */
samp = Sint32(samp * vol);
/* 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;
}
mixbuf[pos] += buf[pos];
}
void SoundMixBuffer::read(Sint16 *buf)
{
for(unsigned pos = 0; pos < mixbuf.size(); ++pos)
{
/* XXX: dither */
Sint32 out = (mixbuf[pos]) / 32768;
out = clamp(out, -32768, 32767);
buf[pos] = Sint16(out);
}
buf[pos] = (Sint16) clamp(mixbuf[pos], -32768, 32767);
mixbuf.erase();
}