-
Notifications
You must be signed in to change notification settings - Fork 78
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
clanSound mixing issue when playing multiple sounds #130
Comments
The issue here is complicated since if you just divide by maximum number of sounds mixed you end up with a way too low volume for what most expect. The better way of dealing with this is to lower the master volume on sounds to, say, 75% so they don't immediately use the entire dynamic range. Since it can still happen, there should be a gain limiter on the mixed result so it will never go beyond 100%. Note that the sound is actually not distorted today as the Windows mixer itself applies a gain limiter on the final output sent the sound card. That is required as you can't know if something else is also playing sound that will put it beyond the limit - i.e. your game + spotify playing sound at the same time. |
Thanks, I had not thought of that. The solution isn't simple for my use case. Asking ChatGPT, the alternatives other than averaging the sound (with perceived reduced volume) is "RMS Normalization with Scaling". As always with ChatGPT it sounds convincing, but if it's right, that's what I would need to research.
Oh, it also suggested "Dynamic Range Compression (Optional)"
|
I'm afraid I don't know enough about the subject to really say if what ChatGPT is talking about makes any sense or not. I thought that OpenAL used a simple limiter where it looked for the max sample value encountered (within a certain time period, the 1024 samples are we mixing in one fragment) and divided it by that value if it was beyond 1.0. At closer inspection though it seems it is using this algorithm:
Their implementation can be found in https://github.com/kcat/openal-soft/blob/master/core/mastering.h where the I can't really say what the quality difference is between the simple limiter I described vs that paper vs whatever ChatGPT ranted about. I'm not that good at audio. :) |
Thanks for the info. I should re-learn the theory behind audio. It has been decades since I understood it. For example, if I play two sine waves, one with sin(theta) and the other sin(theta+pi). Would they, or should they cancel each other out. Or for example if one wave is 2sin(theta) and the other is sin(theta), is the combined sound louder. Even looking back how the Commodore Amiga handles the 4 channels in hardware. I don't know. |
I believe clanSound has a bug where if you play multiple sounds at the same time, they sound distorted (crackling).
The issue is when clanSound mixes sounds, it adds the output to the mix buffer, but it never divides the mix buffer by the number of sounds.
Thus sounds are louder, and distorts when they exceed the -1.0 to 1.0 range
I am surprised that it hasn't been reported before ?
Fix is:
The text was updated successfully, but these errors were encountered: