LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   ALSA: buffer underrun error (http://www.linuxquestions.org/questions/linux-software-2/alsa-buffer-underrun-error-548045/)

ashlesha 04-22-2007 09:41 AM

ALSA: buffer underrun error
 
Hi,

I m using an online code snippet to play pcm files using ALSA. I have verified that the code works.

Next, I m processing a wavfile and then feeding the pcm samples to the aforementioned code and I get the following error:

Quote:

Short write (expected 507904, wrote 1311)
ALSA lib pcm.c:7073:(snd_pcm_recover) underrun occured
I am also pasting the code below.

Thanks,
Ashlesha.

Quote:

#include "wavenet.h"

void wavplay(short int in[], int lastind) //lastind - length of samples
{
static char *device = "default"; /* playback device */
snd_output_t *output = NULL;
int count;
int buffin[lastind];
int err,bytesread=1;
unsigned int i;
char d;
snd_pcm_t *handle;
snd_pcm_sframes_t frames;

count=0;
while(count<lastind) // copy the input buffer into a local buffer to be played
buffin[count]=in[count++];


// printf("no. of samples @16000Hz are %d\n",count);

if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = snd_pcm_set_params(handle,
SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
1,
16000,
1,
10000)) < 0) { /* 2 sec */
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}

for (i = 0; i < 16; i++) {
//frames = snd_pcm_writei(handle, buffin, sizeof(buffin));
frames = snd_pcm_writei(handle, buffin, 128000);
if (frames < 0)
frames = snd_pcm_recover(handle, frames, 0);
if (frames < 0) {
printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
break;
}
if (frames > 0 && frames < (long)sizeof(buffin))
printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffin), frames);
}

snd_pcm_close(handle);

//return 0;
}


All times are GMT -5. The time now is 09:18 PM.