2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-06 14:18:03 +00:00
|
|
|
#include <LibAudio/Buffer.h>
|
|
|
|
#include <LibAudio/ClientConnection.h>
|
|
|
|
#include <LibAudio/WavLoader.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2019-09-21 22:17:53 +00:00
|
|
|
#include <stdio.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 10:54:52 +00:00
|
|
|
|
2019-07-28 19:52:30 +00: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 10:54:52 +00:00
|
|
|
{
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::EventLoop loop;
|
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 10:54:52 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Need a WAV to play\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-06 09:40:02 +00:00
|
|
|
auto audio_client = Audio::ClientConnection::construct();
|
2019-09-21 22:17:53 +00:00
|
|
|
audio_client->handshake();
|
2020-02-06 09:40:02 +00:00
|
|
|
Audio::WavLoader loader(argv[1]);
|
2020-02-09 14:53:10 +00:00
|
|
|
if (loader.has_error()) {
|
|
|
|
fprintf(stderr, "Failed to load WAV file: %s\n", loader.error_string());
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-27 15:20:41 +00:00
|
|
|
|
2019-07-28 19:56:19 +00: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 19:52:30 +00:00
|
|
|
loader.sample_rate(),
|
|
|
|
loader.bits_per_sample(),
|
|
|
|
loader.num_channels() == 1 ? "Mono" : "Stereo");
|
2019-07-28 19:56:19 +00:00
|
|
|
printf("\033[34;1mProgress\033[0m: \033[s");
|
2019-07-27 15:20:41 +00:00
|
|
|
for (;;) {
|
|
|
|
auto samples = loader.get_more_samples();
|
2019-10-19 17:15:40 +00:00
|
|
|
if (samples) {
|
|
|
|
printf("\033[u");
|
|
|
|
printf("%d/%d", loader.loaded_samples(), loader.total_samples());
|
|
|
|
fflush(stdout);
|
|
|
|
audio_client->enqueue(*samples);
|
|
|
|
} else if (audio_client->get_remaining_samples()) {
|
|
|
|
sleep(1);
|
|
|
|
} else {
|
2019-07-27 15:20:41 +00:00
|
|
|
break;
|
2019-10-19 17:15:40 +00:00
|
|
|
}
|
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 10:54:52 +00:00
|
|
|
}
|
2019-07-28 19:52:30 +00: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 10:54:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|