mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +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.
This commit is contained in:
parent
3db9706e57
commit
2df6f0e87f
19 changed files with 873 additions and 141 deletions
37
Servers/AudioServer/ASEventLoop.cpp
Normal file
37
Servers/AudioServer/ASEventLoop.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "ASEventLoop.h"
|
||||
#include "ASClientConnection.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
ASEventLoop::ASEventLoop()
|
||||
{
|
||||
unlink("/tmp/asportal");
|
||||
|
||||
sockaddr_un address;
|
||||
address.sun_family = AF_LOCAL;
|
||||
strcpy(address.sun_path, "/tmp/asportal");
|
||||
int rc = bind(m_server_sock.fd(), (const sockaddr*)&address, sizeof(address));
|
||||
ASSERT(rc == 0);
|
||||
rc = listen(m_server_sock.fd(), 5);
|
||||
ASSERT(rc == 0);
|
||||
|
||||
m_server_notifier = make<CNotifier>(m_server_sock.fd(), CNotifier::Read);
|
||||
m_server_notifier->on_ready_to_read = [this] { drain_server(); };
|
||||
}
|
||||
|
||||
void ASEventLoop::drain_server()
|
||||
{
|
||||
sockaddr_un address;
|
||||
socklen_t address_size = sizeof(address);
|
||||
int client_fd = accept(m_server_sock.fd(), (sockaddr*)&address, &address_size);
|
||||
if (client_fd < 0) {
|
||||
dbgprintf("AudioServer: accept() failed: %s\n", strerror(errno));
|
||||
} else {
|
||||
dbgprintf("AudioServer: accept()ed client %d\n", client_fd);
|
||||
static int s_next_client_id = 0;
|
||||
new ASClientConnection(client_fd, s_next_client_id++, m_mixer);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue