[alsa-devel] Modifying PCM buffer before DMA

Ricard Wanderlof ricard.wanderlof at axis.com
Wed Nov 30 20:47:18 CET 2016


Working with a SoC which has an I2S interface which reuquires 
16-bit-swapped 32 bit samples (i.e. the first and 16 halfwords are 
swapped, but within the halfwords the bytes themselves are little endian), 
I'm trying to figure out a way to adjust the data in the PCM driver so 
that ALSA sees standard S32_LE samples.

My approach is to use a tight loop to halfword-swap the data. This works 
fine for capture, where the swap routine can be run triggered by the DMA 
interrupt as each period arrives from the I2S interface, before calling 
snd_pcm_period_elapsed().

The problem I have is for playback. I want to have SNDRV_PCM_INFO_MMAP set 
in snd_pcm_hardware.info in order to be use plugins such as dmix, which in 
practice means that the PCM driver doesn't really know exactly how much 
data the application has written before the DMA starts writing it out to 
the I2S interface. As far as I can tell, the application layer asks the 
driver for the hw_ptr but there is no way the driver can actually know how 
much data the application has in fact written.

Contrary to the capture case, once the DMA interrupt for a previous period 
has been triggered, the data for the current period will already be on its 
way out to the I2S interface, courtesy of the DMA.

Disabling MMAP seems to be one way to get the PCM driver to take greater 
control of the transfer (for instance via snd_pcm_ops->copy() ), but I 
want to avoid that as mentioned above. My question is, is there another 
way?

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30


More information about the Alsa-devel mailing list