mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Gain clamped to 1.0, but why? #377

Closed dbechrd closed 2 years ago

dbechrd commented 2 years ago

This could be considered a bug, but I'm submitting it as a feature request since it's a totally understadable oversight: Why does ma_device_set_master_volume disallow setting gain to values > 1.0? It's perfectly reasonable for users to want to boost audio levels to more than 100% of the original sample values for a variety of reasons. Can we remove this limitation and only keep the >= 0 check?

mackron commented 2 years ago

It was clamped like that intentionally - not a bug. I originally did it simply because it's common for other audio systems to clamp it as well:

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee418150(v=vs.85) https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-isimpleaudiovolume-setmastervolume http://manuals.opensound.com/developer/SNDCTL_DSP_SETPLAYVOL.html

But thinking about it, I can't really think of a good reason not to support amplification except for maybe safety in the event of some corrupt memory that causes the volume to get set to some extreme value. I've gone ahead and relaxed that restriction and amplification should now be supported.

This change has been added to the dev branch, but note that I'm getting a major release prepared right now so if you're coming from the master branch you might get some breaking API changes.

Commit: https://github.com/mackron/miniaudio/commit/3c8a39f0fdef9c4280319571f53476077862cb84

dbechrd commented 2 years ago

The hardware/hearing safety concern is an excellent consideration. Thanks for clarifying. Most audio hardware does have a knob that limits the maximum output, so even if you set it to 5000 in software it's not going to exceed the hardware limiter. I think VLC is a great example of an application that allows boosting and I haven't heard anyone complain about it, but that's definitely a different scenario than a general purpose audio library. Appreciate the feedback!

mackron commented 2 years ago

This change has been released.