1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:47:34 +00:00

LibAudio: WavLoader: Avoid reading partial samples

When samples are requested in `Audio::Loader::get_more_samples`,
the request comes in as a max number of bytes to read.

However, the requested number of bytes may not be an even multiple
of the bytes per sample of the loaded file. If this is the case, and
the bytes are read from the file/stream, then
the last sample will be a partial/runt sample, which then offsets
the remainder of the stream, causing white noise in playback.

This bug was discovered when trying to play 24-bit Wave files, which
happened to have a sample size that never aligned with the number
of requested bytes.

This commit fixes the bug by only reading a multiple of
"bytes per sample" for the loaded file.
This commit is contained in:
Nick Miller 2021-06-05 10:14:03 -07:00 committed by Ali Mohammad Pur
parent 3938b56577
commit ed5777eb0a
2 changed files with 51 additions and 32 deletions

View file

@ -11,11 +11,14 @@
#include <AK/MemoryStream.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Stream.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/WeakPtr.h>
#include <LibAudio/Buffer.h>
#include <LibAudio/Loader.h>
#include <LibCore/File.h>
#include <LibCore/FileStream.h>
namespace Audio {
class Buffer;
@ -55,7 +58,8 @@ private:
bool valid { false };
RefPtr<Core::File> m_file;
OwnPtr<InputMemoryStream> m_stream;
OwnPtr<AK::InputStream> m_stream;
AK::InputMemoryStream* m_memory_stream;
String m_error_string;
OwnPtr<ResampleHelper> m_resampler;