[alsa-devel] How does struct snd_pcm_hardware relate to the actual hardware

Adam Rosenberg adam at alcorn.com
Wed Jun 30 23:32:41 CEST 2010

I am using DMA to transfer data to SPORT1 on my Blackfin BF537.  I am
using a CS42448 CODEC that has 8 DACs.  I am using TDM mode and have
set the following:

DMA Buffer Size For Each SPORT Data Line (Rx or Tx) = 131072 bytes
DMA Periods = 8

static struct snd_pcm_hardware snd_pcm_hw =
	.formats = SNDRV_PCM_FMTBIT_S32_LE,
	.rates = SNDRV_PCM_RATE_48000,
	.rate_min = 48000,
	.rate_max = 48000,
	.buffer_bytes_max = 32768,
	.channels_min = 2,
	.channels_max = 2,
	.period_bytes_min = 8,
	.period_bytes_max = 4096,
	.periods_min = 8,
	.periods_max = 8,

Everytime I receive a DMA interrupt from the SPORT driver I call
snd_pcm_period_elapsed for all of the substreams that are currently
active.  In the PCM Copy callback I calculate the position within the
DMA buffer to write to based on the TDM slot for the channel and the
position passed into the function.

The audio is not being placed into the DMA buffer properly.  The audio
plays faster than it should and has a constant stutter.  I have read
the "writing an ALSA driver" guide multiple times but it does not
explain the relationship between struct snd_pcm_hardware,
snd_pcm_period_elapsed, and the copy callback clearly enough for me to
understand what I am doing wrong.

Please explain how these interact in more detail to help me fix this
problem.  I can also send the full source code to the CS42448 driver I
am working on if more details are needed.

Thank you,

More information about the Alsa-devel mailing list