LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-22-2007, 09:41 AM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
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:7073snd_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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between the free buffer and buffer in the buffer hash queue? Swagata Linux - Enterprise 0 05-25-2006 11:57 PM
drive buffer underrun = disk not trustworthy? ctos Slackware 3 03-24-2006 09:08 PM
cdrdao buffer underrun HELP! Flowster Linux - Software 2 12-14-2005 04:31 PM
Alsa capturing buffer underruns don_pingu Programming 3 09-16-2004 10:00 AM
buffer underrun with cdrecord GT_Onizuka Linux - Newbie 4 09-06-2003 05:04 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration