diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-08-16 22:01:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-17 00:16:00 +0200 |
commit | c974be91abe7c276376414166bb37680c6e2b232 (patch) | |
tree | db5dab277d44108d172bcc2bb0489048a2ea5c67 | |
parent | 442aa48a61e018d7d1d4aeefaa9c0f4fd53192eb (diff) | |
download | serenity-c974be91abe7c276376414166bb37680c6e2b232.zip |
LibAudio: Rescale integer samples correctly in FLAC loader
The FLAC samples are signed, so we need to rescale them not by their bit
depth, but by half of the bit depth. For example, a 24-bit sample
extends from -2^23 to 2^23-1, and therefore needs to be rescaled by 2^23
to conform to the [-1, 1] double sample range.
-rw-r--r-- | Userland/Libraries/LibAudio/FlacLoader.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 1276c95a91..0e21ad035a 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -414,8 +414,7 @@ void FlacLoaderPlugin::next_frame() VERIFY(left.size() == right.size()); - // TODO: find the correct rescale offset - double sample_rescale = static_cast<double>(1 << pcm_bits_per_sample(m_current_frame->bit_depth)); + double sample_rescale = static_cast<double>(1 << (pcm_bits_per_sample(m_current_frame->bit_depth) - 1)); dbgln_if(AFLACLOADER_DEBUG, "Sample rescaled from {} bits: factor {:.1f}", pcm_bits_per_sample(m_current_frame->bit_depth), sample_rescale); m_current_frame_data.clear_with_capacity(); |