[alsa-devel] DMA buffer alignment

Clemens Ladisch clemens at ladisch.de
Fri Dec 5 12:34:58 CET 2014


Carlo Caione wrote:
> let's say that our application sends uning snd_pcm_writei() a buffer
> that is exactly 64 bytes and that our hwoff (appl_ofs)

The hardware and the software (appl) pointers are independent.

> is pointing to a memory location 0 in the DMA area.
> When this buffer is taken from the SoC sound driver, the .copy
> callback writes this buffer as follow: 32 bytes (left channel) to
> memory locations from *hwoff to *hwoff+31, and 32 bytes (right
> channel) for *hwoff+32 to *hwoff+63.
> Problem is when my buffer is not multiple of 64 bytes, for example if
> the buffer size is < 64. If I receive a buffer of lenght 32 byte than
> my DMA memory is filled as follows: 16 bytes from *hwoff to *hwoff+15
> and 16 bytes from *hwoff+32 to *hwoff+47, leaving 32 bytes in the
> block not initialized.

These bytes are written later.  And if they are not written fast enough,
you get an underrun.  This is no difference from any other sound card.

> In some way I should always guarantee that the size of the buffer
> passed to my .copy callback is multiple of 64 bytes.

The .copy callback just copies samples to memory; this is possible
with any alignment.

The DMA runs asynchronously, and uses its own pointer.


Regards,
Clemens


More information about the Alsa-devel mailing list