All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Proposal for more reliable audio DMA.
@ 2009-06-24 16:28 Mark Brown
  2009-06-24 19:07 ` Jon Smirl
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2009-06-24 16:28 UTC (permalink / raw)
  To: Jon Smirl; +Cc: Takashi Iwai, alsa-devel mailing list, James Courtier-Dutton

On 24 Jun 2009, at 17:07, Jon Smirl <jonsmirl@gmail.com> wrote:

> Trying to directly expose the ring buffer to the app seems like a good
>
> way to avoid a copy, but it isn't achieving that. pulse is not
> decoding audio straight into the ring buffer, it decodes first and
> then copies into the buffer. Pulse is using the timers to estimate the
> destination for the copy.  Move this copy down into the drivers, the
> drivers know the correct destination for the copy.

Pulse isn't just doing straight playback, a large part of what it's  
there for is to do software mixing. When you have multiple sources  
active pulse is going to be forced to do the copy as part of the  
mixing process so putting that bit of the buffer management in kernel  
won't help in the way you think it does. Part of what's going on here  
is that the kernel code is trying to give userspace access to the data  
for as long as possible.

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Proposal for more reliable audio DMA.
@ 2009-06-21  2:06 Jon Smirl
  2009-06-22 16:27 ` James Courtier-Dutton
  0 siblings, 1 reply; 18+ messages in thread
From: Jon Smirl @ 2009-06-21  2:06 UTC (permalink / raw)
  To: alsa-devel mailing list

This algorithm is fairly similar to what currently exists in ALSA with
a few modifications. I'm trying to come up with guaranteed way to play
glitch free audio. Does this algorithm work or could it be modified to
work?

The main change is to track a high resolution timer as the means of
estimating where in the buffer to insert new, low latency data. This
tracking is done in a timer tick interrupt. Jiffies are too coarse and
not all hardware allows you to ask the current DMA position.

The other change is to keep all of the buffers filled with silence if
there isn't any pending data. (not doing this caused problem in my
mpc5200 AC97 driver)

Three buffers are used as a way to deterministically bound the DMA
pointer without needing interrupts.

---

Use three chained buffers.
Buffer size is samples/tick (or maybe 1.5 samples/tick)
Initialize buffers to silence.
Set end of buffer three to automatically terminate DMA

Set FIFO to minimum bus allows
Fill buffer one with samples available, start playing.

On timer tick call into driver..
If buffer one has finished playing move it to third position.
New last buffer is set to automatically stop DMA.
Return swap status to ALSA
If swapped, fill buffer three with silence or pending data
It is important to fill this buffer with silence if there is no pending data

The size of the buffers needs to be large enough to cover worst case
timer tick latency. Buffer two has to be large enough to ensure that
the tick routine will notice buffer one has been played before buffer
three starts.

If two buffers have been completed when the tick runs, let the third
buffer finish without swapping. Since you don't know where you are in
the third buffer, it is unsafe to swap at this point.

Playing the last buffer causes the end of buffer interrupt to happen.
Callback into ALSA to alert it of the underrun and need to restart DMA.
If this callback happens, make the buffers larger.

Long term observation of buffer completion status in tick handler will allow
accurate computation of samples/HPET unit. Record high accuracy timer
(HPET) on tick.

New low latency data that arrives can be inserted into the buffers dynamically.
Use the high resolution timer source to estimate where to place it.
Minimum FIFO ensures low latency play.

Design a minimum power mode.
Allows a huge FIFO to be loaded (like 128KB).
Call into driver to reset to minimum latency, small FIFO mode.

Advantages:

1) If ALSA goes away, hardware will stop on it's own with no noise.
2) No need to know the current position of DMA hardware.
3) Both low and high latency modes.
4) Audio interrupts only generated as error condition
5) Behavior is deterministic. Nothing is left to guess work.


-- 
Jon Smirl
jonsmirl@gmail.com

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

end of thread, other threads:[~2009-06-25 23:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-24 16:28 Proposal for more reliable audio DMA Mark Brown
2009-06-24 19:07 ` Jon Smirl
2009-06-24 21:11   ` Takashi Iwai
2009-06-25  4:26     ` Jon Smirl
2009-06-25  5:36       ` Robert Hancock
2009-06-25 14:20         ` Jon Smirl
2009-06-25 23:26           ` Robert Hancock
2009-06-25 10:25   ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2009-06-21  2:06 Jon Smirl
2009-06-22 16:27 ` James Courtier-Dutton
2009-06-22 16:43   ` Jon Smirl
2009-06-23  9:54     ` Mark Brown
2009-06-24 14:10       ` Jon Smirl
2009-06-24 14:39         ` Takashi Iwai
2009-06-24 15:14           ` Jon Smirl
2009-06-24 15:24             ` Takashi Iwai
2009-06-24 16:07               ` Jon Smirl
2009-06-25 15:26             ` James Courtier-Dutton

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.