[Alsa-user] buffer size and period size relationship?

I'm working on an application where I wanted to do double-buffering and
tried to set the buffer size to 4096 and the period size to 2048. However,
the actual period size used by ALSA is 1365. In fact, it seems that
whatever I choose for the buffer size, the period size used by ALSA is 1/3
of the buffer size. Is this a limitation of the audio HW that I'm using?
cat /proc/asound/cards says:
0 [Intel ]: HDA-Intel - HDA Intel
HDA Intel at 0xf8000000 irq 21
Thanks,
Ray

Thread view

I'm working on an application where I wanted to do double-buffering and
tried to set the buffer size to 4096 and the period size to 2048. However,
the actual period size used by ALSA is 1365. In fact, it seems that
whatever I choose for the buffer size, the period size used by ALSA is 1/3
of the buffer size. Is this a limitation of the audio HW that I'm using?
cat /proc/asound/cards says:
0 [Intel ]: HDA-Intel - HDA Intel
HDA Intel at 0xf8000000 irq 21
Thanks,
Ray

Raymond Toy wrote:
> I'm working on an application where I wanted to do double-buffering and
> tried to set the buffer size to 4096 and the period size to 2048. However,
> the actual period size used by ALSA is 1365. In fact, it seems that
> whatever I choose for the buffer size, the period size used by ALSA is 1/3
> of the buffer size. Is this a limitation of the audio HW that I'm using?
This is possible. There isn't any particular combination of buffer/
period parameters that is guaranteed to be supported with all hardware.
If you want to have two periods, call snd_pcm_hw_params_set_periods
before try to set the other parameters, but this might fail.
> cat /proc/asound/cards says:
>
> 0 [Intel ]: HDA-Intel - HDA Intel
> HDA Intel at 0xf8000000 irq 21
HDA is quite flexible, but it's possible that you're using plugins that
introduce additional restrictions. What device name are you using in
your program? What plugins are shown when you run
"aplay -D devicename -v something.wav"?
Regards,
Clemens

On Thu, Aug 25, 2011 at 12:15 AM, Clemens Ladisch
<cladisch@...>wrote:
> Raymond Toy wrote:
> > I'm working on an application where I wanted to do double-buffering and
> > tried to set the buffer size to 4096 and the period size to 2048.
> However,
> > the actual period size used by ALSA is 1365. In fact, it seems that
> > whatever I choose for the buffer size, the period size used by ALSA is
> 1/3
> > of the buffer size. Is this a limitation of the audio HW that I'm using?
>
> This is possible. There isn't any particular combination of buffer/
> period parameters that is guaranteed to be supported with all hardware.
>
> If you want to have two periods, call snd_pcm_hw_params_set_periods
> before try to set the other parameters, but this might fail.
>
I think I tried that and it failed, but I will try again to be sure.
> > cat /proc/asound/cards says:
> >
> > 0 [Intel ]: HDA-Intel - HDA Intel
> > HDA Intel at 0xf8000000 irq 21
>
> HDA is quite flexible, but it's possible that you're using plugins that
> introduce additional restrictions. What device name are you using in
> your program? What plugins are shown when you run
> "aplay -D devicename -v something.wav"?
>
>
It says:
Playing WAVE 'M1F1-int16WE-AFsp.wav' : Signed 16 bit Little Endian, Rate
8000 Hz, Stereo
ALSA <-> PulseAudio PCM I/O Plugin
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 8000
exact rate : 8000 (8000/1)
msbits : 16
buffer_size : 4000
period_size : 1000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 1000
period_event : 0
start_threshold : 4000
stop_threshold : 4000
silence_threshold: 0
silence_size : 0
boundary : 9007199254740992000
I have read about PulseAudio potentially being a problem, but getting rid of
it is not so easy. Besides, for the application I'm looking at, I won't
have control over that.
Thanks,
Ray