From a8ff35accb500da06d114335ee03ac67bcd26863 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 30 Mar 2020 16:58:55 +0200 Subject: [PATCH] Reset DSP load on backend re-start and after freewheeling --- libs/backends/alsa/alsa_audiobackend.cc | 2 ++ libs/backends/coreaudio/coreaudio_backend.cc | 2 ++ libs/backends/portaudio/portaudio_backend.cc | 7 +++++++ libs/backends/pulseaudio/pulseaudio_backend.cc | 2 ++ 4 files changed, 13 insertions(+) diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index 947b6d5992..ae4ef51448 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -2107,6 +2107,7 @@ AlsaAudioBackend::main_process_thread () Glib::usleep (1000000 * (_samples_per_period / _samplerate )); } + _dsp_load_calc.reset (); _pcmi->pcm_start (); while (_run) { @@ -2124,6 +2125,7 @@ AlsaAudioBackend::main_process_thread () _pcmi->pcm_stop (); _pcmi->pcm_start (); drain_slaves = true; + _dsp_load_calc.reset (); } } diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 3e99155bda..13d739ebf6 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -708,6 +708,7 @@ CoreAudioBackend::_start (bool for_latency_measurement) _port_change_flag = true; pre_process (); + _dsp_load_calc.reset (); // all systems go. _pcmio->set_xrun_callback (xrun_callback_ptr, this); _preinit = false; @@ -1797,6 +1798,7 @@ CoreAudioBackend::process_callback (const uint32_t n_samples, const uint64_t hos if (!_run || _freewheel || _preinit) { // NB if we return 1, the output is // zeroed by the coreaudio callback + _dsp_load_calc.reset (); return 1; } diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index db57b3cc31..71f50b39ba 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -684,6 +684,8 @@ PortAudioBackend::_start (bool for_latency_measurement) engine.reconnect_ports (); _port_change_flag = false; + _dsp_calc.reset (); + if (_use_blocking_api) { if (!start_blocking_process_thread()) { return ProcessThreadStartError; @@ -925,6 +927,7 @@ PortAudioBackend::freewheel_process_thread() _freewheel_ack = false; // prepare next handshake _midiio->set_enabled(true); engine.freewheel_callback (_freewheeling); + _dsp_calc.reset (); } else { first_run = true; _freewheel = true; @@ -1883,11 +1886,15 @@ PortAudioBackend::blocking_process_thread () DWORD tid = GetCurrentThreadId (); DEBUG_THREADS (string_compose ("Process Thread Master ID: %1\n", tid)); + _dsp_calc.reset (); while (_run) { if (_freewheeling != _freewheel) { _freewheel = _freewheeling; engine.freewheel_callback (_freewheel); + if (!_freewheel) { + _dsp_calc.reset (); + } } if (!_freewheel) { diff --git a/libs/backends/pulseaudio/pulseaudio_backend.cc b/libs/backends/pulseaudio/pulseaudio_backend.cc index b742a86c86..9d550a3449 100644 --- a/libs/backends/pulseaudio/pulseaudio_backend.cc +++ b/libs/backends/pulseaudio/pulseaudio_backend.cc @@ -1412,6 +1412,7 @@ PulseAudioBackend::main_process_thread () } } + _dsp_load_calc.reset (); stream_latency_update_cb (p_stream, this); while (_run) { @@ -1436,6 +1437,7 @@ PulseAudioBackend::main_process_thread () if (!sync_pulse (pa_stream_flush (p_stream, stream_operation_cb, this)) || !_operation_succeeded) { break; } + _dsp_load_calc.reset (); } }