mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-17 04:06:26 +01:00
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
This commit is contained in:
parent
6eb48e40a0
commit
3a6a9cfa6c
4 changed files with 26 additions and 38 deletions
|
|
@ -115,8 +115,8 @@ ARDOUR::get_alsa_device_parameters (const char* device_name, const bool play, AL
|
||||||
fprintf (stdout, " channels : %u\n", nfo->max_channels);
|
fprintf (stdout, " channels : %u\n", nfo->max_channels);
|
||||||
fprintf (stdout, " min_rate : %u\n", nfo->min_rate);
|
fprintf (stdout, " min_rate : %u\n", nfo->min_rate);
|
||||||
fprintf (stdout, " max_rate : %u\n", nfo->max_rate);
|
fprintf (stdout, " max_rate : %u\n", nfo->max_rate);
|
||||||
fprintf (stdout, " min_psiz : %lu\n", nfo->min_size);
|
fprintf (stdout, " min_psiz : %lu\n", min_psiz);
|
||||||
fprintf (stdout, " max_psiz : %lu\n", nfo->max_size);
|
fprintf (stdout, " max_psiz : %lu\n", max_psiz);
|
||||||
fprintf (stdout, " min_bufz : %lu\n", min_bufz);
|
fprintf (stdout, " min_bufz : %lu\n", min_bufz);
|
||||||
fprintf (stdout, " max_bufz : %lu\n", max_bufz);
|
fprintf (stdout, " max_bufz : %lu\n", max_bufz);
|
||||||
fprintf (stdout, " min_nper : %d\n", nfo->min_nper);
|
fprintf (stdout, " min_nper : %d\n", nfo->min_nper);
|
||||||
|
|
|
||||||
|
|
@ -270,25 +270,23 @@ std::vector<uint32_t>
|
||||||
AlsaAudioBackend::available_period_sizes (const std::string& driver, const std::string& device) const
|
AlsaAudioBackend::available_period_sizes (const std::string& driver, const std::string& device) const
|
||||||
{
|
{
|
||||||
std::vector<uint32_t> ps;
|
std::vector<uint32_t> ps;
|
||||||
|
ps.push_back (2);
|
||||||
|
|
||||||
ALSADeviceInfo* nfo = NULL;
|
ALSADeviceInfo* nfo = NULL;
|
||||||
if (device == get_standard_device_name(DeviceNone)) {
|
if (device == get_standard_device_name(DeviceNone)) {
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device == _output_audio_device && _output_audio_device_info.valid) {
|
if (device == _output_audio_device && _output_audio_device_info.valid) {
|
||||||
nfo = &_output_audio_device_info;
|
nfo = &_output_audio_device_info;
|
||||||
} else {
|
if (nfo->max_nper > 2) {
|
||||||
ps.push_back (2);
|
|
||||||
return ps;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nfo->min_nper == 2) {
|
|
||||||
ps.push_back (2);
|
|
||||||
if (nfo->max_nper >= 3) {
|
|
||||||
ps.push_back (3);
|
ps.push_back (3);
|
||||||
}
|
}
|
||||||
|
if (nfo->max_nper > 3) {
|
||||||
|
ps.push_back (nfo->min_nper);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ps.push_back (nfo->min_nper);
|
ps.push_back (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
|
|
|
||||||
|
|
@ -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 (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 & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi warning: requested %u periods for playback, using %u.\n", _play_nfrag, nfrag);
|
||||||
if ((_debug & FRAG_NEAR) == 0) {
|
|
||||||
_state = -5;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
|
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);
|
sname, _fsize);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
if ((_debug & FRAG_NEAR)) {
|
|
||||||
unsigned int nf = nfrag;
|
unsigned int nf = nfrag;
|
||||||
snd_pcm_hw_params_set_periods_min (handle, hwpar, &nf, NULL);
|
snd_pcm_hw_params_set_periods_min (handle, hwpar, &nf, NULL);
|
||||||
if (nf > nfrag) {
|
if (nf < nfrag) {
|
||||||
nfrag = nf;
|
nf = nfrag;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (snd_pcm_hw_params_set_buffer_size (handle, hwpar, _fsize * nfrag) < 0)
|
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 (_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",
|
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;
|
return -4;
|
||||||
}
|
}
|
||||||
if (snd_pcm_hw_params (handle, hwpar) < 0)
|
if (snd_pcm_hw_params (handle, hwpar) < 0)
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,7 @@ public:
|
||||||
DEBUG_DATA = 8,
|
DEBUG_DATA = 8,
|
||||||
DEBUG_ALL = 15,
|
DEBUG_ALL = 15,
|
||||||
FORCE_16B = 256,
|
FORCE_16B = 256,
|
||||||
FORCE_2CH = 512,
|
FORCE_2CH = 512
|
||||||
FRAG_NEAR = 1024
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void printinfo (void);
|
void printinfo (void);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue