[alsa-devel] About the buffer_time and period_time

Fengwei Yin yfw.bsp at gmail.com
Tue Oct 16 10:27:58 CEST 2007

Hi all,
I met a problem about period_time/buffer_time on PXA with ASOC enabled.
The kernel version is 2.6.21.

The Audio stream is 32k which is not supported by PXA ASOC driver. Please
refer following
RATES definition for PXA2xx.

#define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |
SNDRV_PCM_RATE_44100 | \

So I set plughw as default ALSA device enable auto samplerate conversion.

The code to set the period_time/buffer_time is as following:

    err = snd_pcm_hw_params_set_rate_near(hPCM, params, &rate, 0);
    if (err < 0) {
        error("Rate not available: %d\n", rate);
        return err;

    err = snd_pcm_hw_params_get_buffer_time_max(params,
                &buffer_time, 0);
    if (buffer_time > 500000)
                buffer_time = 500000;

    buffer_time = 400000;
    period_time = buffer_time/4;

    err = snd_pcm_hw_params_set_buffer_time_near(hPCM, params, &buffer_time,
    if (err < 0) {
            error("Buffer time not available: %d, error number: %d\n",
        return err;

    err = snd_pcm_hw_params_set_period_time_near(hPCM, params, &period_time,
    if (err < 0) {
        error("Period time not available: %d\n", period_time);
        return err;

If I set buffer_time to 400000, I will get:
Buffer time not available: 400000, error number: -22

Cannot init audio driver.
Floating point exception
If I set buffer time to 500000, buffer_time can be set correctly. But audio
playback failed.

If I set period_time before setting buffer_time, Everything is OK.

Any thought about this problem. Thanks.

Yin, Fengwei

More information about the Alsa-devel mailing list