On Tue, 16 Jun 2020 14:17:43 +0100 Mark Hills mark@xwax.org wrote:
Distorted audio appears occasionally, affecting either playback or capture and requiring the affected substream to be closed by all applications and re-opened.
Yes, it also happens here very rarely (one time every some months) and I failed to reproduce the problem.
The best way I have found to reproduce the bug is to use dmix in combination with Chromium, which opens the audio device multiple times in threads. Anecdotally, the problems appear to have increased with faster CPUs.
Since applying this patch I have not had problems, where previously they would occur several times a day.
This patch addresses the following issues:
Check for progress using the counter from the hardware, not after it has been truncated to the buffer.
There appears to be a possible bug if a whole ringbuffer advances between interrupts, it goes unnoticed.
In that case the stream must be restarted anyway due to xrun.
Remove chip->last_period:
It's trivial to derive from pipe->last_counter, and inside pipe is where it more logically belongs. This has less scope for bugs as it is not wrapped to the buffer length.
Ok.
- Remove the accessing of pipe->dma_counter twice in the interrupt handler:
Why twice?
+static int snd_echo_poll_substream(struct snd_pcm_substream *substream) [...] static irqreturn_t snd_echo_interrupt(int irq, void *dev_id) [...]
Looks fine to me.