summaryrefslogtreecommitdiff
path: root/libs/backends
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-04-29 23:55:51 +0200
committerRobin Gareus <robin@gareus.org>2020-04-29 23:56:24 +0200
commit3a6a9cfa6c19db0205e80e88259aec5893c01fc0 (patch)
treea92c4ee94c9af5fbbd1aac14577235b8eccbec30 /libs/backends
parent6eb48e40a033042ca0394dadc0401433cd988d6b (diff)
Tweak ALSA nperiod setting, fallback to nearest
This is mainly for RME RayDAT that has a fixed buffersize of 16k: dev_name : hw:HDSPMxc2f6c5,0 channels : 36 min_rate : 32000 max_rate : 192000 min_bufz : 16384 max_bufz : 16384 min_nper : 4 max_nper : 512 However nperiod configuration determines the effective latency regardless. This is similar to https://github.com/jackaudio/jack1/blob/master/drivers/alsa/alsa_driver.c#L476-L486
Diffstat (limited to 'libs/backends')
-rw-r--r--libs/backends/alsa/alsa_audiobackend.cc16
-rw-r--r--libs/backends/alsa/zita-alsa-pcmi.cc41
-rw-r--r--libs/backends/alsa/zita-alsa-pcmi.h3
3 files changed, 24 insertions, 36 deletions
diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc
index 80b0e36e6f..71bef7517a 100644
--- a/libs/backends/alsa/alsa_audiobackend.cc
+++ b/libs/backends/alsa/alsa_audiobackend.cc
@@ -270,25 +270,23 @@ std::vector<uint32_t>
AlsaAudioBackend::available_period_sizes (const std::string& driver, const std::string& device) const
{
std::vector<uint32_t> ps;
+ ps.push_back (2);
ALSADeviceInfo* nfo = NULL;
if (device == get_standard_device_name(DeviceNone)) {
return ps;
}
+
if (device == _output_audio_device && _output_audio_device_info.valid) {
nfo = &_output_audio_device_info;
- } else {
- ps.push_back (2);
- return ps;
- }
-
- if (nfo->min_nper == 2) {
- ps.push_back (2);
- if (nfo->max_nper >= 3) {
+ if (nfo->max_nper > 2) {
ps.push_back (3);
}
+ if (nfo->max_nper > 3) {
+ ps.push_back (nfo->min_nper);
+ }
} else {
- ps.push_back (nfo->min_nper);
+ ps.push_back (3);
}
return ps;
diff --git a/libs/backends/alsa/zita-alsa-pcmi.cc b/libs/backends/alsa/zita-alsa-pcmi.cc
index fe3e0f1a8b..9d7068cf36 100644
--- a/libs/backends/alsa/zita-alsa-pcmi.cc
+++ b/libs/backends/alsa/zita-alsa-pcmi.cc
@@ -486,11 +486,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
}
if (snd_pcm_hw_params_get_periods (_play_hwpar, &nfrag, &dir) || (nfrag != _play_nfrag) || dir)
{
- if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested number of periods for playback.\n");
- if ((_debug & FRAG_NEAR) == 0) {
- _state = -5;
- return;
- }
+ if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi warning: requested %u periods for playback, using %u.\n", _play_nfrag, nfrag);
}
snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
@@ -776,29 +772,24 @@ int Alsa_pcmi::set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const
sname, _fsize);
return -4;
}
- if ((_debug & FRAG_NEAR)) {
- unsigned int nf = nfrag;
- snd_pcm_hw_params_set_periods_min (handle, hwpar, &nf, NULL);
- if (nf > nfrag) {
- nfrag = nf;
- }
- if (snd_pcm_hw_params_set_periods_near (handle, hwpar, &nfrag, NULL) < 0) {
- if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s periods to %u.\n",
- sname, nfrag);
- return -5;
- }
- } else {
- if (snd_pcm_hw_params_set_periods (handle, hwpar, nfrag, 0) < 0)
- {
- if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s periods to %u.\n",
- sname, nfrag);
- return -5;
- }
+
+ unsigned int nf = nfrag;
+ snd_pcm_hw_params_set_periods_min (handle, hwpar, &nf, NULL);
+ if (nf < nfrag) {
+ nf = nfrag;
+ }
+ if (snd_pcm_hw_params_set_periods_near (handle, hwpar, &nf, NULL) < 0) {
+ if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s periods to %u (requested %u).\n",
+ sname, nf, nfrag);
+ return -5;
}
- if (snd_pcm_hw_params_set_buffer_size (handle, hwpar, _fsize * nfrag) < 0)
+
+ if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: use %d periods for %s ((requested %u).\n", nf, sname, nfrag);
+
+ if (snd_pcm_hw_params_set_buffer_size (handle, hwpar, _fsize * nf) < 0)
{
if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s buffer length to %lu.\n",
- sname, _fsize * nfrag);
+ sname, _fsize * nf);
return -4;
}
if (snd_pcm_hw_params (handle, hwpar) < 0)
diff --git a/libs/backends/alsa/zita-alsa-pcmi.h b/libs/backends/alsa/zita-alsa-pcmi.h
index 65a1d82d2d..48c2396c19 100644
--- a/libs/backends/alsa/zita-alsa-pcmi.h
+++ b/libs/backends/alsa/zita-alsa-pcmi.h
@@ -60,8 +60,7 @@ public:
DEBUG_DATA = 8,
DEBUG_ALL = 15,
FORCE_16B = 256,
- FORCE_2CH = 512,
- FRAG_NEAR = 1024
+ FORCE_2CH = 512
};
void printinfo (void);