ASoC: MPC5200: Changed how appl_ptr is initialized
PATCH 1/1 ASoC: MPC5200: Changed how appl_ptr is initialized
Hello,
I've been working in the ALSA SOC area for the MPC5200. I've noticed that in the routine psc_dma_trigger() in sound/soc/fsl/mpc5200_dma.c there are times when the computed value for s->appl_ptr ends up wrapping negative. This occurs when
s->runtime->control->appl_ptr
is less than
runtime->period_size * runtime->periodsIt seemed like this would occur at then of the data stream or when the data stream is small (smaller than runtime->period_size * runtime->periods).
As far as I can tell, s->appl_ptr is supposed to be the previous value of s->runtime->control->appl_ptr, so the driver can send out the right number of bytes (from previous appl_ptr to current appl_ptr) to avoid pops and clicks at the end of the audio.
So it appears the assumption in this code is wrong, that the previous s->runtime->control->appl_ptr is always rumtime->period_size * runtime->periods bytes prior to the current s->runtime->control->appl_ptr.
I took out this code and instead added code to intialize s->appl_ptr to 0 in psc_dma_open().
Does this fix seem right?
- John
The computation for appl_ptr in the trigger() routine made a bad assumption when the stream is at the end of the file and there is not (periods * period_size) bytes remaining in the data.
This causes playback issues when the total stream size is less than this amount, as the s->appl_ptr wrapps negative and the data is never played.
---
sound/soc/fsl/mpc5200_dma.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
sound/soc/fsl/mpc5200_dma.c +1 -2
@@ -181,8 +181,6 @@ static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)* end of stream and not over running it. */ s->runtime = runtime; - s->appl_ptr = s->runtime->control->appl_ptr - - (runtime->period_size * runtime->periods);/* Fill up the bestcomm bd queue and enable DMA. * This will begin filling the PSC's fifo.
@@ -287,6 +285,7 @@ static int psc_dma_open(struct snd_pcm_substream *substream) } s->stream = substream; + s->appl_ptr =0 ;return 0 ; }
Quoted 9 lines · John Bonesio
Hello,
I've been working in the ALSA SOC area for the MPC5200. I've noticed that in the routine
psc_dma_trigger()insound/soc/fsl/mpc5200_dma.cthere are times when the computed value fors->appl_ptrends up wrapping negative. This occurs when
s->runtime->control->appl_ptr
is less than
runtime->period_size *runtime->periods
I view it as a flaw in ALSA that the driver has having to use appl_ptr in order to behave correctly.
This is a batch mode DMA device. ALSA provides the last fragment and pads it with zeros. When the last fragment plays the interrupt occurs and ALSA is notified. ALSA turns around and stops the DMA hardware.
But there is a latency before ALSA stops the DMA hardware. The interrupt occurred after playing the last padded zero sample. During the time it takes the interrupt to get into ALSA and back into the driver to shut the DMA off, the driver is playing garage since ALSA has not initialized the next fragment. This garbage is clearly audible as a burst of noise at the end of every clip.
Monitoring appl_ptr allows the driver to shut the DMA off at the end of the clip without waiting for ALSA.
Quoted 7 lines
It seemed like this would occur at then of the data stream or when the data stream is small (smaller than
runtime->period_size*runtime->periods).As far as I can tell,
s->appl_ptris supposed to be the previous value ofs->runtime->control->appl_ptr, so the driver can send out the right number of bytes (from previousappl_ptrto currentappl_ptr) to avoid pops and clicks at the end of the audio.
That was correct.
Quoted 5 lines
So it appears the assumption in this code is wrong, that the previous
s->runtime->control->appl_ptris alwaysrumtime->period_size*runtime->periodsbytes prior to the currents->runtime->control->appl_ptr.
I missed the case of very small buffers.
Quoted 44 lines
I took out this code and instead added code to intialize
s->appl_ptrto 0 inpsc_dma_open().Does this fix seem right?
- John
The computation for
appl_ptrin thetrigger()routine made a bad assumption when the stream is at the end of the file and there is not (periods *period_size) bytes remaining in the data.This causes playback issues when the total stream size is less than this amount, as the
s->appl_ptrwrapps negative and the data is never played.Signed-off-by John Bonesio <[email protected]>---
sound/soc/fsl/mpc5200_dma.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)sound/soc/fsl/mpc5200_dma.c +1
-2@@ -181,8 +181,6 @@ static int psc_dma_trigger(struct snd_pcm_substream *substream, int cmd)* end of stream and not over running it. */ s->runtime = runtime; - s->appl_ptr = s->runtime->control->appl_ptr - - (runtime->period_size * runtime->periods); /* Fill up the bestcomm bd queue and enable DMA.* This will begin filling the PSC's fifo. @@ -287,6 +285,7 @@ static int psc_dma_open(struct snd_pcm_substream *substream) } s->stream = substream; + s->appl_ptr = 0; return 0; }
Signature · 2 lines
Jon Smirl [email protected]