aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/alsa.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index 87938568..6aa79a75 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -59,6 +59,8 @@ MAKE_FUNC(snd_pcm_hw_params_set_period_size_near);
MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_min);
MAKE_FUNC(snd_pcm_hw_params_get_buffer_time_min);
MAKE_FUNC(snd_pcm_hw_params_get_buffer_time_max);
+MAKE_FUNC(snd_pcm_hw_params_get_period_time_min);
+MAKE_FUNC(snd_pcm_hw_params_get_period_time_max);
MAKE_FUNC(snd_pcm_hw_params_get_buffer_size);
MAKE_FUNC(snd_pcm_hw_params_get_period_size);
MAKE_FUNC(snd_pcm_hw_params_get_access);
@@ -129,6 +131,8 @@ MAKE_FUNC(snd_card_next);
#define snd_pcm_hw_params_set_buffer_size_min psnd_pcm_hw_params_set_buffer_size_min
#define snd_pcm_hw_params_get_buffer_time_min psnd_pcm_hw_params_get_buffer_time_min
#define snd_pcm_hw_params_get_buffer_time_max psnd_pcm_hw_params_get_buffer_time_max
+#define snd_pcm_hw_params_get_period_time_min psnd_pcm_hw_params_get_period_time_min
+#define snd_pcm_hw_params_get_period_time_max psnd_pcm_hw_params_get_period_time_max
#define snd_pcm_hw_params_get_buffer_size psnd_pcm_hw_params_get_buffer_size
#define snd_pcm_hw_params_get_period_size psnd_pcm_hw_params_get_period_size
#define snd_pcm_hw_params_get_access psnd_pcm_hw_params_get_access
@@ -217,6 +221,8 @@ static ALCboolean alsa_load(void)
LOAD_FUNC(snd_pcm_hw_params_set_period_size_near);
LOAD_FUNC(snd_pcm_hw_params_get_buffer_time_min);
LOAD_FUNC(snd_pcm_hw_params_get_buffer_time_max);
+ LOAD_FUNC(snd_pcm_hw_params_get_period_time_min);
+ LOAD_FUNC(snd_pcm_hw_params_get_period_time_max);
LOAD_FUNC(snd_pcm_hw_params_get_buffer_size);
LOAD_FUNC(snd_pcm_hw_params_get_period_size);
LOAD_FUNC(snd_pcm_hw_params_get_access);
@@ -769,7 +775,17 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
CHECK(snd_pcm_hw_params_set_buffer_time_near(data->pcmHandle, hp, &bufferLen, NULL));
}
/* set period time (implicitly sets buffer size/bytes/time and period size/bytes) */
- CHECK(snd_pcm_hw_params_set_period_time_near(data->pcmHandle, hp, &periodLen, NULL));
+ if(snd_pcm_hw_params_set_period_time_near(data->pcmHandle, hp, &periodLen, NULL) < 0)
+ {
+ unsigned int mintime, maxtime;
+ CHECK(snd_pcm_hw_params_get_period_time_min(hp, &mintime, NULL));
+ CHECK(snd_pcm_hw_params_get_period_time_max(hp, &maxtime, NULL));
+
+ TRACE("Failed to set %uus period time, detected range: %u -> %u\n", periodLen, mintime, maxtime);
+ periodLen = clampu(periodLen, mintime, maxtime);
+
+ CHECK(snd_pcm_hw_params_set_period_time_near(data->pcmHandle, hp, &periodLen, NULL));
+ }
/* install and prepare hardware configuration */
CHECK(snd_pcm_hw_params(data->pcmHandle, hp));
/* retrieve configuration info */