Add flag to allow ALSA backend to fall back to nearest avail. nperiods

This commit is contained in:
Robin Gareus 2020-04-28 02:46:44 +02:00
parent 30a60f45df
commit 13ed8da2bc
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 24 additions and 8 deletions

View file

@ -487,9 +487,11 @@ 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;
}
}
snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
snd_pcm_hw_params_get_access (_play_hwpar, &_play_access);
@ -774,12 +776,25 @@ 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;
}
}
if (snd_pcm_hw_params_set_buffer_size (handle, hwpar, _fsize * nfrag) < 0)
{
if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s buffer length to %lu.\n",

View file

@ -60,7 +60,8 @@ public:
DEBUG_DATA = 8,
DEBUG_ALL = 15,
FORCE_16B = 256,
FORCE_2CH = 512
FORCE_2CH = 512,
FRAG_NEAR = 1024
};
void printinfo (void);