New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AUDIO: Optimize case for !inStereo && outStereo #5437
Conversation
WalkthroughWalkthroughThe changes involve updates to the audio rate conversion logic, ensuring proper handling of stereo and mono channels during the conversion process. The Changes
TipsChat with CodeRabbit Bot (
|
I don't understand this change. You still call Maybe you wanted to write something instead of: } else {
// Output mono channel
st_sample_t val = clampedAdd(outBuffer[0], (outL + outR) / 2);
outBuffer += 1;
if (outStereo)
*outBuffer++ = val;
} something like } else {
// Output mono channel
if (outStereo) {
st_sample_t val = clampedAdd(outBuffer[0], (outL + outR) / 2);
outBuffer++;
*outBuffer++ = val;
} else {
outBuffer++;
}
} |
@sev- no, the change is correct:
The intended optimisation is the last case, currently it ends up in the first case, calling Your proposed change wouldn't write anything in case of |
Okay, thank you for your explanation. Merging. |
Unfortunately, I've had to revert this PR due to the logic quoted above. When mixing a mono sound into a stereo output, there's no reason to assume the stereo output's left and right channel are the same. If you blindly copy the value of the left channel over to the right, you're erasing any stereo information previously present in the sound you're mixing into, while also introducing subtle artifacts. Case in point: a user on the bugtracker caught this exact issue in Gobliiins 5. |
@fracturehill oh dear, you are completely correct. It never occured to me that one can mix stereo and mono samples together! Apologies for the noise (pun intended ;)) and kudos to the reporter. |
This is almost invisible on high-end machines but does it job nicely on lower-end ones (<100 MHz). Instead of calling
clampedAdd
with the same values just copy the value over.As many (older) games use mono samples nearly always, it can be widely used, especially on platform which do not offer 16-bit mono output (yes, they exist ;)).