summaryrefslogtreecommitdiff
path: root/libs/backends/alsa
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-03-30 06:14:41 +0200
committerRobin Gareus <robin@gareus.org>2020-03-30 15:20:54 +0200
commit23baeee829359bd8ed2e9090743ad82188425f26 (patch)
treec91a44e86e1fb9e377dea52a83f190826721fc59 /libs/backends/alsa
parent591c219349ad9f36984f9bd650115c8ddb83c069 (diff)
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.
Diffstat (limited to 'libs/backends/alsa')
-rw-r--r--libs/backends/alsa/alsa_audiobackend.cc16
-rw-r--r--libs/backends/alsa/zita-alsa-pcmi.cc4
2 files changed, 17 insertions, 3 deletions
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<AlsaPort*>::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;
}