From: Jaroslav Kysela <perex@perex.cz>
To: David Henningsson <coding@diwic.se>,
alsa-devel@alsa-project.org, tiwai@suse.de
Subject: Re: [PATCH 1/1] sound: rawmidi: Add framing mode
Date: Thu, 25 Mar 2021 21:47:52 +0100 [thread overview]
Message-ID: <ca984b7a-bb0b-c1fb-e2ce-537e7e1775b5@perex.cz> (raw)
In-Reply-To: <c456e5a2-66aa-4390-6968-1e030e8962e7@diwic.se>
Dne 24. 03. 21 v 17:17 David Henningsson napsal(a):
>
> On 2021-03-24 17:06, Jaroslav Kysela wrote:
>> Dne 24. 03. 21 v 6:31 David Henningsson napsal(a):
>>> This commit adds a new framing mode that frames all MIDI data into
>>> 16-byte frames with a timestamp from the monotonic_raw clock.
>> I would add support for monotonic timestamps, too. The NTP drifts are usually
>> small, so it may make sense to support those timestamps, too. It may be handy
>> for the synchronization among multiple machines (timing sources).
>>
>> The timestamp mode should be selected separately than the framing mode.
> Okay, noted for v3.
>>
>>> +#define SND_RAWMIDI_FRAMING_DATA_LENGTH 7
>>> +
>>> +struct snd_rawmidi_framing_tstamp {
>>> + unsigned int tv_sec; /* seconds */
>>> + unsigned int tv_nsec; /* nanoseconds */
>>> + unsigned char length;
>>> + unsigned char data[SND_RAWMIDI_FRAMING_DATA_LENGTH];
>>> +};
>> Perhaps, we should consider to have a fixed header and variable data length
>> here. For MIDI, the standard messages have only few bytes usually. It would be
>> better to use this space for the seconds field:
>>
>> header {
>> unsigned long long tv_sec;
>> unsigned int tv_nsec;
>> unsigned int len;
>> unsigned char data[0];
>> };
>
> I considered that, but it has problems with alignment. If you have a
> normal midi message of 3 bytes, now your second tv_sec will end up
> starting on an odd byte, unless you add padding, and then that padding
> needs to be specified and so on. In addition, half of the header could
> end up in the end of the ring buffer and the other half in the
> beginning. So I found the 16 byte fixed version to be simpler and easier
> to implement correctly.
I see. I agree that the fixed frame is easier to handle.
> However if you like we could change the tv_sec to 64 bit and end up with:
>
> #define SND_RAWMIDI_FRAMING_DATA_LENGTH 3
>
> struct snd_rawmidi_framing_tstamp {
> unsigned long long tv_sec; /* seconds */
> unsigned int tv_nsec; /* nanoseconds */
> unsigned char length;
> unsigned char data[SND_RAWMIDI_FRAMING_DATA_LENGTH];
> };
>
> We'll then have only three bytes for the actual data, but since that is what most midi messages are anyway, it would be okay, I assume.
We can use the free bits in tv_nsec. It may be possible to carry 4 midi bytes
with the 64-bit tv_sec field, too.
Jaroslav
--
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
prev parent reply other threads:[~2021-03-25 20:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca984b7a-bb0b-c1fb-e2ce-537e7e1775b5@perex.cz \
--to=perex@perex.cz \
--cc=alsa-devel@alsa-project.org \
--cc=coding@diwic.se \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox