Optimize audio

Here are some tips for reducing audio latency:

  • 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, then the fragment size will be locked to the software mixer's fragment size, which is 4 KB by default).

    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 you must wait until three audio fragments/blocks are written into the audio interface before issuing the "go" command, or else you will risk an underrun.

Last modified: 2014-05-14

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus