[alsa-devel] how to handle buffer underrun in a softsynth

Clemens Ladisch clemens at ladisch.de
Tue Nov 29 11:46:38 CET 2011


Henning Thielemann wrote:
> I must somehow map timestamps of ALSA sequencer events to sample
> counts in order to let notes start within a sample block. JACK claims
> to synchronize everything and it runs on top of ALSA - how does it
> manage synchronization between MIDI and PCM?

It takes timestamps whenever ALSA reports a period boundary.  (This
requires that the code doesn't run too late, i.e., that underruns do
not happen.)  There may be some DLL to smooth out the measurements.

The timestamps can be made more reliable by using a recent enough kernel
and alsa-lib, and enabling timestamps for PCM pointer updates with
snd_pcm_sw_params_set_tstamp_mode(); then snd_pcm_status() will return
both the buffer position and the corresponding timestamp.

> How can I detect a buffer underrun when I disabled underrun detection?

The avail value is larger than the buffer size.


Regards,
Clemens


More information about the Alsa-devel mailing list