* Broken pipe mystery
@ 2003-02-08 10:21 Pete Barnard
2003-02-08 11:13 ` tomasz motylewski
2003-02-09 7:36 ` Josh Green
0 siblings, 2 replies; 7+ messages in thread
From: Pete Barnard @ 2003-02-08 10:21 UTC (permalink / raw)
To: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 1037 bytes --]
I am using ALSA 0.9.0rc7 and Red Hat Linux 7.2. My sound card is a CS461x.
My computer is a reasonably powerful beast with 512M of RAM and 1Gig clock
speed.
I have written a simple capture program which reads interleaved samples from
the sound card and goes around in a continuous while(1) loop. My program
works perfectly - until it crashes after several hours with the message:
"read from audio interface failed: broken pipe".
I have narrowed it down to the following piece of code. The size of buf is 256 (shorts). Why would the snd_pcm_readi suddenly (randomly?) fail with a broken pipe??? Any ideas or suggestions would be greatly appreciated as I'm struggling with this
annoying (and difficult to debug) problem.
Regards,
Pete
while (1)
{
if ((err = snd_pcm_readi(capture_handle,buf,128)) != 128
{
// this is where it fails after several hours of working
successfully
cout << "read from audio interface failed: " << snd_strerror(err) <<
endl;
exit(1);
}
}
[-- Attachment #2: Type: text/html, Size: 1671 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Broken pipe mystery
2003-02-08 10:21 Broken pipe mystery Pete Barnard
@ 2003-02-08 11:13 ` tomasz motylewski
2003-02-08 13:56 ` Pete Barnard
2003-02-13 20:56 ` Pete Barnard
2003-02-09 7:36 ` Josh Green
1 sibling, 2 replies; 7+ messages in thread
From: tomasz motylewski @ 2003-02-08 11:13 UTC (permalink / raw)
To: Pete Barnard; +Cc: alsa-devel
On Sat, 8 Feb 2003, Pete Barnard wrote:
> I have written a simple capture program which reads interleaved samples from
> the sound card and goes around in a continuous while(1) loop. My program
> works perfectly - until it crashes after several hours with the message:
Does it always crash after the same time?
What sampling frequency do you use (kHz) ?
Best regards,
--
Tomek
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Broken pipe mystery
2003-02-08 11:13 ` tomasz motylewski
@ 2003-02-08 13:56 ` Pete Barnard
2003-02-10 7:47 ` tomasz motylewski
2003-02-13 20:56 ` Pete Barnard
1 sibling, 1 reply; 7+ messages in thread
From: Pete Barnard @ 2003-02-08 13:56 UTC (permalink / raw)
To: tomasz motylewski; +Cc: alsa-devel
> Does it always crash after the same time?
This is something I was actually thinking about. I'm not sure at this stage
but it is certainly a something worth exploring. I have never been there
when the program crashes because everytime I run the program all night it
has always crashed when I get back in the morning - and I'd always forgotten
to put a system("date") line in the code before I went home. I won't be
able to try it it until Monday but I'll definitely put a system("date")
command in the code and get back to you when I can answer your question.
> What sampling frequency do you use (kHz) ?
16kHz is the sampling frequency.
Thank you replying.
Regards,
Pete
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> http://www.vasoftware.com
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Broken pipe mystery
2003-02-08 13:56 ` Pete Barnard
@ 2003-02-10 7:47 ` tomasz motylewski
0 siblings, 0 replies; 7+ messages in thread
From: tomasz motylewski @ 2003-02-10 7:47 UTC (permalink / raw)
To: Pete Barnard; +Cc: alsa-devel
> > What sampling frequency do you use (kHz) ?
>
> 16kHz is the sampling frequency.
Please note what period and boundary size are you using. 16000*60*60*24 =
1382400000, this should be still OK, unless you are counting bytes, not frames.
I suspect some problems when 32 bit counter wraps around (changes from positive
to negative), but this should probably take longer in your case.
Anyway if it always takes the same time you should be able to calculate what
your magic number is. If not, then something else.
Best regards,
--
Tomek
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Broken pipe mystery
2003-02-08 11:13 ` tomasz motylewski
2003-02-08 13:56 ` Pete Barnard
@ 2003-02-13 20:56 ` Pete Barnard
2003-02-13 23:36 ` Josh Green
1 sibling, 1 reply; 7+ messages in thread
From: Pete Barnard @ 2003-02-13 20:56 UTC (permalink / raw)
To: tomasz motylewski; +Cc: alsa-devel
:
>
> Does it always crash after the same time?
No. It didin't crash after the same time. The problem is fixed now thanks
to Josh Green's tip. (I wrote a function that caught the EPIPE error and
then did a snd_pcm_prepare). I left it for 2 nights with a system("date") in
the catch function and got an EPIPE once on one night and not at all on the
second night - so even though it is fixed I'm still slightly curious as to
why I got this problem/feature at all.
Regards,
Pete
>
> What sampling frequency do you use (kHz) ?
>
> Best regards,
> --
> Tomek
>
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Broken pipe mystery
2003-02-13 20:56 ` Pete Barnard
@ 2003-02-13 23:36 ` Josh Green
0 siblings, 0 replies; 7+ messages in thread
From: Josh Green @ 2003-02-13 23:36 UTC (permalink / raw)
To: Pete Barnard; +Cc: alsa-devel
On Thu, 2003-02-13 at 12:56, Pete Barnard wrote:
> :
> >
> > Does it always crash after the same time?
>
> No. It didin't crash after the same time. The problem is fixed now thanks
> to Josh Green's tip. (I wrote a function that caught the EPIPE error and
> then did a snd_pcm_prepare). I left it for 2 nights with a system("date") in
> the catch function and got an EPIPE once on one night and not at all on the
> second night - so even though it is fixed I'm still slightly curious as to
> why I got this problem/feature at all.
>
> Regards,
>
> Pete
>
Its due to your program not being able to meet the deadline for writing
an audio buffer for playback. This is often Linux kernel related and
there is lots of information about tuning your kernel (do a search for
"linux kernel low latency"). It can be somewhat of a black art, because
different hardware and Linux drivers can have adverse effects on
latency. For instance if your hard disk is IDE and isn't tuned right
(DMA not enabled for instance) you can get real long latency spikes when
reading/writing the hard disk. You'll also want to look into the lowlat
patch and perhaps the preempt patch as well. Kernels that come with
Linux distributions have a tendency to not be very low latency friendly,
so if you wan't low latency, build your own kernel with one of those
patches.
On your program side:
You can increase the audio buffer size and/or count to minimize
underruns (at the cost of higher latency audio playback).
If you require low latency, run your program with SCHED_FIFO scheduling
(see man sched_setscheduler, requires root privileges). Note that your
program then has the ability to lock up the machine, should it decide to
consume all the CPU time.
I think this is one of the main things that still needs to be solved
with Linux and audio. Low latency audio shouldn't entail buggy processes
being able to bring the system to its knees. Cheers.
Josh Green
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Broken pipe mystery
2003-02-08 10:21 Broken pipe mystery Pete Barnard
2003-02-08 11:13 ` tomasz motylewski
@ 2003-02-09 7:36 ` Josh Green
1 sibling, 0 replies; 7+ messages in thread
From: Josh Green @ 2003-02-09 7:36 UTC (permalink / raw)
To: Pete Barnard; +Cc: alsa-devel
On Sat, 2003-02-08 at 02:21, Pete Barnard wrote:
> I am using ALSA 0.9.0rc7 and Red Hat Linux 7.2. My sound card is a CS461x.
> My computer is a reasonably powerful beast with 512M of RAM and 1Gig clock
> speed.
> I have written a simple capture program which reads interleaved samples from
> the sound card and goes around in a continuous while(1) loop. My program
> works perfectly - until it crashes after several hours with the message:
>
> "read from audio interface failed: broken pipe".
>
> I have narrowed it down to the following piece of code. The size of buf is 256 (shorts). Why would the snd_pcm_readi suddenly (randomly?) fail with a broken pipe??? Any ideas or suggestions would be greatly appreciated as I'm struggling with this
> annoying (and difficult to debug) problem.
>
> Regards,
>
> Pete
>
> while (1)
> {
> if ((err = snd_pcm_readi(capture_handle,buf,128)) != 128
> {
> // this is where it fails after several hours of working
> successfully
> cout << "read from audio interface failed: " << snd_strerror(err) <<
> endl;
> exit(1);
> }
> }
>
If I remember correctly the EPIPE error code is returned when an xrun
occurs. In the case of a read it would be a buffer overrun. Your code
should check for this return value and I believe you have to start the
stream again with "snd_pcm_prepare". Check out the ALSA site for HOWTOs
and the like. Cheers.
Josh Green
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-02-13 23:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-08 10:21 Broken pipe mystery Pete Barnard
2003-02-08 11:13 ` tomasz motylewski
2003-02-08 13:56 ` Pete Barnard
2003-02-10 7:47 ` tomasz motylewski
2003-02-13 20:56 ` Pete Barnard
2003-02-13 23:36 ` Josh Green
2003-02-09 7:36 ` Josh Green
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.