From 1341664e48a8d421beb6da9f0632e39a8105d16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20M=C3=BCller?= Date: Wed, 18 Aug 2021 22:22:21 +0200 Subject: Audaspace: porting PulseAudio fixes from upstream. --- .../audaspace/plugins/pulseaudio/PulseAudioDevice.cpp | 19 ++++++++++++++----- .../audaspace/plugins/pulseaudio/PulseAudioDevice.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'extern') diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp index cbfb5e96e6c..bf3fad82620 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp @@ -32,17 +32,24 @@ void PulseAudioDevice::PulseAudio_state_callback(pa_context *context, void *data device->m_state = AUD_pa_context_get_state(context); } -void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t num_bytes, void *data) +void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t total_bytes, void *data) { PulseAudioDevice* device = (PulseAudioDevice*)data; void* buffer; - AUD_pa_stream_begin_write(stream, &buffer, &num_bytes); + while(total_bytes > 0) + { + size_t num_bytes = total_bytes; + + AUD_pa_stream_begin_write(stream, &buffer, &num_bytes); + + device->mix((data_t*)buffer, num_bytes / AUD_DEVICE_SAMPLE_SIZE(device->m_specs)); - device->mix((data_t*)buffer, num_bytes / AUD_DEVICE_SAMPLE_SIZE(device->m_specs)); + AUD_pa_stream_write(stream, buffer, num_bytes, nullptr, 0, PA_SEEK_RELATIVE); - AUD_pa_stream_write(stream, buffer, num_bytes, nullptr, 0, PA_SEEK_RELATIVE); + total_bytes -= num_bytes; + } } void PulseAudioDevice::PulseAudio_underflow(pa_stream *stream, void *data) @@ -96,7 +103,6 @@ void PulseAudioDevice::runMixingThread() PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buffersize) : m_state(PA_CONTEXT_UNCONNECTED), - m_buffersize(buffersize), m_underflows(0) { m_mainloop = AUD_pa_mainloop_new(); @@ -187,6 +193,9 @@ PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buff AUD_pa_stream_set_write_callback(m_stream, PulseAudio_request, this); AUD_pa_stream_set_underflow_callback(m_stream, PulseAudio_underflow, this); + buffersize *= AUD_DEVICE_SAMPLE_SIZE(m_specs); + m_buffersize = buffersize; + pa_buffer_attr buffer_attr; buffer_attr.fragsize = -1U; diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h index be34cc9032b..45b813a5755 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h @@ -59,7 +59,7 @@ private: * \param num_bytes The length in bytes to be supplied. * \param data The PulseAudio device. */ - AUD_LOCAL static void PulseAudio_request(pa_stream* stream, size_t num_bytes, void* data); + AUD_LOCAL static void PulseAudio_request(pa_stream* stream, size_t total_bytes, void* data); /** * Reports an underflow from the PulseAudio server. -- cgit v1.2.3