diff --git a/extern/audaspace/include/util/RingBuffer.h b/extern/audaspace/include/util/RingBuffer.h index 67bd1cc8640..6173c10ddcc 100644 --- a/extern/audaspace/include/util/RingBuffer.h +++ b/extern/audaspace/include/util/RingBuffer.h @@ -74,6 +74,8 @@ public: size_t write(data_t* source, size_t size); + void clear(); + /** * Resets the ring buffer to a state where nothing has been written or read. */ diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp index a018e9e4cf2..b2fc2d4d44f 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp @@ -91,6 +91,12 @@ void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t total_bytes, AUD_pa_stream_begin_write(stream, reinterpret_cast(&buffer), &num_bytes); + if(device->m_clear) + { + device->m_clear = false; + device->m_ring_buffer.clear(); + } + size_t readsamples = device->m_ring_buffer.getReadSize(); readsamples = std::min(readsamples, size_t(num_bytes)) / sample_size; @@ -119,11 +125,18 @@ void PulseAudioDevice::playing(bool playing) AUD_pa_threaded_mainloop_lock(m_mainloop); AUD_pa_stream_cork(m_stream, playing ? 0 : 1, nullptr, nullptr); AUD_pa_threaded_mainloop_unlock(m_mainloop); + + if(!playing) + { + AUD_pa_stream_flush(m_stream, nullptr, nullptr); + m_clear = true; + } } PulseAudioDevice::PulseAudioDevice(const std::string &name, DeviceSpecs specs, int buffersize) : m_synchronizer(this), m_playback(false), + m_clear(false), m_state(PA_CONTEXT_UNCONNECTED), m_valid(true), m_underflows(0) diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h index 23306168173..e985dfa66cc 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h @@ -60,6 +60,11 @@ private: */ volatile bool m_playback; + /** + * Set when playback is paused in order to later clear the ring buffer when the playback starts again. + */ + volatile bool m_clear; + pa_threaded_mainloop* m_mainloop; pa_context* m_context; pa_stream* m_stream; diff --git a/extern/audaspace/src/util/RingBuffer.cpp b/extern/audaspace/src/util/RingBuffer.cpp index 3796684aa88..27f661b9e6b 100644 --- a/extern/audaspace/src/util/RingBuffer.cpp +++ b/extern/audaspace/src/util/RingBuffer.cpp @@ -116,6 +116,11 @@ size_t RingBuffer::write(data_t* source, size_t size) return size; } +void RingBuffer::clear() +{ + m_read = m_write; +} + void RingBuffer::reset() { m_read = 0;