Skip to contentSkip to conversation

How is buffer size, periode size and periods determined?

DISCUSSION Hans-Christian Egtvedt 2 participants 2 messages May 12, 2006 – May 17, 2006

lore
Share & tools
lore
#0 lore raw

Hi

I'm experiencing that my aplay/arecord (1.0.11) is setting up a bit weird values for buffer size, period size and periods.

For example when trying to record S16_LE 44100 Hz Mono I get the following parameters:
buffer size: 44100
period size: 4094
periods : 10

10 * 4094 = 40940 != 44100, the player asks for a bigger buffer than needed.

Other example, S16_LE 32000 Hz Mono:
buffer size: 32752
period size: 4094
periods : 8

8 * 4094 = 32752 == 32752, which is a correct buffer size.

How come the alsa-lib/aplay behaves like this? I would like to see the last behaviour all the time. Does this point to a bug on my platform, or is this the way alsa-lib can calculate the buffers?

The reason I'm asking is that it wastes some memory and the DMA controller currently in the Linux for my platform doesn't like the buffersize to be greater than periode size * periods.

Signature · 13 lines
With kind regards,
Med vennlig hilsen,

Hans-Christian Egtvedt
Applications Engineer - AVR Applications Lab
Atmel Norway


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
#1 lore raw

RE: How is buffer size, periode size and periods de

Quoted 10 lines · On 12-May-2006 Hans-Christian Egtvedt wrote:

I'm experiencing that my aplay/arecord (1.0.11) is setting up a bit weird values for buffer size, period size and periods.

For example when trying to record S16_LE 44100 Hz Mono I get the following parameters:
buffer size: 44100
period size: 4094
periods : 10

10 * 4094 = 40940 != 44100, the player asks for a bigger buffer than needed.

Someone should add this issue the the FAQs.

ALSA is not required to make the buffer size multiple than the period size, unless the driver asks for it. If it doesn't, then the driver must be able to manage the case when the IRQs happen at different points of the ring buffer each round. Anyway, n*persize <= bufsize < (n+1)*persize

ALSA middle layer is robust enough to cope with unevenly sizes periods well (eg. buf=1000 per=400 -> 3 periods of 400, 400, 200). I wouldn't be surprised if some drivers still use periods of different sizes because ALSA doesn't complain (mine did it at the beginning).

--
Giuliano.

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642