Ensure sample rates and data formats are matched between the libasound client
and the audio hardware, so that there's no need for Soft SRC or any other data
conversion in libasound.
Make sure the libasound client's reads and writes are in the exact audio fragments/block
size, and disable the libasound sub-buffering plugin by calling
snd_pcm_plugin_set_disable():
In the libasound client, configure the audio interface to use a smaller audio
fragment/block size.
If playing to the software mixer, the fragment size can be any multiple of the PCM software mixer's fragment size,
up to the maximum fragment size.
(In earlier releases, the fragment size was locked to the software mixer's fragment size, which is 4 KB by default).
Note:
Make sure to look at the fragment size returned via the
snd_pcm_plugin_setup()
call, because the audio interface may not be able to exactly
satisfy your fragment size request, depending on various factors such as DMA
alignment requirements, potentially required data conversions, and so on.
In the libasound client, set the playback start mode to be
SND_PCM_START_GO, and then issue the "go" command (by calling
snd_pcm_playback_go())
after you've written two audio fragments/blocks into the interface.
For capture, use SND_PCM_START_DATA, which enables capture to the client as soon as one fragment
of data is available.
If you're using the sw_mixer, then:
If your fragment size is the same as the software mixer's fragment size, then you must wait until
three audio fragments/blocks are written to audio interface before issuing the "go" command,
or else you will risk an underrun.
If your fragment size is larger (by an even multiple) than that of the software mixer, then you need
to wait only until two audio fragments/blocks are written before issuing the "go" command.