diff options
author | Andrew Kaster <akaster@serenityos.org> | 2022-12-24 22:40:19 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-31 00:04:34 +0100 |
commit | 86995be111d7c5b6c80ed2a15c30c926a754ad99 (patch) | |
tree | 7bdd5fd73de8d991872f613d957859d9f0ad0720 | |
parent | 140000f37ad8aad3b8e549b5aa949f2d1d127aab (diff) | |
download | serenity-86995be111d7c5b6c80ed2a15c30c926a754ad99.zip |
LibAudio: Tolerate a file sample rate lower than the AudioServer's
Previously, trying to load a wav file in aplay or SoundPlayer with a
sample rate less than 44100 would crash in an assertion failure trying
to unchecked_append to a vector that was not resized properly.
-rw-r--r-- | Userland/Libraries/LibAudio/Resampler.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibAudio/Resampler.h b/Userland/Libraries/LibAudio/Resampler.h index 86799d9197..c4c2e11af2 100644 --- a/Userland/Libraries/LibAudio/Resampler.h +++ b/Userland/Libraries/LibAudio/Resampler.h @@ -62,7 +62,8 @@ public: template<ArrayLike<SampleType> Samples, size_t vector_inline_capacity = 0> ErrorOr<void> try_resample_into_end(Vector<SampleType, vector_inline_capacity>& destination, Samples&& to_resample) { - TRY(destination.try_ensure_capacity(destination.size() + to_resample.size() * ceil_div(m_source, m_target))); + float ratio = (m_source > m_target) ? static_cast<float>(m_source) / m_target : static_cast<float>(m_target) / m_source; + TRY(destination.try_ensure_capacity(destination.size() + to_resample.size() * ratio)); for (auto sample : to_resample) { process_sample(sample, sample); |