All of lore.kernel.org
 help / color / mirror / Atom feed
* alsaseq reorders my events
@ 2007-03-01 13:35 Dmitry Baikov
  2007-03-01 16:51 ` [Jackit-devel] [Alsa-devel] " Rui Nuno Capela
  2007-03-01 16:59 ` [Jackit-devel] " Clemens Ladisch
  0 siblings, 2 replies; 9+ messages in thread
From: Dmitry Baikov @ 2007-03-01 13:35 UTC (permalink / raw)
  To: alsa-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jack Dev List,
	linux-audio-dev-oG0YroN0ZiqENrSoib9kfje48wsgrGvP

Hi!

I nearly finished alsaseq driver for jackmidi, but have a problem.
Alsaseq reorders events in fast sequences, so note-on/note-off pairs got mixed.

The algorithm of sending is simple:

 		snd_seq_ev_schedule_real(&alsa_event, output_que, 1, &timestamp);
		frame_time = jack_frame_time(self->jack);
		frame_offset = event.time - frame_time;

		offset = ((long long)frame_offset) * 1000000000 / rate;
		timestamp.tv_sec = (long) (offset / 1000000000);
		timestamp.tv_nsec = (long) (offset % 1000000000);
 		snd_seq_event_output(self->seq, &alsa_event);


Here are the traces of what is going on:

jackmidi_alsaseq reads events from external midi interface and send
them to another midi interface.

Log shows what is being sent to alsaseq and when. Output format is:
[event] at [event.time] ([frame_time] + [frame_offset]) (+[offset]ns)

c0ff@ace ~/src/jack/alsamidi $ ./jackmidi_alsaseq
port created: in (20:0)  MIDI 1
port created: out (20:0)  MIDI 1
port created: in (24:0) USB Trigger Finger MIDI 1
port created: out (24:0) USB Trigger Finger MIDI 1
port_event: ADD 130:0
port created: out (130:0) aseqdump
90 4e 7f  at 86646526 (86622198 + 24328) (+506833333ns)
80 4e 40  at 86649830 (86622200 + 27630) (+575625000ns)
90 4e 7f  at 86654006 (86622201 + 31805) (+662604166ns)
80 4e 40  at 86656795 (86638582 + 18213) (+379437500ns)
90 4e 7f  at 86660562 (86638584 + 21978) (+457875000ns)
80 4e 40  at 86663502 (86638584 + 24918) (+519125000ns)
90 4e 7f  at 86666819 (86638585 + 28234) (+588208333ns)
80 4e 40  at 86669453 (86638585 + 30868) (+643083333ns)
90 4e 7f  at 86673078 (86654965 + 18113) (+377354166ns)
80 4e 40  at 86676430 (86654966 + 21464) (+447166666ns)
90 4e 6f  at 86678638 (86654967 + 23671) (+493145833ns)
80 4e 40  at 86680654 (86654968 + 25686) (+535125000ns)

We can see that all events go strictly in order (their frame_time is
monotonically increasing). Frame offsets are so big, because it runs
under jackd -d dummy -p 16384.

At the same time, aseqdump is hooked to jackmidi_alsaseq output port:

c0ff@ace ~ $ aseqdump
Waiting for data at port 130:0. Press Ctrl+C to end.
Source_ Event_________________ Ch _Data__
  0:1   Port subscribed           128:5 -> 130:0
  0:1   Port subscribed           128:2 -> 130:0
128:2   Note on                 0  78 127
128:2   Note off                0  78  64
128:2   Note off                0  78  64
128:2   Note on                 0  78 127
128:2   Note on                 0  78 127
128:2   Note on                 0  78 127
128:2   Note off                0  78  64
128:2   Note on                 0  78 127
128:2   Note off                0  78  64
128:2   Note off                0  78  64
128:2   Note on                 0  78 111
128:2   Note off                0  78  64

We see, Note on/Note off events are mixed.
Your suggestions, please.

Regards,
Dmitry.

P.S. Not wanting to start a flame war, but it is exactly the case, why
it's better for jackmidi driver to use as lower-level interface as
possible - less problems, more control.

P.P.S. alsa-devels, if you reply, please CC me, i'm not subscribed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] [Alsa-devel] alsaseq reorders my events
  2007-03-01 13:35 alsaseq reorders my events Dmitry Baikov
@ 2007-03-01 16:51 ` Rui Nuno Capela
  2007-03-01 16:59 ` [Jackit-devel] " Clemens Ladisch
  1 sibling, 0 replies; 9+ messages in thread
From: Rui Nuno Capela @ 2007-03-01 16:51 UTC (permalink / raw)
  To: Dmitry Baikov; +Cc: Jack Dev List, alsa-devel, linux-audio-dev


