Commit f1ef9f9d authored by Yue Wang's avatar Yue Wang Committed by Max Kellermann

OSXOutputPlugin: set the buffer time to be 100ms

[mk: the following text was copied from https://github.com/MusicPlayerDaemon/MPD/pull/167] For certain format (hi-res files) and normal buffer size hardware, The hardware may at once consume most of the buffers. However, in Delay() function, MPD is supposed to wait for 25 ms after the next try. it will create a hiccup. The negative impact is much major than increasing the latency. I understand larger buffers come at a price. That's why in my earlier commit last year I significantly reduced it. However, the buffer size in CoreAudio is set according to the hardware, which is super small latency. For instance, the system audio of 2015 generation of macbook pro has maximum buffer size of 4096 samples, which is just 0.09s for 44.1k framerate, or 0.04s for 96k frames --- . compare to the 0.5 sec latency alsa plugin has, even if we quadruple it, it's still super tiny.
parent dfaf0874
ver 0.20.13 (not yet released)
* output
- osx: set up ring buffer to hold at least 100ms
* database
- simple: don't purge mount points on update/rescan
- simple: fix "mount" bug caused by bad compiler optimization
......
......@@ -36,9 +36,10 @@
#include <memory>
static constexpr unsigned MPD_OSX_BUFFER_TIME_MS = 100;
struct OSXOutput {
AudioOutput base;
/* configuration settings */
OSType component_subtype;
/* only applicable with kAudioUnitSubType_HALOutput */
......@@ -693,7 +694,9 @@ osx_output_open(AudioOutput *ao, AudioFormat &audio_format)
errormsg);
}
od->ring_buffer = new boost::lockfree::spsc_queue<uint8_t>(buffer_frame_size);
size_t ring_buffer_size = std::max<size_t>(buffer_frame_size,
MPD_OSX_BUFFER_TIME_MS * audio_format.GetFrameSize() * audio_format.sample_rate / 1000);
od->ring_buffer = new boost::lockfree::spsc_queue<uint8_t>(ring_buffer_size);
status = AudioOutputUnitStart(od->au);
if (status != 0) {
......@@ -717,7 +720,7 @@ osx_output_delay(AudioOutput *ao) noexcept
OSXOutput *od = (OSXOutput *)ao;
return od->ring_buffer->write_available()
? std::chrono::steady_clock::duration::zero()
: std::chrono::milliseconds(25);
: std::chrono::milliseconds(MPD_OSX_BUFFER_TIME_MS / 4);
}
int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment