All of lore.kernel.org
 help / color / mirror / Atom feed
* playing underruns
@ 2003-02-12 22:56 Chris Raphael
  2003-02-12 23:34 ` Paul Davis
  2003-02-13  9:55 ` Takashi Iwai
  0 siblings, 2 replies; 9+ messages in thread
From: Chris Raphael @ 2003-02-12 22:56 UTC (permalink / raw)
  To: alsa-devel


Hello List,  

  This is my first post and I am new (a couple of weeks) to ALSA.

I am working on an application that plays audio output in response
to audio input --- the relationship between input and output is 
complicated and I will not describe it in any detail here --- I
am building a musical accompaniment system.  I want the output to "respond"
to the input with low latency so I cannot write the output samples
very long before they are actually going to be played.  Currently
I have a function that is called repeatedly (through a signal) and
writes the samples about .05 secs before they will actually be played.  
I monitor the delay, in samples, (I can't remember the name of the
function (snd_delay_???) and see that the number of unplayed samples
fluctuates but there does not seem to be an increasing or decreasing
trend.  So I assume that I am writing at very close to the right
rate and mostly the playback sounds fine.  But every so often,
maybe once every 10 secs or so, I get a playback underrun.  I
always check the system clock when my writing routine begins,
so I know the underruns are almost always *not* due to my writing 
routine getting a late callback.  By everything I can measure, the 
samples are written on time.  Can anyone tell me what I need to do 
to fix this problem? Perhaps it is not reasonable of me to hope to 
write samples such a short time before they need to be played?

I would really appreciate any help I can get on this and will supply
any relevant details.  I just didn't want to clutter up my question
with lots of irrelevant info.

Thanks,

Christopher Raphael


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: playing underruns
  2003-02-12 22:56 playing underruns Chris Raphael
@ 2003-02-12 23:34 ` Paul Davis
  2003-02-13  9:55 ` Takashi Iwai
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Davis @ 2003-02-12 23:34 UTC (permalink / raw)
  To: Chris Raphael; +Cc: alsa-devel

oh boy. there is so much that you might not know. lets start with the
most obvious:
     
     which kernel are you using (version + distribution)
     SCSI or IDE disk controller
     have you ever heard of the low latency patch?

--p


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: playing underruns
  2003-02-12 22:56 playing underruns Chris Raphael
  2003-02-12 23:34 ` Paul Davis
@ 2003-02-13  9:55 ` Takashi Iwai
  1 sibling, 0 replies; 9+ messages in thread
From: Takashi Iwai @ 2003-02-13  9:55 UTC (permalink / raw)
  To: Chris Raphael; +Cc: alsa-devel

Hi,

check LAD site,
	http://www.linuxdj.com/audio/lad/resourceslatency.php3

you'll find some good information how to get low-latency.


Takashi

At Wed, 12 Feb 2003 17:56:19 -0500,
Chris Raphael wrote:
> 
> 
> Hello List,  
> 
>   This is my first post and I am new (a couple of weeks) to ALSA.
> 
> I am working on an application that plays audio output in response
> to audio input --- the relationship between input and output is 
> complicated and I will not describe it in any detail here --- I
> am building a musical accompaniment system.  I want the output to "respond"
> to the input with low latency so I cannot write the output samples
> very long before they are actually going to be played.  Currently
> I have a function that is called repeatedly (through a signal) and
> writes the samples about .05 secs before they will actually be played.  
> I monitor the delay, in samples, (I can't remember the name of the
> function (snd_delay_???) and see that the number of unplayed samples
> fluctuates but there does not seem to be an increasing or decreasing
> trend.  So I assume that I am writing at very close to the right
> rate and mostly the playback sounds fine.  But every so often,
> maybe once every 10 secs or so, I get a playback underrun.  I
> always check the system clock when my writing routine begins,
> so I know the underruns are almost always *not* due to my writing 
> routine getting a late callback.  By everything I can measure, the 
> samples are written on time.  Can anyone tell me what I need to do 
> to fix this problem? Perhaps it is not reasonable of me to hope to 
> write samples such a short time before they need to be played?
> 
> I would really appreciate any help I can get on this and will supply
> any relevant details.  I just didn't want to clutter up my question
> with lots of irrelevant info.
> 
> Thanks,
> 
> Christopher Raphael
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
> 


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: playing underruns
       [not found] <200302122330.h1CNUMn05990@thales.math.umass.edu>
@ 2003-02-13 14:10 ` Chris Raphael
  2003-02-13 14:35   ` Paul Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Raphael @ 2003-02-13 14:10 UTC (permalink / raw)
  To: paul; +Cc: alsa-devel


Thanks for responding Paul.

I'm using Red Hat 7.2 which is the 2.4 kernel and the 0.9.0rc7 ALSA driver.

I'm not sure why you want to know about the disk controller since there
is no disk access in the real-time part of my application.  But I am using
a Dell Inspiron 8200 and I looked on the web at the spec sheet which describes
the disk as "Ultra ATA."  They didn't have any info about controllers unless
ATA is some kind of controller.  

I think I have heard about the "low latency"
patch.  My understanding about that is that it is for more precise delivery
of signals.  That is, more precise than the .01 secs promised and usually
delivered by Linux.   With the current signal delivery my sound samples still
get written well before they should be played.  I am writing samples .05 secs
before they time they should actually move the speaker while my signals are
only rarely any later than .02 secs after the time requested.  
Of course, I have no idea what must happen
between the time I write the samples and when they actually are turned into sound.

Chris


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: playing underruns
  2003-02-13 14:10 ` Chris Raphael
@ 2003-02-13 14:35   ` Paul Davis
  0 siblings, 0 replies; 9+ messages in thread
From: Paul Davis @ 2003-02-13 14:35 UTC (permalink / raw)
  To: Chris Raphael; +Cc: alsa-devel

trying to summarize 3-4 years of experience with this is hard. but
lets start by pointing out that its possible that your disk controller
causes the kernel to delay scheduling for up to 100msecs. i'm not sure
if RH7 fixed this by setting the driver parameters correctly - i have
heard that newer versions of RH do this. IDE/ATA drives have been
notorious under linux for ruining any soft-real-time performance. and
yes, your program may do no disk i/o, but that doesn't mean none is
going on.

you need to run hdparm to get the driver parameters, and also check if
you have a file /proc/sys/kernel/lowlatency.

--p

ps. and BTW, in my regularly scheduled plug, please, please take a
    look at jackit.sf.net for a much easier and more useful
    way to write audio apps for linux. and now, back to our
    program!
	


-------------------------------------------------------
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] 9+ messages in thread

* Re: playing underruns
       [not found] <200302131435.h1DEZWn21451@thales.math.umass.edu>
@ 2003-02-13 19:07 ` Chris Raphael
  2003-02-13 19:10   ` Paul Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Raphael @ 2003-02-13 19:07 UTC (permalink / raw)
  To: paul; +Cc: alsa-devel


Paul,  Again thanks very much.  From: 

/sbin/hdparm /dev/hda2

I get:

/dev/hda2:
 multcount	= 16 (on)
 I/O support	= 0 (default 16-bit)
 unmaskirq	= 0 (off)
 using_dma	= 1 (on)
 keepsettings	= 0 (off)
 nowerr		= 0 (off)
 readonly	= 0 (off)
 readahead	= 8 (on)
 geometry	= 4864/255/73, sectors = 36869175, start = 4225095

with similar results for the other hda's.  I don't know if this
is the question you were asking, though, since this doesn't seem
to have much info.  

I don't have the low latency patch.  

I will take a look at jackit.sf.net.  However, I am close to having 
the sound I/0 working the way I need it to, so I am a little reluctant
to start all over.  :)