On Thu, March 1, 2007 13:35, Dmitry Baikov wrote:
> Hi!
>
>
> I nearly finished alsaseq driver for jackmidi, but have a problem.
> Alsaseq reorders events in fast sequences, so note-on/note-off pairs got
> mixed.
>
> The algorithm of sending is simple:
>
>
> snd_seq_ev_schedule_real(&alsa_event, output_que, 1, &timestamp);
> frame_time = jack_frame_time(self->jack); frame_offset = event.time -
> frame_time;
>
> offset = ((long long)frame_offset) * 1000000000 / rate; timestamp.tv_sec =
> (long) (offset / 1000000000);
> timestamp.tv_nsec = (long) (offset % 1000000000);
> snd_seq_event_output(self->seq, &alsa_event);
>
>

Is the snd_seq_ev_schedule_real correct where it is? Or should you call
_after_ you set the intended timestamp, like this:


  frame_time = jack_frame_time(self->jack);
  frame_offset = event.time - frame_time;

  offset = ((long long)frame_offset) * 1000000000 / rate;
  timestamp.tv_sec = (long) (offset / 1000000000);
  timestamp.tv_nsec = (long) (offset % 1000000000);

  snd_seq_ev_schedule_real(&alsa_event, output_que, 1, &timestamp);

  snd_seq_event_output(self->seq, &alsa_event);


Cheers.
-- 
rncbc aka Rui Nuno Capela
rncbc@rncbc.org

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 13:35 alsaseq reorders my events Dmitry Baikov
  2007-03-01 16:51 ` [Jackit-devel] [Alsa-devel] " Rui Nuno Capela
@ 2007-03-01 16:59 ` Clemens Ladisch
  2007-03-01 17:23   ` Dmitry Baikov
  1 sibling, 1 reply; 9+ messages in thread
From: Clemens Ladisch @ 2007-03-01 16:59 UTC (permalink / raw)
  To: Dmitry Baikov, alsa-devel, Jack Dev List

Dmitry Baikov wrote:
> I nearly finished alsaseq driver for jackmidi, but have a problem.
> Alsaseq reorders events in fast sequences, so note-on/note-off pairs got
> mixed.

Events with the same timestamp are delivered in strict FIFO order.

> The algorithm of sending is simple:
> 
>  		snd_seq_ev_schedule_real(&alsa_event, output_que, 1, &timestamp);
>  		...
> 		timestamp.tv_sec = (long) (offset / 1000000000);
> 		timestamp.tv_nsec = (long) (offset % 1000000000);
>  		snd_seq_event_output(self->seq, &alsa_event);

Does this code really compute the time stamp _after_ setting it?


Regards,
Clemens

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 16:59 ` [Jackit-devel] " Clemens Ladisch
@ 2007-03-01 17:23   ` Dmitry Baikov
  2007-03-01 22:02     ` Rui Nuno Capela
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Dmitry Baikov @ 2007-03-01 17:23 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: Jack Dev List, alsa-devel

On 3/1/07, Clemens Ladisch <cladisch@fastmail.net> wrote:
> Does this code really compute the time stamp _after_ setting it?

Gotcha! Very stupid....
I copied this code from another place AND misread
snd_seq_ev_schedule_real() body - I was sure it stores timeout's
pointer, not value.

Thank you, gentlemen.

And since I already rewritten this code with snd_seq_ev_set_direct() +
poll(), I have a question:
Does queue + snd_seq_ev_schedule_real() offer better real resolution
than poll (which gives 1 ms)?

Dmitry.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 17:23   ` Dmitry Baikov
@ 2007-03-01 22:02     ` Rui Nuno Capela
  2007-03-01 22:12     ` Lee Revell
  2007-03-02 10:35     ` Clemens Ladisch
  2 siblings, 0 replies; 9+ messages in thread
From: Rui Nuno Capela @ 2007-03-01 22:02 UTC (permalink / raw)
  To: Dmitry Baikov; +Cc: Jack Dev List, alsa-devel

Dmitry Baikov wrote:
> On 3/1/07, Clemens Ladisch <cladisch@fastmail.net> wrote:
>> Does this code really compute the time stamp _after_ setting it?
> 
> Gotcha! Very stupid....
> I copied this code from another place AND misread
> snd_seq_ev_schedule_real() body - I was sure it stores timeout's
> pointer, not value.
> 
> Thank you, gentlemen.
> 
> And since I already rewritten this code with snd_seq_ev_set_direct() +
> poll(), I have a question:
> Does queue + snd_seq_ev_schedule_real() offer better real resolution
> than poll (which gives 1 ms)?
> 

Dunno what really advantage you're after with poll(), but then I'll ask
you what are the actual problems you're trying to workaround by choosing
like so?

