Tag Archives: ALSA

MIDI over Bluetooth Low Energy on Linux finally accepted

I am very happy to say that MIDI over BLE on Linux will be part of the next BlueZ release! You can check both commits for this initial release.

In order to build you need alsa-lib dependency and run ./configure  with --enable-midi  option because it is disabled by default since it is an experimental feature yet.

Now you can run bluetoothd and just connect to a BLE device that advertises the MIDI Primary Service. Once done that, bluetoothd will load the MIDI driver and a new ALSA Sequencer client/port will be created for the device. You can check with aseqdump -l  command to list all available ports for subscription. Connect to your Synth and enjoy!

Okay, there might be one caveat on this whole thing. It is very important that Connection Interval property is set via the Connection Update Command from the peripheral, but some devices don’t do it! This is required by the BLE-MIDI spec, but apparently MacOS or iOS force a Connection Interval for their particular adapters on each platform when connected to a MIDI device (yes, clearly they don’t trust device manufactures and they now exactly the most optimal configuration for their specific adapters). And since most MIDI device users use those OSes, they don’t really care about setting the Connection Interval. That’s a shame, I know…

So, If you notice any drop of connection, bad latency and packet drops, force BlueZ do the same – enforce a Connection Interval. To do that you have to edit a file that is located in  /var/lib/bluetooth/[ADAPTER]/[DEVICE]/info  where [ADAPTER] and [DEVICE] is their respective addresses and restart bluetoothd. Add the following lines:

If these values doesn’t work well for you, you might need to try out different MinInterval and MaxInterval for your particular adapter. I know it sucks, but that’s the price to pay for non compliant devices. If that is the case, complain to the manufacturer!

Anyway, back to the good stuff.

There is still work to be done. It is missing the Peripheral role support that can be implemented as a bluetoothd plugin or, perhaps, as a dedicated program if the prior doesn’t meet the low-latency requirements. There is also a support missing in ALSA Sequencer for arbitrary event timestamp, which is required by BLE-MIDI.

I will continue maintaining my personal branch of BlueZ to support MIDI further developments, so feel free to drop a line there, open issues (or use BlueZ bugtracker), send pull-requets etc.

Thanks to ROLI Ltd. for supporting me on this project. Also, Ben Supper, Luiz Augusto von Dentz and Adam Goode for reviewing the patch set.

USB-MIDI Gadget improvements on Linux

Here at ROLI we make heavy usage of Linux and its audio stack (ALSA). And one of our problems was the MIDI Gadget driver. The Linux USB Gadget MIDI driver has been neglected for few years now. It had several bugs, memory leaks and not very clean code-base. Why didn’t anyone care? Well, one of the reasons is that MIDI is a low speed and low throughput protocol, and the current driver was delivering just enough. But that is about to change because ROLI and others have been working on the Multidimensional Polyphonic Expression (MPE) MIDI specification, which increases dramatically the number of MIDI messages per second and per USB request. Thus problems started to arise.

Overall there were several patches that we upstreamed, including performance and memory-footprint improvements by pre-allocating IN USB requests, state machine refactor and fixing an annoying bug that caused the MIDI Streaming endpoint to freeze. There were also critical memory leaks fixes in ChipIdea’s UDC driver.

It is important to note that the Linux community was very helpful and open as always. Our threads created some helpful discussions and motivated others to contribute and improve the MIDI driver too.

So, update your kernel to v4.5 and enjoy a much better MIDI experience for your device on Linux.

PS: v4.6 and v4.7 will also have other improvements that were not merged yet.

MIDI over Bluetooth Low Energy on Linux

Two months ago I made a request for comments on the linux-bluetooth and linux-alsa lists to propose the implementation of the MIDI over Bluetooth Low Energy profile on Linux using BlueZ and ALSA.

The main goals of the project are:

  1. To be transparent to applications, i.e., use ALSA Sequencer interface (ideally also use ALSA RawMidi too[1]);
  2. Support Peripheral and Central Bluetooth GAP roles.

[1] The problem with this is that it requires a kernel module to create a rawmidi device.

MMA is almost done with the actual MIDI over BLE spec. But since it is very close to Apple’s one, we can actually start implementing it.

On the mailing list, BlueZ developers suggested to implement it using the GATT D-Bus API to read and write the MIDI I/O characteristic for the sake of simplicity of initial version. Although this recommendation is valid, it will probably not fit the low latency requirements for this type of application.

That is why I already started the implementation as a native BlueZ plug-in (using the new shared api’s) instead. I’ve also sent two patches to fix a bug on that new API, which still requires some more work.

What I’ve Got So Far

I have a simple BlueZ profile plug-in that setups up an ALSA Sequencer client and port, reads the MIDI I/O characteristics notifications and writes the MIDI messages to the Sequencer port. I have tested the Seaboard RISE with a Linux synthesizer that supports ALSA Sequencer and it seems to work pretty fine.

This initial version still lacks timestamp support, write support and central role support.


I’ve noticed that the connection with the Seaboard RISE was very unstable. Every time the RISE would send high throughput messages, the connection would drop. Then I’ve noticed that the RISE doesn’t send the Connection Update Command to the host and then BlueZ would not update the connection state to be in a lower latency. But that doesn’t happen on a iOS and Mac OS system, but why?

To understand what was going on, I connected to an iThing device as a peripheral exporting the MIDI Service and dumped the Connection Update Command data. I noticed that the Mac OS forced the connection parameters (instead of listening to the peripheral to suggest it) as follows:

  • Minimum Connection Interval: 6
  • Maximum Connection Interval: 12
  • Connection Latency: 0
  • Supervision Timeout: 200

As BlueZ supports the setting up connection parameters, I just changed the info file and reconnected. That caused my connection to be much more stable, but still not perfect. Eventually the connection still drops. So, that is something I still need to figure out. Any suggestions on it will be helpful.

I want to finish the timestamp and write support before releasing it. The central role can be implemented after the release, since I think the most exciting feature right now is to support BLE MIDI devices.

If you are interested in contributing, send me an email, I can share what I have it so far.