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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-22-2007, 09:41 AM
|
#1
|
|
Member
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204
Rep:
|
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;
}
|
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:23 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|