mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
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.
This commit is contained in:
parent
140000f37a
commit
86995be111
1 changed files with 2 additions and 1 deletions
|
@ -62,7 +62,8 @@ public:
|
||||||
template<ArrayLike<SampleType> Samples, size_t vector_inline_capacity = 0>
|
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)
|
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) {
|
for (auto sample : to_resample) {
|
||||||
process_sample(sample, sample);
|
process_sample(sample, sample);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue