[alsa-devel] error in recovery from buffer under-run.

Ashlesha Shintre ashlesha.shintre at gmail.com
Wed May 2 17:26:01 CEST 2007


Thanks for the link you emailed earlier.  I tried writing my own code, based
on the how to in the alsa wiki.  I have attached that code with this email.

The problem it faces is a buffer underrun every alternate time, i try
writing to the device.

In my code, to take care of underruns, I do the following:

buffer is a short int array which is 16000 in length.
every alternate call to snd_pcm_writei is successful but only write in the
vicinity of 1350 frames, instead of size which is initialised to length of

Now, in the code below, the snd_pcm_recover function prints a message
indicating a buffer under-run has occured, however, it returns a 0,
indicating success in recovery from the error!

I am not sure how to deal with this -- is there a problem with my ALSA
Sorry about the length of this email and thanks again,


> {
> frames = snd_pcm_writei (pcm_handle, buffer, size);
> printf("frames returned is %d\n",frames);
> if (frames>0)
>     temp=frames;
> if (frames ==  -32){
>           frames = snd_pcm_recover(pcm_handle, frames, 0);
>           printf("recover returned %d\n",frames);
>           }
> if (frames < 0){
>           printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
>           return -1;
>           }
> printf("%d frames written\n",frames);
> if(temp>0)
>     size=size-temp;
> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: async_ash.c
Type: text/x-csrc
Size: 2764 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20070502/d73839e0/attachment-0001.c 

More information about the Alsa-devel mailing list