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,8 +487,10 @@ 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: can't get requested number of periods for playback.\n");
_state = -5; if ((_debug & FRAG_NEAR) == 0) {
return; _state = -5;
return;
}
} }
snd_pcm_hw_params_get_format (_play_hwpar, &_play_format); snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
@ -774,11 +776,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 (snd_pcm_hw_params_set_periods (handle, hwpar, nfrag, 0) < 0) if ((_debug & FRAG_NEAR)) {
{ unsigned int nf = nfrag;
if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't set %s periods to %u.\n", snd_pcm_hw_params_set_periods_min (handle, hwpar, &nf, NULL);
sname, nfrag); if (nf > nfrag) {
return -5; 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 (snd_pcm_hw_params_set_buffer_size (handle, hwpar, _fsize * nfrag) < 0)
{ {

View file

@ -60,7 +60,8 @@ 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);