Chris


-------------------------------------------------------
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] 9+ messages in thread

* Re: playing underruns
  2003-02-13 19:07 ` Chris Raphael
@ 2003-02-13 19:10   ` Paul Davis
  2003-02-13 19:26     ` Mark Knecht
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Davis @ 2003-02-13 19:10 UTC (permalink / raw)
  To: Chris Raphael; +Cc: alsa-devel

>/sbin/hdparm /dev/hda2
>
>I get:
>
>/dev/hda2:
> multcount	= 16 (on)
> I/O support	= 0 (default 16-bit)
> unmaskirq	= 0 (off)
> using_dma	= 1 (on)
> keepsettings	= 0 (off)
> nowerr		= 0 (off)
> readonly	= 0 (off)
> readahead	= 8 (on)
> geometry	= 4864/255/73, sectors = 36869175, start = 4225095
>
>with similar results for the other hda's.  I don't know if this
>is the question you were asking, though, since this doesn't seem
>to have much info.  

yep, this doesn't look too good, though its not a complete
disaster. please read this:

http://linux.oreillynet.com/pub/a/linux/2000/06/29/hdparm.html

keep in mind that some distributions (RH included, i think) have fixed
this issue somewhat, though they may not have gone far enough for low
latency audio.

>I don't have the low latency patch.  

you will probably need it. the standard kernel in RH7 is not up to the
task. 

--p


-------------------------------------------------------
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] 9+ messages in thread

* RE: playing underruns
  2003-02-13 19:10   ` Paul Davis
