Audio and MIDI Controller on Ubuntu Linux

Khairil Yusof
7 min readMay 21, 2020

--

Setting up Ubuntu Linux for audio and MIDI is relatively quick and straightforward these days. This will cover setting up your audio system with JACK Audio and then your MIDI keyboard.

This quick write up is on simply quickly getting a MIDI controller keyboard, which is pretty much any keyboard with USB port these days to play virtual instrument installed on your computer.

sudo apt install ubuntustudio-audio linux-lowlatency

This should get you everything you need, especially the Ubuntu Studio Setup Utility and low latency kernel. Reboot.

Understanding Configuring JACK and Pulseaudio

Usually one would have a USB Audio Interface like a Steinberg UR22 or Focusrite, but we will use our built-in sound device in this article.

JACK Audio Connection Kit is the audio system that allows us to connect different audio sources and outputs out, with low latency. The delay between say pressing a key or recording in mic and the audio that comes out of your computer speakers. If it’s too high, the delay is noticeable and confusing, like trying to talk in a video call where you can hear your delayed voice from someone else using speakers and not muting.

Try to get this as low as possible, while still having everything work and without Xruns. Xruns are when your CPU cannot keep up with the audio data, and it will result in crackling and pops. A buffer size of 256 would give you about 10ms of latency which would be good enough for playing keyboards. For my generic sound card, I’ve gotten it down to 128 buffers and 3 periods, which is about 8ms.

Get your other devices working

Under Extra Devices tab, you will probably want to enable Bridge USB Devices to Jack. Usually this is the microphone from your webcam or USB microphone, which is the case if you don’t have a USB audio interface.

Ubuntu Studio Controls — Audio Setup

Bridging (joining between different systems) JACK and Pulseaudio

Pulseaudio currently handles most of the sound support for your desktop applications such as your web browser, music player, games and video call apps like Skype and Zoom. You don’t want to get rid of this functionality if you want to use your normal desktop apps.

What we want is to have pulseaudio outputs (playback) and input (recording/microphone) to work together with JACK which will take over control over management of your audio devices.

Thanks to Ubuntu Studio Controls you don’t need to edit a bunch of text configuration files.

For normal audio soundcard (builtin) and a webcam, we will want to bridge at least 2 input bridges. You can add an additional one by clicking on the Add an input bridge.

JACK Patchbay and Carla

You can think of JACK as a patchbay or the back of your home entertainment devices, where you can connect different audio inputs and outputs with cables.

Open the application Carla and click on the Patchbay tab. If you don’t see the inputs and outputs, on the bottom left there is a mini map of what’s available and you can drag the box over the mini patches.

system: playback_1 and playback_2 is your line out output port (usually connected to your speakers)

system: capture_1 and capture_2 is your line-in/mic input on your sound card or motherboard

pulse_out: is the sound output of pulseaudio that’s mixed from all pulseaudio apps

pulse_in 1 and 2 is what pulseaudio sees as input devices

The interesting thing with JACK is that you can easily see and connect what you want into those inputs.

In the following example, I’ve connected C525, my webcam mono output into both pulse_in channels and my line-in port on my sound card to pulse_in 2.

Carla Patchbay with Pulseaudio Bridges

This is how it looks like on Skype. As you can see, I probably should change the microphone to pulse_in as that is what my webcam C525 is connected to in JACK patchbay. I could also just keep it as pulse_in-2 in Skype ,and in Carla connect C525-in to pulse_in-2 and that would work too. With JACK patchbay you have clear understanding of what devices are connected to.

Skype Audio Settings

This configuration is consistent throughout all desktop applications on Linux which usually defaults to using pulseaudio which is installed by default. Here is the Pulseaudio Volume Controller for inputs. You can also monitor here, to check if your microphone is working correctly.

Pulseaudio Volume Control — Input Devices

If after reboot and login, your volume controls on your keyboard are only adjusting Null Output, you can click on the green check next to pulse_out to make it the default output device. Your volume controller will now work properly.

Note that, this is your pulseaudio overall volume, not the master volume of your audio device. If your pulseaudio volume is at maximum, and your master volume is very low or mute, you might not hear anything.

To change the master volume controller, you need to go to Ubuntu Studio Controls Audio tab and click on Open QASMixer for GUI to manage the settings of your main sound card device, including master volume. Your audio device options may be different from mine, but the Master volume should be there.

Hooking up your MIDI Controller to play songs with JACK and Linux virtual instruments

To get MIDI controller to be detected, and usable in JACK, you will need to bridge ALSA MIDI to JACK MIDI, somewhat similar to Pulseaudio steps earlier.

You can enable this and restart JACK via the GUI in Ubuntu Studio Controls.

Or you can open a terminal and type:

 a2jmidid -e

Open up Carla Patchbay and you should now see your MIDI Controllers, we’re interested in the capture (input) ports for now. Almost all USB MIDI devices should work, as USB MIDI like audio is a standard and usually does not need additional drivers. Check your MIDI Controller manual on the different channels. For my keyboard, the keys are MIDI 1 and other controls are MIDI 2.

Carla can also load up virtual instrument plugins VSTs, LADSAP or LV2 in Linux.

Click on the + Add Plugin button on the menu bar of Carla, and search for and add MDA Piano, which should have been installed as part of Ubuntu Studio Audio package.

Connect your MIDI input to the events-in MIDI port of MDA Piano, and then the output to system playback. You now have a pretty decent bright Piano VST.

Carla also can also load SFX intruments and you can try find some free ones online to try as well such as Salamander Grand Piano which is a high quality sampled Yamaha C5 piano. You are now no longer limited to the onboard synth sounds of a cheap keyboard, and make it play complex sampled virtual instruments similar to that of much more expensive e-pianos.

From what we’ve learned earlier, we know we could connect our output to our pulse_in and now play the piano in the background, mixed with in our mic for your Skype calls.

At this stage you can now happily enjoy playing or experimenting on your connected keyboard.

Linux DAWS

Eventually you may want to experiment with creating or arranging music within a Digital Audio Workstation (DAW) on Linux. There are now several options on Linux. They’re complicated, so we’re only going to touch on the MIDI controller settings we’ve covered.

Ardour

Ardour is a free/open source software DAW, and you will need to launch a2jmidi to bridge to use your MIDI keyboard with it.

Bitwig Studio

If you’re trying out Bitwig Studio DAW on Linux, you don’t need to load up a2jmidi for your MIDI controller to work. Bitwig will detect and communicate directly with your MIDI Controllers via ALSA.

--

--