summaryrefslogtreecommitdiff
path: root/Servers/AudioServer/ASMixer.cpp
AgeCommit message (Collapse)Author
2019-12-25AudioServer: Block the mixer thread when there's nothing to doAndreas Kling
Use a pthread_cond_t to have the ASMixer thread wait until a client has connected and added a buffer queue to the "pending mixing" vector. This solves the long-standing issue of the system "idling" at ~8% CPU.
2019-12-22AudioServer: Remove any pending mixer queues whose client disconnectedAndreas Kling
We were pumping the sound device full of silence even after the last audio client disconnected.
2019-12-08AudioServer: Set the mixer thread name to "AudioServer[mixer]"Andrew Kaster
2019-11-23AudioServer: Broadcast muted state changes to all clientsAndreas Kling
2019-11-22AudioServer: Allow muting the system audioAndreas Kling
This patch adds muting to ASMixer, which works by substituting what we would normally send to the sound card with zero-filled memory instead. We do it this way to ensure that the queued sample buffers keep getting played (silently.) This is obviously not the perfect way of doing this, and in the future we should improve on this, and also find a way to utilize any hardware mixing functions in the sound card.
2019-10-19AudioServer: Added ability to get count of samples in the buffer queueTill Mayer
Now the AClientConnection can get the count of samples still in the buffer queue.
2019-09-21LibCore: Convert CFile to ObjectPtrAndreas Kling
2019-08-26AudioServer: Port threading to LibThreadSergey Bugaev
2019-08-18AudioServer: Turn ASMixer into a CObjectAndreas Kling
It was wrongly inheriting from RefCounted<AudioServer> without using reference counting. Let's just make it a CObject instead.
2019-07-29AudioServer: Add a "main mix volume" and a simple program to get/set itAndreas Kling
Give the mixer a main volume value (percent) that we scale all the outgoing samples by (before clipping.) Also add a simple "avol" program for querying and setting the volume: - "avol" prints the current volume. - "avol 200" sets the main mix volume to 200%
2019-07-28AudioServer+LibAudio: Make mixing queue-based instead of buffer-based.Andreas Kling
Each client connection now sets up an ASBufferQueue, which is basically a queue of ABuffers. This allows us to immediately start streaming the next pending buffer whenever our current buffer runs out of samples. This makes the majority of the skippiness go away for me. :^) Also get rid of the old PlayBuffer API, since we don't need it anymore.
2019-07-27AudioServer: Let ASMixer notify ASClientConnection about finished buffers.Andreas Kling
Instead of posting a message directly from ASMixer, notify the client via ASClientConnection::did_finish_playing_buffer().
2019-07-27Audio: Make ABuffer sit on top of a SharedBuffer.Andreas Kling
This allows us to carry the same buffer all the way from the WAV loader to the AudioServer mixer. This alleviates some of the stutter, but there's still a noticeable skip when switching buffers. We're gonna need to do better. :^)
2019-07-27AudioServer: Avoid two heap allocations per mixing iteration.Andreas Kling
2019-07-27Audio: Make basic streaming WAV playback work.Andreas Kling
I had to solve a bunch of things simultaneously to make this work. Refactor AWavLoader to be a streaming loader rather than a one-shot one. The constructor parses the header, and if everything looks good, you can repeatedly ask the AWavLoader for sample buffers until it runs out. Also send a message from AudioServer when a buffer has finished playing. That allows us to implement a blocking variant of play(). Use all of this in aplay to play WAV files chunk-at-a-time. This is definitely not perfect and it's a little glitchy and skippy, but I think it's a step in the right direction.
2019-07-17AudioServer: Use Vector::append(Vector&&) for pending mix buffers.Andreas Kling
Vector::append(Vector&&) is a simple pointer transfer when appending to an empty Vector. :^)
2019-07-17ABuffer: clamp -> clipRobin Burchell
More natural term when talking about audio :)
2019-07-17Work on AudioServerRobin Burchell
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.