AFAICT using an alsa-seq queue and thus snd_seq_ev_schedule_...() are
pretty fitted to the job, or isn't? besides it is kindly assisted at
kernel (module) level that is.

hmm... but then again, if you think you've found something wrong with
alsa-seq queuing... it surely can be fixed, of course ;)

Clemens?
-- 
rncbc aka Rui Nuno Capela
rncbc@rncbc.org

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 17:23   ` Dmitry Baikov
  2007-03-01 22:02     ` Rui Nuno Capela
@ 2007-03-01 22:12     ` Lee Revell
  2007-03-01 22:14       ` Dmitry Baikov
  2007-03-02 10:35     ` Clemens Ladisch
  2 siblings, 1 reply; 9+ messages in thread
From: Lee Revell @ 2007-03-01 22:12 UTC (permalink / raw)
  To: Dmitry Baikov; +Cc: Jack Dev List, alsa-devel

On 3/1/07, Dmitry Baikov <dsbaikov@gmail.com> wrote:
> And since I already rewritten this code with snd_seq_ev_set_direct() +
> poll(), I have a question:
> Does queue + snd_seq_ev_schedule_real() offer better real resolution
> than poll (which gives 1 ms)?

On older kernels it depends on whether ALSA sequencer is configured to
use RTC or regular kernel timers.  And poll() resolution is 4ms by
default (HZ=250) not 1ms.

Anyway mainline Linux kernel has hrtimers now.  So shouldn't the
resolution of all timeouts be much better than 1ms?

Lee

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 22:12     ` Lee Revell
@ 2007-03-01 22:14       ` Dmitry Baikov
  2007-03-01 22:17         ` Lee Revell
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Baikov @ 2007-03-01 22:14 UTC (permalink / raw)
  To: Lee Revell; +Cc: Jack Dev List, alsa-devel

On 3/2/07, Lee Revell <rlrevell@joe-job.com> wrote:
> On older kernels it depends on whether ALSA sequencer is configured to
> use RTC or regular kernel timers.  And poll() resolution is 4ms by
> default (HZ=250) not 1ms.
HZ=1000 here :)

> Anyway mainline Linux kernel has hrtimers now.  So shouldn't the
> resolution of all timeouts be much better than 1ms?

poll() has 1ms resolution by design (API) :(

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 22:14       ` Dmitry Baikov
@ 2007-03-01 22:17         ` Lee Revell
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Revell @ 2007-03-01 22:17 UTC (permalink / raw)
  To: Dmitry Baikov; +Cc: Jack Dev List, alsa-devel

On 3/1/07, Dmitry Baikov <dsbaikov@gmail.com> wrote:
> On 3/2/07, Lee Revell <rlrevell@joe-job.com> wrote:
> > On older kernels it depends on whether ALSA sequencer is configured to
> > use RTC or regular kernel timers.  And poll() resolution is 4ms by
> > default (HZ=250) not 1ms.
> HZ=1000 here :)
>
> > Anyway mainline Linux kernel has hrtimers now.  So shouldn't the
> > resolution of all timeouts be much better than 1ms?
>
> poll() has 1ms resolution by design (API) :(
>

Hmm then I would consider using whatever userspace API hrtimers expose
if it's acceptable to require a recent kernel (or you don't mind
implementing lower resolution for legacy systems).

Lee

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Jackit-devel] alsaseq reorders my events
  2007-03-01 17:23   ` Dmitry Baikov
  2007-03-01 22:02     ` Rui Nuno Capela
  2007-03-01 22:12     ` Lee Revell
@ 2007-03-02 10:35     ` Clemens Ladisch
  2 siblings, 0 replies; 9+ messages in thread
From: Clemens Ladisch @ 2007-03-02 10:35 UTC (permalink / raw)
  To: Dmitry Baikov; +Cc: Jack Dev List, alsa-devel

Dmitry Baikov wrote:
> Does queue + snd_seq_ev_schedule_real() offer better real resolution
> than poll (which gives 1 ms)?

The default timer used by sequencer timers is the RTC timer at 1024 Hz,
i.e., 0.98 ms.  hrtimers are not yet supported.


HTH
Clemens

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-03-02 10:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-01 13:35 alsaseq reorders my events Dmitry Baikov
2007-03-01 16:51 ` [Jackit-devel] [Alsa-devel] " Rui Nuno Capela
2007-03-01 16:59 ` [Jackit-devel] " Clemens Ladisch
2007-03-01 17:23   ` Dmitry Baikov
2007-03-01 22:02     ` Rui Nuno Capela
2007-03-01 22:12     ` Lee Revell
2007-03-01 22:14       ` Dmitry Baikov
2007-03-01 22:17         ` Lee Revell
2007-03-02 10:35     ` Clemens Ladisch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.