All of lore.kernel.org
 help / color / mirror / Atom feed
From: Timur Tabi <timur@freescale.com>
To: alsa-devel@alsa-project.org
Subject: Trouble understanding ALSA's DMA buffers
Date: Mon, 11 Jun 2007 14:57:53 -0500	[thread overview]
Message-ID: <466DA941.40309@freescale.com> (raw)

I'm writing an ALSA SOC driver for an I2S-based device, and I'm having a really hard time 
understanding how ALSA uses the DMA buffers.  And yes, I've read the documentation and 
studied some sample source code.

I used to write audio drivers for a living, but that was many years ago, and it wasn't for 
Linux.  Perhaps the concepts in my head are outdated, but I just don't see enough 
explanation as to how DMA buffers are supposed to work.

Back then, audio drivers used "ping pong" DMA buffers.  A single DMA buffer is allocated, 
and the audio hardware is programmed to read from that buffer in a loop.  That is, it 
would automatically restart reading from the beginning of the buffer without any 
reprogramming.  The hardware would also be programmed to issue an interrupt when it got to 
the end of the buffer, and when it got to the half-way point.

To start playback, you first filled the whole buffer with audio data, and then told the 
hardware to start playing.  After the hardware got to the half-way point, it would issue 
an interrupt.  You would then tell the OS you need more data, and you'd get it.  You then 
copy that data into the first half of the buffer *while* the hardware was playing the 
second half.  Later, the hardware would interrupt you when it got to the end of the 
buffer.  You'd then copy more data to the 2nd half while the hardware is playing the first
half.

And so - hardware plays one half while you copy data to the other half.  Hence, "ping pong".

So how do I implement this in ALSA?  The "Writing an ALSA Driver" document doesn't even 
contain the words "ping" or "pong".

-- 
Timur Tabi
Linux Kernel Developer @ Freescale

             reply	other threads:[~2007-06-11 19:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 19:57 Timur Tabi [this message]
2007-06-11 20:29 ` Trouble understanding ALSA's DMA buffers Nobin Mathew
2007-06-12 10:36   ` Takashi Iwai
2007-06-12 15:21     ` Pharaoh .
2007-06-12 15:44       ` Pharaoh .
2007-06-12 16:36     ` Timur Tabi
2007-06-12 16:45       ` Takashi Iwai

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=466DA941.40309@freescale.com \
    --to=timur@freescale.com \
    --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.