1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

Audio: Change how volume works

Across the entire audio system, audio now works in 0-1 terms instead of
0-100 as before. Therefore, volume is now a double instead of an int.
The master volume of the AudioServer changes smoothly through a
FadingProperty, preventing clicks. Finally, volume computations are done
with logarithmic scaling, which is more natural for the human ear.

Note that this could be 4-5 different commits, but as they change each
other's code all the time, it makes no sense to split them up.
This commit is contained in:
kleines Filmröllchen 2021-08-27 23:47:09 +02:00 committed by Andreas Kling
parent 2909c3a931
commit 152ec28da0
14 changed files with 190 additions and 45 deletions

View file

@ -95,8 +95,8 @@ void Track::fill_sample(Sample& sample)
default:
VERIFY_NOT_REACHED();
}
new_sample.left += note_sample.left * m_power[note] * volume_factor * (static_cast<double>(volume()) / volume_max);
new_sample.right += note_sample.right * m_power[note] * volume_factor * (static_cast<double>(volume()) / volume_max);
new_sample.left += note_sample.left * m_power[note] * NumericLimits<i16>::max() * volume_factor * (static_cast<double>(volume()) / volume_max);
new_sample.right += note_sample.right * m_power[note] * NumericLimits<i16>::max() * volume_factor * (static_cast<double>(volume()) / volume_max);
}
auto new_sample_dsp = LibDSP::Signal(LibDSP::Sample { new_sample.left / NumericLimits<i16>::max(), new_sample.right / NumericLimits<i16>::max() });
@ -105,6 +105,9 @@ void Track::fill_sample(Sample& sample)
new_sample.left = delayed_sample.left * NumericLimits<i16>::max();
new_sample.right = delayed_sample.right * NumericLimits<i16>::max();
new_sample.left = clamp(new_sample.left, NumericLimits<i16>::min(), NumericLimits<i16>::max());
new_sample.right = clamp(new_sample.right, NumericLimits<i16>::min(), NumericLimits<i16>::max());
sample.left += new_sample.left;
sample.right += new_sample.right;
}