[alsa-devel] Avoiding buffer underruns in the hardware interrupt handler

Laurent Pinchart laurent.pinchart at skynet.be
Wed May 13 23:24:25 CEST 2009

Hi everybody.

Disclaimer: I'm new with ALSA development and I'm trying to digest the large 
amount of information I'm overflowed with, so please bear with possibly stupid 
help requests.

I'm writing an ALSA driver for a playback device. Unlike most sound cards, 
this device uses private memory for its audio buffer. I thus need to manually 
copy data from the ALSA buffer to the device buffer in the driver.

The device audio buffer is quite small, and for this reason I'd rather not use 
the copy/silence callbacks, but copy data from the ALSA buffer to the device 
in interrupt.

The device might generate interrupts a bit faster than what would be expected 
from sampling rate, so I need to check in the interrupt handler how much data 
the ALSA buffer holds. To do so I need to maintain a "hardware pointer" in the 
driver and to access the "user pointer" on the other side of the buffer.

I haven't found a clear API to access that second pointer. What is the 
best/preferred way to find out how much data the ALSA buffer holds ? I suppose 
I will need to perform some locking when accessing the "user pointer", I will 
also appreciate advices regarding which mutex/spinlock I should use for that 

Best regards,

Laurent Pinchart

More information about the Alsa-devel mailing list