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.
2019-07-15 13:54:52 +03:00
|
|
|
#include <LibAudio/ABuffer.h>
|
2019-07-28 22:52:30 +03:00
|
|
|
#include <LibAudio/AClientConnection.h>
|
|
|
|
#include <LibAudio/AWavLoader.h>
|
|
|
|
#include <LibCore/CEventLoop.h>
|
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.
2019-07-15 13:54:52 +03:00
|
|
|
#include <cstdio>
|
|
|
|
|
2019-07-28 22:52:30 +03:00
|
|
|
int main(int argc, char** argv)
|
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.
2019-07-15 13:54:52 +03:00
|
|
|
{
|
|
|
|
CEventLoop loop;
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Need a WAV to play\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AClientConnection a_conn;
|
2019-07-17 19:28:30 +03:00
|
|
|
a_conn.handshake();
|
2019-07-27 18:20:41 +03:00
|
|
|
AWavLoader loader(argv[1]);
|
|
|
|
|
2019-07-28 22:56:19 +03:00
|
|
|
printf("\033[34;1m Playing\033[0m: %s\n", argv[1]);
|
|
|
|
printf("\033[34;1m Format\033[0m: %u Hz, %u-bit, %s\n",
|
2019-07-28 22:52:30 +03:00
|
|
|
loader.sample_rate(),
|
|
|
|
loader.bits_per_sample(),
|
|
|
|
loader.num_channels() == 1 ? "Mono" : "Stereo");
|
2019-07-28 22:56:19 +03:00
|
|
|
printf("\033[34;1mProgress\033[0m: \033[s");
|
2019-07-27 18:20:41 +03:00
|
|
|
for (;;) {
|
|
|
|
auto samples = loader.get_more_samples();
|
2019-07-28 22:52:30 +03:00
|
|
|
if (!samples)
|
2019-07-27 18:20:41 +03:00
|
|
|
break;
|
2019-07-28 22:52:30 +03:00
|
|
|
printf("\033[u");
|
|
|
|
printf("%d/%d", loader.loaded_samples(), loader.total_samples());
|
|
|
|
fflush(stdout);
|
2019-07-28 19:27:32 +03:00
|
|
|
a_conn.enqueue(*samples);
|
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.
2019-07-15 13:54:52 +03:00
|
|
|
}
|
2019-07-28 22:52:30 +03:00
|
|
|
printf("\n");
|
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.
2019-07-15 13:54:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|