Use cubic mapping for volume control (#6020)
* Use cubic mapping for volume control * Update comment for hardware volume slider
This commit is contained in:
parent
46c6e5c4c0
commit
a6e7a81de9
@ -84,11 +84,11 @@ void DspInterface::OutputCallback(s16* buffer, std::size_t num_frames) {
|
|||||||
std::memcpy(buffer + 2 * i, &last_frame[0], 2 * sizeof(s16));
|
std::memcpy(buffer + 2 * i, &last_frame[0], 2 * sizeof(s16));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of the hardware volume slider with a dynamic range of 60 dB
|
// Implementation of the hardware volume slider
|
||||||
|
// A cubic curve is used to approximate a linear change in human-perceived loudness
|
||||||
const float linear_volume = std::clamp(Settings::values.volume, 0.0f, 1.0f);
|
const float linear_volume = std::clamp(Settings::values.volume, 0.0f, 1.0f);
|
||||||
if (linear_volume != 1.0) {
|
if (linear_volume != 1.0) {
|
||||||
const float volume_scale_factor =
|
const float volume_scale_factor = linear_volume * linear_volume * linear_volume;
|
||||||
linear_volume == 0 ? 0 : std::exp(6.90775f * linear_volume) * 0.001f;
|
|
||||||
for (std::size_t i = 0; i < num_frames; i++) {
|
for (std::size_t i = 0; i < num_frames; i++) {
|
||||||
buffer[i * 2 + 0] = static_cast<s16>(buffer[i * 2 + 0] * volume_scale_factor);
|
buffer[i * 2 + 0] = static_cast<s16>(buffer[i * 2 + 0] * volume_scale_factor);
|
||||||
buffer[i * 2 + 1] = static_cast<s16>(buffer[i * 2 + 1] * volume_scale_factor);
|
buffer[i * 2 + 1] = static_cast<s16>(buffer[i * 2 + 1] * volume_scale_factor);
|
||||||
|
Loading…
Reference in New Issue
Block a user