diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-27 17:20:41 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-27 17:27:05 +0200 |
commit | 426248098c18bd44b50252b066a0c672c62eba69 (patch) | |
tree | 714dfeda4a340e672c2cad458b8a66517226538b /Userland | |
parent | a292d8cd5a59915ccf4dfdc7fade6066e7d3db14 (diff) | |
download | serenity-426248098c18bd44b50252b066a0c672c62eba69.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/aplay.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Userland/aplay.cpp b/Userland/aplay.cpp index 8d8ef71d56..a86088c55c 100644 --- a/Userland/aplay.cpp +++ b/Userland/aplay.cpp @@ -16,15 +16,18 @@ int main(int argc, char **argv) AClientConnection a_conn; a_conn.handshake(); printf("Established connection\n"); - AWavLoader loader; - const auto& buffer = loader.load_wav(argv[1]); - if (!buffer) { - dbgprintf("Can't parse WAV: %s\n", loader.error_string()); - return 1; + AWavLoader loader(argv[1]); + printf("Loaded WAV\n"); + + for (;;) { + auto samples = loader.get_more_samples(); + if (!samples) { + break; + } + printf("Playing %d sample(s)\n", samples->samples().size()); + a_conn.play(*samples, true); } - printf("Playing WAV\n"); - a_conn.play(*buffer); printf("Exiting! :)\n"); return 0; } |