Skip to content

Commit 92f7786

Browse files
committed
LibAudio: Put all classes in the Audio namespace and remove leading A
1 parent 0bce5f7 commit 92f7786

20 files changed

+127
-103
lines changed

Applications/Piano/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
4141
{
4242
GUI::Application app(argc, argv);
4343

44-
auto audio_client = AClientConnection::construct();
44+
auto audio_client = Audio::ClientConnection::construct();
4545
audio_client->handshake();
4646

4747
AudioEngine audio_engine;

Applications/SoundPlayer/PlaybackManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "PlaybackManager.h"
2828

29-
PlaybackManager::PlaybackManager(NonnullRefPtr<AClientConnection> connection)
29+
PlaybackManager::PlaybackManager(NonnullRefPtr<Audio::ClientConnection> connection)
3030
: m_connection(connection)
3131
{
3232
m_timer = Core::Timer::construct(100, [&]() {
@@ -41,7 +41,7 @@ PlaybackManager::~PlaybackManager()
4141
{
4242
}
4343

44-
void PlaybackManager::set_loader(OwnPtr<AWavLoader>&& loader)
44+
void PlaybackManager::set_loader(OwnPtr<Audio::WavLoader>&& loader)
4545
{
4646
stop();
4747
m_loader = move(loader);

Applications/SoundPlayer/PlaybackManager.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636

3737
class PlaybackManager final {
3838
public:
39-
PlaybackManager(NonnullRefPtr<AClientConnection>);
39+
PlaybackManager(NonnullRefPtr<Audio::ClientConnection>);
4040
~PlaybackManager();
4141

4242
void play();
4343
void stop();
4444
void pause();
4545
void seek(const int position);
4646
bool toggle_pause();
47-
void set_loader(OwnPtr<AWavLoader>&&);
47+
void set_loader(OwnPtr<Audio::WavLoader>&&);
4848

4949
int last_seek() const { return m_last_seek; }
5050
bool is_paused() const { return m_paused; }
5151
float total_length() const { return m_total_length; }
52-
RefPtr<ABuffer> current_buffer() const { return m_current_buffer; }
52+
RefPtr<Audio::Buffer> current_buffer() const { return m_current_buffer; }
5353

54-
NonnullRefPtr<AClientConnection> connection() const { return m_connection; }
54+
NonnullRefPtr<Audio::ClientConnection> connection() const { return m_connection; }
5555

5656
Function<void()> on_update;
5757

@@ -65,10 +65,10 @@ class PlaybackManager final {
6565
int m_next_ptr { 0 };
6666
int m_last_seek { 0 };
6767
float m_total_length { 0 };
68-
OwnPtr<AWavLoader> m_loader { nullptr };
69-
NonnullRefPtr<AClientConnection> m_connection;
70-
RefPtr<ABuffer> m_next_buffer;
71-
RefPtr<ABuffer> m_current_buffer;
72-
Vector<RefPtr<ABuffer>> m_buffers;
68+
OwnPtr<Audio::WavLoader> m_loader { nullptr };
69+
NonnullRefPtr<Audio::ClientConnection> m_connection;
70+
RefPtr<Audio::Buffer> m_next_buffer;
71+
RefPtr<Audio::Buffer> m_current_buffer;
72+
Vector<RefPtr<Audio::Buffer>> m_buffers;
7373
RefPtr<Core::Timer> m_timer;
7474
};

Applications/SoundPlayer/SampleWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void SampleWidget::paint_event(GUI::PaintEvent& event)
7777
}
7878
}
7979

80-
void SampleWidget::set_buffer(ABuffer* buffer)
80+
void SampleWidget::set_buffer(Audio::Buffer* buffer)
8181
{
8282
if (m_buffer == buffer)
8383
return;

Applications/SoundPlayer/SampleWidget.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828

2929
#include <LibGUI/GFrame.h>
3030

31-
class ABuffer;
31+
namespace Audio {
32+
class Buffer;
33+
}
3234

3335
class SampleWidget final : public GUI::Frame {
3436
C_OBJECT(SampleWidget)
3537
public:
3638
virtual ~SampleWidget() override;
3739

38-
void set_buffer(ABuffer*);
40+
void set_buffer(Audio::Buffer*);
3941
private:
4042
explicit SampleWidget(GUI::Widget* parent);
4143
virtual void paint_event(GUI::PaintEvent&) override;
4244

43-
RefPtr<ABuffer> m_buffer;
45+
RefPtr<Audio::Buffer> m_buffer;
4446
};

Applications/SoundPlayer/SoundPlayerWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <LibGUI/GMessageBox.h>
3333
#include <LibM/math.h>
3434

35-
SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<AClientConnection> connection)
35+
SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::ClientConnection> connection)
3636
: m_window(window)
3737
, m_connection(connection)
3838
, m_manager(connection)
@@ -124,7 +124,7 @@ void SoundPlayerWidget::open_file(String path)
124124
return;
125125
}
126126

127-
OwnPtr<AWavLoader> loader = make<AWavLoader>(path);
127+
OwnPtr<Audio::WavLoader> loader = make<Audio::WavLoader>(path);
128128
if (loader->has_error()) {
129129
GUI::MessageBox::show(
130130
String::format(

Applications/SoundPlayer/SoundPlayerWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SoundPlayerWidget final : public GUI::Widget {
4343
PlaybackManager& manager() { return m_manager; }
4444

4545
private:
46-
explicit SoundPlayerWidget(GUI::Window&, NonnullRefPtr<AClientConnection>);
46+
explicit SoundPlayerWidget(GUI::Window&, NonnullRefPtr<Audio::ClientConnection>);
4747

4848
void update_position(const int position);
4949
void update_ui();
@@ -77,7 +77,7 @@ class SoundPlayerWidget final : public GUI::Widget {
7777
};
7878

7979
GUI::Window& m_window;
80-
NonnullRefPtr<AClientConnection> m_connection;
80+
NonnullRefPtr<Audio::ClientConnection> m_connection;
8181
PlaybackManager m_manager;
8282
float m_sample_ratio;
8383
RefPtr<GUI::Label> m_status;

Applications/SoundPlayer/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main(int argc, char** argv)
5050
return 1;
5151
}
5252

53-
auto audio_client = AClientConnection::construct();
53+
auto audio_client = Audio::ClientConnection::construct();
5454
audio_client->handshake();
5555

5656
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {

Libraries/LibAudio/ABuffer.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,26 @@
3131
#include <AK/Vector.h>
3232
#include <AK/SharedBuffer.h>
3333

34+
namespace Audio {
35+
3436
// A single sample in an audio buffer.
3537
// Values are floating point, and should range from -1.0 to +1.0
36-
struct ASample {
37-
ASample()
38+
struct Sample {
39+
Sample()
3840
: left(0)
3941
, right(0)
4042
{
4143
}
4244

4345
// For mono
44-
ASample(float left)
46+
Sample(float left)
4547
: left(left)
4648
, right(left)
4749
{
4850
}
4951

5052
// For stereo
51-
ASample(float left, float right)
53+
Sample(float left, float right)
5254
: left(left)
5355
, right(right)
5456
{
@@ -74,7 +76,7 @@ struct ASample {
7476
right *= pct;
7577
}
7678

77-
ASample& operator+=(const ASample& other)
79+
Sample& operator+=(const Sample& other)
7880
{
7981
left += other.left;
8082
right += other.right;
@@ -88,9 +90,9 @@ struct ASample {
8890
// Small helper to resample from one playback rate to another
8991
// This isn't really "smart", in that we just insert (or drop) samples.
9092
// Should do better...
91-
class AResampleHelper {
93+
class ResampleHelper {
9294
public:
93-
AResampleHelper(float source, float target);
95+
ResampleHelper(float source, float target);
9496

9597
void process_sample(float sample_l, float sample_r);
9698
bool read_sample(float& next_l, float& next_r);
@@ -103,34 +105,34 @@ class AResampleHelper {
103105
};
104106

105107
// A buffer of audio samples, normalized to 44100hz.
106-
class ABuffer : public RefCounted<ABuffer> {
108+
class Buffer : public RefCounted<Buffer> {
107109
public:
108-
static RefPtr<ABuffer> from_pcm_data(ByteBuffer& data, AResampleHelper& resampler, int num_channels, int bits_per_sample);
109-
static NonnullRefPtr<ABuffer> create_with_samples(Vector<ASample>&& samples)
110+
static RefPtr<Buffer> from_pcm_data(ByteBuffer& data, ResampleHelper& resampler, int num_channels, int bits_per_sample);
111+
static NonnullRefPtr<Buffer> create_with_samples(Vector<Sample>&& samples)
110112
{
111-
return adopt(*new ABuffer(move(samples)));
113+
return adopt(*new Buffer(move(samples)));
112114
}
113-
static NonnullRefPtr<ABuffer> create_with_shared_buffer(NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
115+
static NonnullRefPtr<Buffer> create_with_shared_buffer(NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
114116
{
115-
return adopt(*new ABuffer(move(buffer), sample_count));
117+
return adopt(*new Buffer(move(buffer), sample_count));
116118
}
117119

118-
const ASample* samples() const { return (const ASample*)data(); }
120+
const Sample* samples() const { return (const Sample*)data(); }
119121
int sample_count() const { return m_sample_count; }
120122
const void* data() const { return m_buffer->data(); }
121-
int size_in_bytes() const { return m_sample_count * (int)sizeof(ASample); }
123+
int size_in_bytes() const { return m_sample_count * (int)sizeof(Sample); }
122124
int shared_buffer_id() const { return m_buffer->shared_buffer_id(); }
123125
SharedBuffer& shared_buffer() { return *m_buffer; }
124126

125127
private:
126-
explicit ABuffer(Vector<ASample>&& samples)
127-
: m_buffer(*SharedBuffer::create_with_size(samples.size() * sizeof(ASample))),
128+
explicit Buffer(Vector<Sample>&& samples)
129+
: m_buffer(*SharedBuffer::create_with_size(samples.size() * sizeof(Sample))),
128130
m_sample_count(samples.size())
129131
{
130-
memcpy(m_buffer->data(), samples.data(), samples.size() * sizeof(ASample));
132+
memcpy(m_buffer->data(), samples.data(), samples.size() * sizeof(Sample));
131133
}
132134

133-
explicit ABuffer(NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
135+
explicit Buffer(NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
134136
: m_buffer(move(buffer)),
135137
m_sample_count(sample_count)
136138
{
@@ -139,3 +141,5 @@ class ABuffer : public RefCounted<ABuffer> {
139141
NonnullRefPtr<SharedBuffer> m_buffer;
140142
const int m_sample_count;
141143
};
144+
145+
}

Libraries/LibAudio/AClientConnection.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,88 +28,92 @@
2828
#include <LibAudio/ABuffer.h>
2929
#include <LibAudio/AClientConnection.h>
3030

31-
AClientConnection::AClientConnection()
31+
namespace Audio {
32+
33+
ClientConnection::ClientConnection()
3234
: IPC::ServerConnection<AudioClientEndpoint, AudioServerEndpoint>(*this, "/tmp/portal/audio")
3335
{
3436
}
3537

36-
void AClientConnection::handshake()
38+
void ClientConnection::handshake()
3739
{
3840
auto response = send_sync<AudioServer::Greet>();
3941
set_my_client_id(response->client_id());
4042
}
4143

42-
void AClientConnection::enqueue(const ABuffer& buffer)
44+
void ClientConnection::enqueue(const Buffer& buffer)
4345
{
4446
for (;;) {
45-
const_cast<ABuffer&>(buffer).shared_buffer().share_with(server_pid());
47+
const_cast<Buffer&>(buffer).shared_buffer().share_with(server_pid());
4648
auto response = send_sync<AudioServer::EnqueueBuffer>(buffer.shared_buffer_id(), buffer.sample_count());
4749
if (response->success())
4850
break;
4951
sleep(1);
5052
}
5153
}
5254

53-
bool AClientConnection::try_enqueue(const ABuffer& buffer)
55+
bool ClientConnection::try_enqueue(const Buffer& buffer)
5456
{
55-
const_cast<ABuffer&>(buffer).shared_buffer().share_with(server_pid());
57+
const_cast<Buffer&>(buffer).shared_buffer().share_with(server_pid());
5658
auto response = send_sync<AudioServer::EnqueueBuffer>(buffer.shared_buffer_id(), buffer.sample_count());
5759
return response->success();
5860
}
5961

60-
bool AClientConnection::get_muted()
62+
bool ClientConnection::get_muted()
6163
{
6264
return send_sync<AudioServer::GetMuted>()->muted();
6365
}
6466

65-
void AClientConnection::set_muted(bool muted)
67+
void ClientConnection::set_muted(bool muted)
6668
{
6769
send_sync<AudioServer::SetMuted>(muted);
6870
}
6971

70-
int AClientConnection::get_main_mix_volume()
72+
int ClientConnection::get_main_mix_volume()
7173
{
7274
return send_sync<AudioServer::GetMainMixVolume>()->volume();
7375
}
7476

75-
void AClientConnection::set_main_mix_volume(int volume)
77+
void ClientConnection::set_main_mix_volume(int volume)
7678
{
7779
send_sync<AudioServer::SetMainMixVolume>(volume);
7880
}
7981

80-
int AClientConnection::get_remaining_samples()
82+
int ClientConnection::get_remaining_samples()
8183
{
8284
return send_sync<AudioServer::GetRemainingSamples>()->remaining_samples();
8385
}
8486

85-
int AClientConnection::get_played_samples()
87+
int ClientConnection::get_played_samples()
8688
{
8789
return send_sync<AudioServer::GetPlayedSamples>()->played_samples();
8890
}
8991

90-
void AClientConnection::set_paused(bool paused)
92+
void ClientConnection::set_paused(bool paused)
9193
{
9294
send_sync<AudioServer::SetPaused>(paused);
9395
}
9496

95-
void AClientConnection::clear_buffer(bool paused)
97+
void ClientConnection::clear_buffer(bool paused)
9698
{
9799
send_sync<AudioServer::ClearBuffer>(paused);
98100
}
99101

100-
int AClientConnection::get_playing_buffer()
102+
int ClientConnection::get_playing_buffer()
101103
{
102104
return send_sync<AudioServer::GetPlayingBuffer>()->buffer_id();
103105
}
104106

105-
void AClientConnection::handle(const AudioClient::FinishedPlayingBuffer& message)
107+
void ClientConnection::handle(const AudioClient::FinishedPlayingBuffer& message)
106108
{
107109
if (on_finish_playing_buffer)
108110
on_finish_playing_buffer(message.buffer_id());
109111
}
110112

111-
void AClientConnection::handle(const AudioClient::MutedStateChanged& message)
113+
void ClientConnection::handle(const AudioClient::MutedStateChanged& message)
112114
{
113115
if (on_muted_state_change)
114116
on_muted_state_change(message.muted());
115117
}
118+
119+
}

0 commit comments

Comments
 (0)