[mythtv] ALSA Sound Driver Question

Paul Volkaerts paul.volkaerts at lineone.net
Thu Jun 2 08:36:07 UTC 2005

> >The "fragment size" is fixed at 4096 bytes, which means I need
> to feed the
> >audio output with 4096 bytes before it will begin playing. At telephony
> >rates this equates to 250ms, which is far too long a delay to
> insert into a
> >phone call (I currently use around 40ms).
> >
> >
> I guess also that the open function in each bit of code should probably
> have a look at the rate and decide on a sensible buffer size
> based on that.
> It becomes a difficult heuristic though.  You find a bunch of cards
> which simply break if you want them to use buffer sizes smaller than X
> or larger than Y....
> I think the best thing is just to have the flag I mentioned try and set
> the absolute lowest latency the card will stand (within reason, my pro
> RME card can so silly low levels...).  If the card can do less then 40ms
> then basically go as low as 10ms...
> Either way it's going to need the individual driver hackers to fix
> this.  Suggest not worrying too much.  I will try and have a look as well

I ran into a couple of other issues which I am still chasing but thought it
was worth putting my "findings so far" out there.

1. Using the Alsa driver, a call to "getBufferOnSoundcard" returns zero
immediately after the first few calls to AddSamples. I think this is because
it only calls snd_pcm_delay if the state is running or draining, but the
state seems to stay as "PREPARED" for a while. I don't understand ALSA
enough to know what causes it to change from Prepared to Running, i.e. will
the first call to writei do this or does it need a minimum number of bytes?

2. Because of the asynchronous nature of the drivers, there can be a gap of
around 5ms to 10ms between my first call to AddSamples and the data being
sent to the soundcard. (i.e. it has to wake from a sleep and then the task
has to be scheduled by the kernel). Can you think of any way of getting rid
of this?  Is it not possible to feed the soundcard from AddSamples directly
if the soundcard is empty?


More information about the mythtv-dev mailing list