Backstory to my audio interface and condenser mic adventure
For a long time I’ve been trying to set up my old Behringer C2 condenser microphone 🎤 for streaming, gaming, discord calls, etc. This mic had barely been touched since my hobby-musician days about 10 years ago.
Why did I want to use this mic? Well, my Razer Barracuda-X headset mic had almost no gain in wireless mode. I replaced the headset under warranty, no dice 🎲, and hours of 🦆🦆‘ing resulted in no fixes.
The closest I could get to a fix was to ‘boost’ the signal 📶 within PulseAudio.
I had no idea what PulseAudio was when I started. Turns out if you’re running Ubuntu, or Ubuntu MATE as I do, then in 20.04 (at least) you are using PulseAudio. You may have even interacted with it via the little 🔈 icon on your desktop toolbar. PulseAudio has a bit of a reputation for being not great.
The ‘boost’ fix sucks because it’s not adjusting the gain on the headset, it’s post-processing the input signal. When this happens you get quantisation and higher signal-to-noise ratio (SNR). Quantisation makes me sound like an AM radio 📻, retro, but not what I wanted.
Ground zero
You can’t just plug this mic into a computer. It has an XLR socket and more to the point it requires 48V input called ‘phantom power.
The rich person’s option would be to buy a USB interface with XLR like the SHURE X2u.
I happened to have an audio interface lying around, an old TASCAM US122L, so what the heck, let’s try right?
Oh, I was so young and innocent back then.
Attempt one: learning about Ubuntu/Linux audio
Here’s what I now understand about the way audio works in Ubuntu:
- Kernel level: recognises the hardware and some low-level API to talk to it, this includes some ‘ALSA’ machinery.
- ALSA: a layer on top of the kernel that organises and mixes signals.
- PulseAudio: another layer on top of ALSA that mixes signals.
My guess is that PulseAudio exists because the ALSA API is too awkward for people who write software.
At the kernel/ALSA level it seems that the US122L was ok. When I was running kernal 5.14.21, I could check the sound cards that ALSA knows about:
username@domain:~$ cat /proc/asound/cards
...
3 [US122L ]: USB US-122L - TASCAM US-122L
TASCAM US-122L (644:800e if 0 at 003/004)
However, the card wasn’t listed as a recording (nor playback) device for ALSA:
username@domain:~$ arecord --list-devices
card 2: Generic_1 [HD-Audio Generic], device 0: ALC294 Analog [ALC294 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
Yeah, that’s not it.
Turns out, there are instructions for a thing called ALSA module-usb-us122l
. I needed to set up a ‘usb_stream’ device by modifying
~/.asoundrc
to include:
# The usb_stream plugin configuration
pcm.!usb_stream {
@args [ CARD ]
@args.CARD {
type string
default "1"
}
type usb_stream
card $CARD
}
ctl.!usb_stream {
@args [ CARD ]
@args.CARD {
type string
default "1"
}
type hw
card $CARD
}
With this; I could record from the device using arecord by specifically telling it to use the ‘usb_stream’ device (identified US122L from the
\[ \] in the
output of cat proc/asound/cards
above):
arecord --period-size=640 -c2 -fS24_3LE -r44100 \
-MDusb_stream:CARD=US122L > test.wav
Now:
- ⚠️ Not setting period size resulted in my keyboard freezing completely, requiring a reset.
- ⚠️ same with using aplay; not setting period size was not good.
Problem ‼️ the US122L still isn’t listed as a device via
--list-devices
and furthermore PulseAudio can’t see it.
The instructions for module-usb-us122l mentioned, curiously,
This module is intended for use with the jack driver “usb_stream”.
and
The jack daemon can be started with options like these:
What the jack?! 🤔
Attempt two: Using JACK
Ubuntu (and Linux) being Ubuntu, there are millions of competing options (see xkcd’s Standards). JACK is an alternative to PulseAudio that is intended for musicians and studio types, which explains why it is being mentioned in relation to a studio-ish audio interface device.
I made a lot of progress in this direction, but ultimately, ran into problems when I used OBS. I have reached out to ALSA and JACK devs (see alsa-lib/issues/269 and jack1/issues/118), but no word yet.
For completeness, here’s some of what did work.
Both JACK and a handy GUI called qjackctl are available on the main Ubuntu package repostiory - so they’re easy to install:
username@domain:~$ apt show jackd
Package: jackd
...
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Multimedia Maintainers <debian-multimedia@lists.debian.org>
...
APT-Sources: http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
user_name@domain:~$ sudo apt install jackd qjacktl
...
PulseAudio can pipe to/from JACK via the JACK connectivity modules which are made available in the pulseaudio-module-jack package (also on Ubuntu main package repo). Now;
-
The JACK daemon is a bit like the PulseAudio daemon, that is, any application which accesses sound via (at least) the JACK API can do so while the daemon is running.
-
PulseAudio JACK connectivity modules can, for example, set up a ‘source’ (i.e. a recording signal) based on a JACK ‘source’, like the US122L.
pacmd load-module module-jackdbus-detect pacmd load-module module-jack-source
should create a source called ‘jack_in’, then:
pacmd list-sources | grep name:
should show the jack_in source.
-
PulseAudio can also remap sources so I can get a nice clean mono signal based on the US122L’s left channel which I connected the Behringer C2 to:
pacmd load-module module-remap-source source_name=mono_tascam \ master=jack_in master_channel_map=left channel_map=mono
-
Finally, I could record via PulseAudio
parecord --device=mono_tascam
.
However, as I said above, I ran into problems. As soon as I ran OBS, the microphone would work for a second, then drop out, and ALSA seemed to 💩 itself.
In addition to the tickets I raised, I noticed a similarly quiet ticket on Ubuntu Launchpad. According to this, if the problem is in the kernel, then this is persisting until at least 5.17. Damn. 😬
Attempt three: starting out with PipeWire
Even though there might be a kernel issue; while I was chatting on stream someone mentioned an alternative to both JACK and PulseAudio, called PipeWire.
Now this isn’t available on the usual Ubuntu package repo, however it has been made kindly availabe on the pipewire-debian PPA for those with Ubuntu like me.
I essentially followed the instructions there. Once I had completed the installation step and disabled PulseAudio, I checked that it had actually been disabled:
$ pacmd
No PulseAudio daemon running, or not running as session daemon.
Great! I then enabled pipewire as suggested, and checked that its (pseudo) PulseAudio daemon was running
$ pactl info | grep '^Server Name'
Server Name: PulseAudio (on PipeWire 0.3.57)
It seemed good up until that point. My bluetooth speaker worked ok. However, my USB headset (the Razer Barracuda-X mentioned earlier) didn’t work. And while PipeWire has an implementation of JACK service; I have no idea how to set it up, in particular for a usb_stream device.
Stay tuned!