summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-10-14 12:44:26 +0200
committerAndrew Kaster <andrewdkaster@gmail.com>2022-10-14 09:20:38 -0600
commite6ea49d10bb149e5e87581f58d803749a5002894 (patch)
tree0012286f34511e6eddf40a3711e8f2ca1fc8130d /Userland/Libraries/LibAudio
parent5f71c81e1bce080f70509d53d256375acf9a665c (diff)
downloadserenity-e6ea49d10bb149e5e87581f58d803749a5002894.zip
LibAudio: Fix 24-bit PCM rescaling
This code was so totally wrong I can't even explain it.
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r--Userland/Libraries/LibAudio/WavLoader.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp
index 2747615386..f7b89a9636 100644
--- a/Userland/Libraries/LibAudio/WavLoader.cpp
+++ b/Userland/Libraries/LibAudio/WavLoader.cpp
@@ -72,10 +72,13 @@ static ErrorOr<double> read_sample_int24(Core::Stream::Stream& stream)
i32 sample3 = byte;
i32 value = 0;
- value = sample1 << 8;
- value |= sample2 << 16;
- value |= sample3 << 24;
- return static_cast<double>(value) / static_cast<double>((1 << 24) - 1);
+ value = sample1;
+ value |= sample2 << 8;
+ value |= sample3 << 16;
+ // Sign extend the value, as it can currently not have the correct sign.
+ value = (value << 8) >> 8;
+ // Range of value is now -2^23 to 2^23-1 and we can rescale normally.
+ return static_cast<double>(value) / static_cast<double>((1 << 23) - 1);
}
template<typename T>