From: Jonathan Andrews <jon@jonshouse.co.uk>
To: alsa-devel@alsa-project.org
Subject: Trying to understand alsa
Date: Thu, 12 Jan 2012 23:36:53 +0000 [thread overview]
Message-ID: <1326411413.23310.46.camel@jonspc> (raw)
> If a packet arrives very late (and one will, eventually), you will
> underrun. That's unavoidable. You can check for SND_PCM_STATE_XRUN
> from snd_pcm_state(). It's undocumented, but you need to call
> snd_pcm_avail_update() first to get an accurate reading from
> snd_pcm_state(). When an underrun occurs, recover with
> snd_pcm_recover() and then start writing data again.
>
Ok, this my first attempt at recovery, still haven't solved buffering
problem so it underruns for each and every write.
Does this look roughly correct ?
Thanks,
Jon
#ifdef ALSA
// snd_pcm_writen - writes non interleaved (mono) samples
// bufs an explicit void* pointer type set to point at real sample buffer "audio"
// broken pipe indicates buffer underrun
numrecs=sizeof(audio)/2; // 1k buffer, 512 samples
//printf("%d \n", snd_pcm_wait(playback_handle[activeslot],1));
err = snd_pcm_writen (playback_handle[activeslot], &bufs, numrecs);
if (err<numrecs)
{
fflush(stdout);
if (err>0)
{
fprintf (stderr, "snd_pcm_writen: wrote only %d\n",err);
fflush(stderr);
}
else
{
if (err == EPIPE)
{
errb=snd_pcm_recover(playback_handle[activeslot],err,0); // error passed is resullt of writen
if (errb<0)
{
fprintf(stderr,"Failed to recover from underrun\n");
fflush(stderr);
exit(1);
}
}
else
{
fprintf (stderr, "snd_pcm_writen: write to audio interface failed (%s) (%d)\n", snd_strerror (err),err);
fflush(stdout);
fflush(stderr);
exit (1);
}
}
}
#endif
next reply other threads:[~2012-01-12 23:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-12 23:36 Jonathan Andrews [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-01-12 23:45 Trying to understand alsa Jonathan Andrews
2012-01-13 1:25 ` Jonathan Andrews
2012-01-12 23:36 Jonathan Andrews
2012-01-12 21:44 Jonathan Andrews
2012-01-12 21:50 ` Fons Adriaensen
2012-01-12 22:12 ` Andrew Eikum
[not found] ` <1326410207.23310.17.camel@jonspc>
2012-01-13 15:10 ` Andrew Eikum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326411413.23310.46.camel@jonspc \
--to=jon@jonshouse.co.uk \
--cc=alsa-devel@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.