mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:38:12 +00:00

I had to solve a bunch of things simultaneously to make this work. Refactor AWavLoader to be a streaming loader rather than a one-shot one. The constructor parses the header, and if everything looks good, you can repeatedly ask the AWavLoader for sample buffers until it runs out. Also send a message from AudioServer when a buffer has finished playing. That allows us to implement a blocking variant of play(). Use all of this in aplay to play WAV files chunk-at-a-time. This is definitely not perfect and it's a little glitchy and skippy, but I think it's a step in the right direction.
31 lines
649 B
C++
31 lines
649 B
C++
#pragma once
|
|
|
|
#include <AK/AKString.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibCore/CFile.h>
|
|
|
|
class ABuffer;
|
|
|
|
namespace AK {
|
|
class ByteBuffer;
|
|
}
|
|
|
|
// Parses a WAV file and produces an ABuffer instance from it
|
|
class AWavLoader {
|
|
public:
|
|
explicit AWavLoader(const StringView& path);
|
|
RefPtr<ABuffer> load_wav(const StringView& path);
|
|
const char* error_string() { return m_error_string.characters(); }
|
|
|
|
RefPtr<ABuffer> get_more_samples();
|
|
|
|
private:
|
|
bool parse_header();
|
|
CFile m_file;
|
|
String m_error_string;
|
|
|
|
u32 m_sample_rate { 0 };
|
|
u16 m_num_channels { 0 };
|
|
u16 m_bits_per_sample { 0 };
|
|
};
|