diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-07-15 12:54:52 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-17 09:39:31 +0200 |
commit | 2df6f0e87f0312f6ee5c2b8abc11729487276bd1 (patch) | |
tree | 0a89021ff86a0daef01c128ad2d33b6a4a169331 /Userland | |
parent | 3db9706e57d160077f2c1b4d98efb8f5558805e4 (diff) | |
download | serenity-2df6f0e87f0312f6ee5c2b8abc11729487276bd1.zip |
Work on AudioServer
The center of this is now an ABuffer class in LibAudio.
ABuffer contains ASample, which has two channels (left/right) in
floating point for mixing purposes, in 44100hz.
This means that the loaders (AWavLoader in this case) needs to do some
manipulation to get things in the right format, but that we don't need
to care after format loading is done.
While we're at it, do some correctness fixes. PCM data is unsigned if
it's 8 bit, but 16 bit is signed. And /dev/audio also wants signed 16
bit audio, so give it what it wants.
On top of this, AudioServer now accepts requests to play a buffer.
The IPC mechanism here is pretty much a 1:1 copy-paste from
LibGUI/WindowServer. It can be generalized more in the future, but for
now I want to get AudioServer working decently first :)
Additionally, add a little "aplay" tool to load and play a WAV file. It
will break with large WAVs (run out of memory, heh...) but it's a start.
Future work needs to make AudioServer block buffer submission from
clients until it has played the buffer they are requesting to play.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Makefile | 2 | ||||
-rw-r--r-- | Userland/aplay.cpp | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Userland/Makefile b/Userland/Makefile index 80c84a6af8..e56242e7e2 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -19,7 +19,7 @@ clean: $(APPS) : % : %.o $(OBJS) @echo "LD $@" - @$(LD) -o $@ $(LDFLAGS) $< -lc -lgui -lcore + @$(LD) -o $@ $(LDFLAGS) $< -lc -lgui -laudio -lcore %.o: %.cpp @echo "CXX $<" diff --git a/Userland/aplay.cpp b/Userland/aplay.cpp new file mode 100644 index 0000000000..e50fe16edc --- /dev/null +++ b/Userland/aplay.cpp @@ -0,0 +1,29 @@ +#include <LibCore/CEventLoop.h> +#include <LibAudio/AWavLoader.h> +#include <LibAudio/AClientConnection.h> +#include <LibAudio/ABuffer.h> +#include <cstdio> + +int main(int argc, char **argv) +{ + CEventLoop loop; + if (argc < 2) { + fprintf(stderr, "Need a WAV to play\n"); + return 1; + } + + printf("Establishing connection\n"); + AClientConnection a_conn; + 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; + } + + printf("Playing WAV\n"); + a_conn.play(*buffer); + printf("Exiting! :)\n"); + return 0; +} |