summaryrefslogtreecommitdiff
path: root/Userland/Applications/Piano
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-08-27 23:47:09 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-12 23:38:57 +0200
commit152ec28da0d1a51ade18fe6799a34ac9b7aa07b0 (patch)
tree540e62552da0d9bb767e566f8951f081009e136a /Userland/Applications/Piano
parent2909c3a931439d0cbed3e4599d9eed47a6fdb446 (diff)
downloadserenity-152ec28da0d1a51ade18fe6799a34ac9b7aa07b0.zip
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.
Diffstat (limited to 'Userland/Applications/Piano')
-rw-r--r--Userland/Applications/Piano/Music.h3
-rw-r--r--Userland/Applications/Piano/Track.cpp7
2 files changed, 7 insertions, 3 deletions
diff --git a/Userland/Applications/Piano/Music.h b/Userland/Applications/Piano/Music.h
index a1080155e9..ce2c814735 100644
--- a/Userland/Applications/Piano/Music.h
+++ b/Userland/Applications/Piano/Music.h
@@ -30,7 +30,8 @@ constexpr int buffer_size = sample_count * sizeof(Sample);
constexpr double sample_rate = 44100;
-constexpr double volume_factor = 1800;
+// Headroom for the synth
+constexpr double volume_factor = 0.1;
enum Switch {
Off,
diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp
index f077efc994..5727a945f7 100644
--- a/Userland/Applications/Piano/Track.cpp
+++ b/Userland/Applications/Piano/Track.cpp
@@ -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;
}