[alsa-devel] Playing a wav file for a tone in an embedded project

Jeff Horn outforaride at gmail.com
Fri Mar 15 17:07:33 CET 2019


Hi,

I am working on an embedded project ( i.MX6 ) and having an issue using a
wav file for a tone in a Qt application. I am upgrading an existing project
from Qt 5.3 with alsa-lib 1.0.8 and a 3.10.17 kernel to Qt 5.11 with
alsa-lib 1.1.6 and a 4.9.123 kernel.

The beep code is pretty simple, it loads a wav file and saves the wav data
in a buffer. Then on each click event in Qt a beep() function is called.
The beep() function calls snd_pcm_prepare() -> snd_pcm_writei() ->
snd_pcm_drain().

With the previous release the entire beep() function takes ~160ms with the
snd_pcm_prepare() close to 0ms. However, with the latest release the beep()
function takes 550ms with 400ms in snd_pcm_prepare().

I tried to trace snd_pcm_prepare() in the kernel and found that the code
path lands in dapm_power_widgets() and this is where a majority of the
prepare call path time is spent.

I don't know why the previous release seems to almost bypass
snd_pcm_prepare() and the newer code base does not.

So, is there a way to load a wav file on startup, save the wav data and
then on each invocation of a beep() function play the data without having
to call prepare each time?

Thanks in advance for any suggestions/help

Cheers,
Jeff


More information about the Alsa-devel mailing list