2019-07-13 19:42:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2019-07-13 19:42:03 +02:00
|
|
|
#include <AK/RefPtr.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 12:54:52 +02:00
|
|
|
#include <AK/StringView.h>
|
2019-07-27 17:20:41 +02:00
|
|
|
#include <LibCore/CFile.h>
|
2019-10-16 15:31:01 +02:00
|
|
|
#include <LibAudio/ABuffer.h>
|
2019-07-13 19:42:03 +02: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 12:54:52 +02:00
|
|
|
class ABuffer;
|
2019-07-27 14:30:09 +02:00
|
|
|
|
|
|
|
|
namespace AK {
|
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 12:54:52 +02:00
|
|
|
class ByteBuffer;
|
2019-07-27 14:30:09 +02:00
|
|
|
}
|
2019-07-13 19:42:03 +02: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 12:54:52 +02:00
|
|
|
// Parses a WAV file and produces an ABuffer instance from it
|
2019-07-13 19:42:03 +02:00
|
|
|
class AWavLoader {
|
|
|
|
|
public:
|
2019-07-27 17:20:41 +02:00
|
|
|
explicit AWavLoader(const StringView& path);
|
2019-09-04 20:13:32 +02:00
|
|
|
|
|
|
|
|
bool has_error() const { return !m_error_string.is_null(); }
|
2019-07-13 19:42:03 +02:00
|
|
|
const char* error_string() { return m_error_string.characters(); }
|
2019-07-27 14:30:09 +02:00
|
|
|
|
2019-09-04 20:13:32 +02:00
|
|
|
RefPtr<ABuffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KB);
|
2019-07-27 17:20:41 +02:00
|
|
|
|
2019-11-04 19:39:17 +01:00
|
|
|
void reset();
|
|
|
|
|
void seek(const int position);
|
|
|
|
|
|
2019-07-28 21:52:30 +02:00
|
|
|
int loaded_samples() const { return m_loaded_samples; }
|
|
|
|
|
int total_samples() const { return m_total_samples; }
|
|
|
|
|
u32 sample_rate() const { return m_sample_rate; }
|
|
|
|
|
u16 num_channels() const { return m_num_channels; }
|
|
|
|
|
u16 bits_per_sample() const { return m_bits_per_sample; }
|
2019-11-05 19:09:31 +01:00
|
|
|
RefPtr<CFile> file() const { return m_file; }
|
2019-07-28 21:52:30 +02:00
|
|
|
|
2019-07-13 19:42:03 +02:00
|
|
|
private:
|
2019-07-27 17:20:41 +02:00
|
|
|
bool parse_header();
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<CFile> m_file;
|
2019-07-13 19:42:03 +02:00
|
|
|
String m_error_string;
|
2019-10-16 15:31:01 +02:00
|
|
|
OwnPtr<AResampleHelper> m_resampler;
|
2019-07-27 17:20:41 +02:00
|
|
|
|
|
|
|
|
u32 m_sample_rate { 0 };
|
|
|
|
|
u16 m_num_channels { 0 };
|
|
|
|
|
u16 m_bits_per_sample { 0 };
|
2019-07-28 21:52:30 +02:00
|
|
|
|
|
|
|
|
int m_loaded_samples { 0 };
|
|
|
|
|
int m_total_samples { 0 };
|
2019-07-13 19:42:03 +02:00
|
|
|
};
|