Single-purpose jitter-free realtime MIDI patchbay/sequencer

Yesterday I posted the same question to r/FindMeADistro but I got no replies, so I figured I should try here.

I would like to turn an older netbook into a USB MIDI router/recorder/sequencer with quasi-zero latency and jitter, only limited by USB's 1000Hz frame rate. A midi message should arrive in one frame and leave with the next or at most second next frame, i.e. 1 or 2ms later, including any midi processing such as arpeggiation, chord triggering or CC translation.

I don't need a general purpose distro, I'm happy to give up networking, audio and all other overhead except USB MIDI and a way to retrieve the recordings. The router/sequencer would be the only thing ever running on this machine, almost like an embedded system, but I'd expect it to be realtime and rock solid. Is it doable or not?

Posted Jul 19, 2022, 8:40 AM UTC

27
nori_iron•

Your resources are out of sync with your requirements tbh. This is doable, but it isn't something that's been solved for you. IMO: design a test that would prove your requirements are being met, pick a few different real-time kernels and options for each element of your software stack, try it with a few different minimal distros (no display manager or GUI obvsly, arch should be on the list, there are other low-spec distros). Try things. See what works.

This really isn't a job for an older netbook at all. Get a piece of hardware designed for this task or lower your expectations. Not saying you shouldn't try still, it sounds like an interesting project you'll learn something from.

3
howabootOP•

I had not originally planned for a side project, but I may give it a go. I'm not interested in doing it with any hardware other than the netbook, since this is first and foremost about turning a useless netbook into something cool as opposed to me needing a latency-free sequencer that bad. Why do you think a netbook would be unsuitable for the task? The processing requirements are negligible. It can do 3-15ms even with something as heavy as AV Linux + Reaper with low CPU load. Also, what do you mean by "no display manager or GUI obviously"? It isn't obvious to me, at least I thought a 4-core CPU, however weak, is enough to promptly process USB messages and run a basic display manager.

1
spacegardener•

Might be easier (ok… that is quite relative) to achieve that goal with a microcontroller rather than a pc.

1
howabootOP•

Is this because OS's and apps are too bloated to carry out a task like this in 1 millisecond? The reason I'm asking in a Linux sub is because Linux has so many specialized flavors, perhaps one exists where USB latency is in focus. I get that a fully fledged fancy general purpose OS might not be able to do it, but surely a custom no-fluff Linux distro can?

Intuitively, the task sounds trivial, 1 ms is a lifetime in CPU terms and there's really not a whole lot of variables and unpredictable events at play.

1
spacegardener•

I am not saying it is impossible – I have not enough data – never tried anything that ambitious, never really cared much about MIDI latency, so I don't really know what timings are achievable on Linux.What I know is how Linux being a general-purpose OS doesn't even try to hit such targets. I doubt there is an API allowing to schedule high-level (MIDI) data to be sent with a specific USB frame. There are other tasks which will go in a way – disk access (e.g. for regular system logging), GPU interfacing, sharing USB for mouse and keyboard access (even when not used), etc. There are ways to mitigate all this, there is the RT kernel patch to help on the kernel side. But all the things that make Linux a general-purpose OS are going to make things difficult.

On a microcontroller you can write a program that reads a chunk of data from USB, processes it, waits a fraction of ms and sends the processed data out. Nothing else will go in the way of your program. What is not there will not be executed. But you might be forced to implement even the MIDI over USB protocol yourself, which make things difficult in other ways.

2
granticculus•

I'd suggest Alpine because it can easily run from RAM and is quite minimal by default, but I don't know if they package a precompiled RT kernel, so there might be a bit of work there.

You could try setting it up with JACK anyway to get a feel for the performance.

1
[deleted]•

[removed]

1