From 23baeee829359bd8ed2e9090743ad82188425f26 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 30 Mar 2020 06:14:41 +0200 Subject: [PATCH] Tweak engine startup, initial silence This can help when running with very low latency and the initial process callback is [indirectly] expensive. E.g. load a heavy session the a RPi4, initial setup can pull in a lot of data, which blocks the bus. In particular with the ALSA backend this can lead to poll timeout which effectively stops the backend. --- libs/ardour/audioengine.cc | 2 +- libs/backends/alsa/alsa_audiobackend.cc | 16 +++++++++++++++- libs/backends/alsa/zita-alsa-pcmi.cc | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index c0350a7802..a4ee9dc587 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -728,7 +728,7 @@ AudioEngine::set_session (Session *s) SessionHandlePtr::set_session (s); if (_session) { - _init_countdown = std::max (8, (int)(_backend->sample_rate () / _backend->buffer_size ()) / 2); + _init_countdown = std::max (8, (int)(_backend->sample_rate () / _backend->buffer_size ()) / 4); } } diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index 357b00c044..947b6d5992 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -2086,7 +2086,6 @@ AlsaAudioBackend::main_process_thread () double dll_w2 = dll_w1 * dll_w1; uint64_t clock1; - _pcmi->pcm_start (); int no_proc_errors = 0; const int bailout = 5 * _samplerate / _samples_per_period; @@ -2095,6 +2094,21 @@ AlsaAudioBackend::main_process_thread () const double sr_norm = 1e-6 * (double) _samplerate / (double)_samples_per_period; + /* warm up */ + int cnt = std::max (8, (int)(_samplerate / _samples_per_period) / 2); + for (int w = 0; w < cnt; ++w) { + for (std::vector::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) { + memset ((*it)->get_buffer (_samples_per_period), 0, _samples_per_period * sizeof (Sample)); + } + if (engine.process_callback (_samples_per_period)) { + _active = false; + return 0; + } + Glib::usleep (1000000 * (_samples_per_period / _samplerate )); + } + + _pcmi->pcm_start (); + while (_run) { long nr; bool xrun = false; diff --git a/libs/backends/alsa/zita-alsa-pcmi.cc b/libs/backends/alsa/zita-alsa-pcmi.cc index 534d183025..a35b2b3f03 100644 --- a/libs/backends/alsa/zita-alsa-pcmi.cc +++ b/libs/backends/alsa/zita-alsa-pcmi.cc @@ -230,7 +230,7 @@ snd_pcm_sframes_t Alsa_pcmi::pcm_wait (void) { _state = -1; if (!recover ()) { - _state = 1; + _state = 1; } return 0; } @@ -239,7 +239,7 @@ snd_pcm_sframes_t Alsa_pcmi::pcm_wait (void) { _state = -1; if (!recover ()) { - _state = 1; + _state = 1; } return 0; }