1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +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:
Andreas Kling 2019-07-27 17:20:41 +02:00
parent a292d8cd5a
commit 426248098c
10 changed files with 88 additions and 64 deletions

View file

@ -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;
}