mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
Audio: Make basic streaming WAV playback work.
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.
This commit is contained in:
parent
a292d8cd5a
commit
426248098c
10 changed files with 88 additions and 64 deletions
|
@ -53,9 +53,10 @@ struct ASample {
|
|||
class ABuffer : public RefCounted<ABuffer> {
|
||||
public:
|
||||
static RefPtr<ABuffer> from_pcm_data(ByteBuffer& data, int num_channels, int bits_per_sample, int source_rate);
|
||||
ABuffer(Vector<ASample>&& samples)
|
||||
: m_samples(move(samples))
|
||||
{}
|
||||
static NonnullRefPtr<ABuffer> create_with_samples(Vector<ASample>&& samples)
|
||||
{
|
||||
return adopt(*new ABuffer(move(samples)));
|
||||
}
|
||||
|
||||
const Vector<ASample>& samples() const { return m_samples; }
|
||||
Vector<ASample>& samples() { return m_samples; }
|
||||
|
@ -63,6 +64,10 @@ public:
|
|||
int size_in_bytes() const { return m_samples.size() * sizeof(ASample); }
|
||||
|
||||
private:
|
||||
ABuffer(Vector<ASample>&& samples)
|
||||
: m_samples(move(samples))
|
||||
{
|
||||
}
|
||||
|
||||
Vector<ASample> m_samples;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue