aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/pulseaudio.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-03-27 01:03:01 -0700
committerChris Robinson <[email protected]>2020-03-27 01:03:01 -0700
commit8731accd3f40b25632fa0f90c8954a5f0b1fd5a5 (patch)
treec679752a6538ced01ae89c4af1269447b6f80543 /alc/backends/pulseaudio.cpp
parente73c0979a16ebde1cfa9bda308c9b62b24541a91 (diff)
Make sure prebuf is filled when starting pulseaudio playback
Diffstat (limited to 'alc/backends/pulseaudio.cpp')
-rw-r--r--alc/backends/pulseaudio.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp
index bd1dd54a..4d546f44 100644
--- a/alc/backends/pulseaudio.cpp
+++ b/alc/backends/pulseaudio.cpp
@@ -1050,8 +1050,32 @@ bool PulsePlayback::start()
pa_stream_set_write_callback(mStream, &PulsePlayback::streamWriteCallbackC, this);
pa_operation *op{pa_stream_cork(mStream, 0, &PulseMainloop::streamSuccessCallbackC,
&mMainloop)};
- mMainloop.waitForOperation(op, plock);
+ /* Write some (silent) samples to fill the prebuf amount if needed. */
+ if(size_t prebuf{mAttr.prebuf})
+ {
+ prebuf = minz(prebuf, pa_stream_writable_size(mStream));
+
+ void *buf{pa_xmalloc(prebuf)};
+ switch(mSpec.format)
+ {
+ case PA_SAMPLE_U8:
+ std::fill_n(static_cast<uint8_t*>(buf), prebuf, 0x80);
+ break;
+ case PA_SAMPLE_ALAW:
+ std::fill_n(static_cast<uint8_t*>(buf), prebuf, 0xD5);
+ break;
+ case PA_SAMPLE_ULAW:
+ std::fill_n(static_cast<uint8_t*>(buf), prebuf, 0x7f);
+ break;
+ default:
+ std::fill_n(static_cast<uint8_t*>(buf), prebuf, 0x00);
+ break;
+ }
+ pa_stream_write(mStream, buf, prebuf, pa_xfree, 0, PA_SEEK_RELATIVE);
+ }
+
+ mMainloop.waitForOperation(op, plock);
return true;
}