@ 2003-02-13 19:26     ` Mark Knecht
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Knecht @ 2003-02-13 19:26 UTC (permalink / raw)
  To: Chris Raphael; +Cc: alsa-devel

Also check out the Planet for more info on this. Fernando has some
suggestions for Redhat there.

Cheers,
Mark

-----Original Message-----
From: alsa-devel-admin@lists.sourceforge.net
[mailto:alsa-devel-admin@lists.sourceforge.net]On Behalf Of Paul Davis
Sent: Thursday, February 13, 2003 11:11 AM
To: Chris Raphael
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: [Alsa-devel] playing underruns


>/sbin/hdparm /dev/hda2
>
>I get:
>
>/dev/hda2:
> multcount	= 16 (on)
> I/O support	= 0 (default 16-bit)
> unmaskirq	= 0 (off)
> using_dma	= 1 (on)
> keepsettings	= 0 (off)
> nowerr		= 0 (off)
> readonly	= 0 (off)
> readahead	= 8 (on)
> geometry	= 4864/255/73, sectors = 36869175, start = 4225095
>
>with similar results for the other hda's.  I don't know if this
>is the question you were asking, though, since this doesn't seem
>to have much info.

yep, this doesn't look too good, though its not a complete
disaster. please read this:

http://linux.oreillynet.com/pub/a/linux/2000/06/29/hdparm.html

keep in mind that some distributions (RH included, i think) have fixed
this issue somewhat, though they may not have gone far enough for low
latency audio.

>I don't have the low latency patch.

you will probably need it. the standard kernel in RH7 is not up to the
task.

--p


-------------------------------------------------------
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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-devel





-------------------------------------------------------
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] 9+ messages in thread

* Re: playing underruns
       [not found] <200302131911.h1DJBBn08117@thales.math.umass.edu>
@ 2003-02-13 20:13 ` Chris Raphael
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Raphael @ 2003-02-13 20:13 UTC (permalink / raw)
  To: paul; +Cc: alsa-devel


Paul,  Okay I looked at the page you pointed me to with info about
hdparm.  before I changed any of the controller settings I 
got 21.12 MB/sec for "Timing buffered disk reads" which seems to be 
pretty good according to the
author of the web page.  After changing the settings (I/O support
32 bit, unmaskirq = on, transfer mode to UltraDMA) no change.
I think my program is not adversely affected by any disk access
since I always check to see  when my program's callbacks are
actually delivered.  They seem to be accurate enough and almost
never more that .02 secs later than requested.  My sense is that
I am writing my samples on time (as far as I can measure) and the
problem happens somewhere in the chain of events *after*
my program writes audio samples.  Do you think the lowlatency patch
might help there?  Or any other ideas?

Chris



-------------------------------------------------------
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] 9+ messages in thread

end of thread, other threads:[~2003-02-13 20:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-12 22:56 playing underruns Chris Raphael
2003-02-12 23:34 ` Paul Davis
2003-02-13  9:55 ` Takashi Iwai
     [not found] <200302122330.h1CNUMn05990@thales.math.umass.edu>
2003-02-13 14:10 ` Chris Raphael
2003-02-13 14:35   ` Paul Davis
     [not found] <200302131435.h1DEZWn21451@thales.math.umass.edu>
2003-02-13 19:07 ` Chris Raphael
2003-02-13 19:10   ` Paul Davis
2003-02-13 19:26     ` Mark Knecht
     [not found] <200302131911.h1DJBBn08117@thales.math.umass.edu>
2003-02-13 20:13 ` Chris Raphael

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.