All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] sound: rawmidi: Add framing mode
@ 2021-03-24  5:31 David Henningsson
  2021-03-24  5:31 ` [PATCH 1/1] " David Henningsson
  0 siblings, 1 reply; 5+ messages in thread
From: David Henningsson @ 2021-03-24  5:31 UTC (permalink / raw)
  To: alsa-devel, tiwai, perex; +Cc: David Henningsson

Hi,

When writing an application that records midi (and e g saves it to disk), ultra-low latency isn't really needed, all we need to know is exactly when the midi message came in. The application can then wake up once a second or so, to write the incoming data, including an accurate timestamp for every event, to disk.

As far as I can see, the rawmidi interface does not support such a feature at all. There is a snd_rawmidi_status syscall, but its timestamp field is not even filled by the kernel (!). But even if that was fixed, it would not fix the problem as there could be several midi events in the buffer with different timestamps.

You could use the seq interface, it does support timestamps, but I can see at least two potential problems with this:

First, the seq code runs in a work queue, not in the actual IRQ. This means that midi event is timestamped too late, especially so if the work is delayed for some reason.

Second, seq hard-codes the timestamp type to monotonic - there is no monotonic_raw, so the timestamp would be affected by NTP changes.

Also, the timespec uses 32-bit for sec and nsec, but I suspect this is less of a problem (unless people constantly record midi for sixty years or so...).

So here's a patch that adds a new "framing" mode that stuffs all MIDI data into 16 byte frames, 8 bytes of timestamp, one byte length, up to seven bytes of data. I'll follow up with an alsa-lib patch if this gets merged. 

David Henningsson (1):
  sound: rawmidi: Add framing mode

 include/sound/rawmidi.h     |  1 +
 include/uapi/sound/asound.h | 18 ++++++++++++++-
 sound/core/rawmidi.c        | 45 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 62 insertions(+), 2 deletions(-)

-- 
2.25.1


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

end of thread, other threads:[~2021-03-25 20:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24  5:31 [PATCH 0/1] sound: rawmidi: Add framing mode David Henningsson
2021-03-24  5:31 ` [PATCH 1/1] " David Henningsson
2021-03-24 16:06   ` Jaroslav Kysela
2021-03-24 16:17     ` David Henningsson
2021-03-25 20:47       ` Jaroslav Kysela

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.