--- alsa.c.orig 2013-11-14 18:38:23.320000001 -0200 +++ alsa.c 2013-11-14 18:39:59.916000000 -0200 @@ -226,6 +226,8 @@ static int open_alsa(ca_context *c, struct outstanding *out) { int ret; snd_pcm_hw_params_t *hwparams; + unsigned buffer_time; + unsigned period_time; unsigned rate; snd_pcm_hw_params_alloca(&hwparams); @@ -258,6 +260,19 @@ if ((ret = snd_pcm_hw_params_set_channels(out->pcm, hwparams, ca_sound_file_get_nchannels(out->file))) < 0) goto finish; + if ((ret = snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0)) < 0) + goto finish; + + if (buffer_time > 500000) + buffer_time = 500000; + + if ((ret = snd_pcm_hw_params_set_buffer_time_near(out->pcm, hwparams, &buffer_time, 0)) < 0) + goto finish; + + period_time = buffer_time / 4; + if ((ret = snd_pcm_hw_params_set_period_time_near(out->pcm, hwparams, &period_time, 0)) < 0) + goto finish; + if ((ret = snd_pcm_hw_params(out->pcm, hwparams)) < 0) goto finish;