[alsa-devel] Why does snd_seq_drain_output() need lots of time to execute?
rafalcieslak256 at gmail.com
Thu Jan 26 18:19:48 CET 2012
I have a serious problem using the ALSA sequencer interface. I am
writing an application that makes use of it's queues, and have got
into troubles which I can't resolve at any cost.
The main problem is that although the documentation states that
snd_seq_drain_output() returns immediately, it turns out that it
occasionally needs lots of time (even a second or two), and blocks my
application, as I call it. According to my research, it looks like a
possible bug in ALSA, but I'd rather ask you if it is indeed
I won't post the code unless you ask me for it, as it is quite a
complex application, and that would unnecessarily mess up this post.
So let me describe what I've found about this problem.
Most of time snd_seq_drain_output() works as it should. I call it from
time to time after putting a bunch of MIDI events on a queue. I use it
to schedule lots of notes, MIDI controller change messages, and
several custom events. It seems I use it more or less appropriately,
for the outputting data is scheduled as I wish it to be. I have
followed tutorials and examples to learn how to use ALSA sequencer
interface, for the documentation does not mention a word on how one
should actually use these calls. However, I have compared my snd_seq_*
calls to many other open-source MIDI applications, and it seems I got
everything right. And, indeed, most of time the app works perfectly.
Problems start when I schedule a big amount of events on the queue.
There is no exact number that triggers the problem, but it's usually
in between 900 and 1100. In that case snd_seq_drain_output() freezes
for a very long time. The exact time depends on the tempo applied to
the queue (which I find very weird), but is about 0,6 sec for tempo of
60bpm, and greater for slower tempos.
I tried also scheduling notes using snd_seq_event_output_direct() to
avoid calling snd_seq_drain_output(), but that caused
snd_seq_event_output_direct() to lag similarly after such large amount
of notes gets scheduled on the queue.
And before you ask, I've set the output buffer to some huge amount,
that is much lager then the amount of notes I am trying to schedule.
It is likely that it's my fault, for I can't fully understand how
these calls should be used. In this case could anyone please explain
me in which cases snd_seq_drain_output() may block the calling app? I
will check if my code might trigger this behaviour. Otherwise, is
there any workaround for this lag? Or maybe I have missed something? I
need help a lot, because this problem makes me completely unable to
continue development of my application.
Please let me know in case you need me to provide additional information.
More information about the Alsa-devel