[alsa-devel] ALSA throwing buffers away?

Radivoje Jovanovic radivojejovanovic at gmail.com
Tue Nov 23 17:36:34 CET 2010

I am developing driver for a really simple hardware. Hardware has codec that
supports mono/stereo and the amplifier that supports only one speaker so the
driver has to be mono driver and the codec is setup to manage mono data. I
have setup ALSA with following parameters:


    .formats = SNDRV_PCM_FMTBIT_U16_LE |
           SNDRV_PCM_FMTBIT_U16_BE |
           SNDRV_PCM_FMTBIT_S16_LE |
           SNDRV_PCM_FMTBIT_S16_BE |
.channels_min = 1,
 .channels_max = 1,

Initially I was happy since sound started playing right away, but I noticed
that songs are skipping. I created buffers that collect statistics about
playback which is printed at the STOP trigger. The hardware is going through
ALSA circular buffer correctly, and ALSA is filling the buffer as the
hardware progresses, but after each buffer iteration ALSA skips the buffer
length of the data?! For example:
If buffer is .5 Mb ALSA will fill first .5Mb from the file into the buffer.
As the hardware is playing the sound ALSA fills the buffer starting 1.0 Mb
away from the begining of the file (the data from .5-1.0 Mb never makes it
to the buffer). This pattern repeats constantly to the end of the song. I
have tried SNDRV_PCM_INFO_INTERLEAVED with the same results (in this case
ALSA will not even try to play stereo files using my mono driver). The files
I tested are stereo and mono and they all behave the same. I am collecting
ALSA info in the snd_pcm_lib_write1 method in the pcm_lib.c file. I was
wondering if ALSA maybe deals with two circular buffers in the same time, or
if anybody has an idea what is going on here?


More information about the Alsa-devel mailing list