[alsa-devel] Keyclick latency

Marc-André Hébert hebert.marcandre at gmail.com
Fri Mar 18 15:13:29 CET 2011


I am working on an embedded device which does audio playback. Now when
the user presses a key, we want to play a tone to provide a keyclick
feedback to the user.

What we always did (we were using OSS before) was pretty much the
simplest thing possible which is for the application to:
-stop sending playback samples
-send the keyclick samples
-resume sending the playback samples

With our new hardware this approach does not produce good results
because of the size of the device's ringbuffer. The larger buffer
introduces a significant latency issue for the user feedback. Reducing
the ring buffer size is not a viable option to ensure no underruns are
generated on the system.

Now I was wondering if there a good approach for this using alsa.
Checking the api, a simple solution would be to:
-call snd_pcm_drop
-send the keyclick samples
-resume sending the playback samples

I've tried this and the latency is good, unfortunately there is the
drawback that some samples were dropped. So I guess the application
could :
-keep a copy of the samples sent,
-check the amount of  samples left in the ringbuffer before calling
-send the keyclick
-resend dropped samples
-resume sending the playback samples

Seems a little overcomplicated so I was wondering if I was missing
something. Would there be a simpler approach? Something like pausing
the stream or reading the contents of the ringbuffer before dropping.


More information about the Alsa-devel mailing list