mupuf.org // we are octopimupuf.org

Nura Headphones on Linux

Tl;dr: Quirk for the USB mode is on the way for fix­ing the prob­lem up­stream, force a sam­pling rate of 48kHz to get sound out in the mean time

I re­ceived a cou­ple of days ago my nu­ra­phones which I backed on Kick­starter some time ago. So far, I re­ally like the sound qual­ity and they sound a bit bet­ter than my mon­i­tor­ing loud speak­ers. I re­ally like in-ear mon­i­tors, so this head­set is no is­sue for me, on the con­trary!

Since I am ex­clu­sively a Linux user, I wanted to get things work­ing on my work’s PC and my Sail­fish OS X. I had no is­sue with blue­tooth on my phone and Desk­top PC (in­struc­tions), but the teth­ered mode was not on ei­ther plat­forms… The sound card would be rec­og­nized but no sounds com­ing out…

De­bug­ging the is­sue

Af­ter ver­i­fy­ing that the head­set in­deed works out of the box on Win­dows (no dri­ver needed), I knew the head­set was likely mis­con­fig­ured. Back on Linux, I tried us­ing alsa di­rectly to re­duce the prob­lem as much as pos­si­ble, and the sound just came out with­out any hick­ups!

Af­ter fid­dling with some pulseau­dio pa­ra­me­ters to mimic as closely as pos­si­ble the set­tings used by aplay, I man­aged to get the sound out sim­ply by set­ting the fol­low­ing pa­ra­me­ter in /etc/pulse/daemon.​conf:​

default-sample-rate = 48000

Now that we have some sound out, let’s try to un­der­stand why pulseau­dio was de­fault­ing to 44.1kHz. It would seem like Win­dows, or ALSA (pro­to­col used by aplay to play sound) are us­ing the de­fault sam­pling rate of the head­phones. How­ever, pulseau­dio uses 44.1kHz and 16 bit sam­ples by de­fault be­cause it is al­ready suf­fi­cient to cover the en­tire spec­trum that can be heard by the hu­man ear and in­creas­ing it for play­back is just a waste of com­put­ing power. So, to avoid re­sam­pling from 44.1kHz to 48kHz, which re­duces the qual­ity of the sound and uses more CPU, pulseau­dio prefers se­lect­ing a match­ing sam­pling rate if the USB in­ter­face sup­ports it.

Let’s check what are the sup­ported sam­pling rates:

$ cat /proc/asound/nuraphone/stream0
nura nuraphone at usb-0000:00:14.0-4, full speed : USB Audio

Playback:
Status: Stop
Interface 2
    Altset 1
    Format: S16_LE
    Channels: 2
    Endpoint: 3 OUT (NONE)
    Rates: 48000, 44100, 32000, 22050, 16000, 8000

Capture:
Status: Stop
Interface 1
    Altset 1
    Format: S16_LE
    Channels: 1
    Endpoint: 3 IN (NONE)
    Rates: 48000

Bingo, 44.1kHz is in­deed a valid op­tion, if are to be­lieve what the head­phones re­port! Af­ter try­ing to op­er­ate pulseau­dio at all the listed sam­pling rates, it ap­pears that only the 48kHz mode ac­tu­ally works… Also, I never man­aged to make use of the mi­cro­phone, on Win­dows or Linux. So, to avoid any prob­lem, we need to in­struct Linux to de­ac­ti­vate the fea­tures the head­set is falsely claim­ing to sup­port.

Patch­ing the Linux ker­nel (patch)

I have been a ker­nel de­vel­oper for al­most 8 years, and have been com­pil­ing Linux ker­nels for a bit more than a decade, but I never had to deal with the sound sub-sys­tem, so that was an in­ter­est­ing feel­ing.

Iden­ti­fy­ing the dri­ver I needed to fix was quite easy, and I quickly found the file sound/usb/quirks-table.h which con­tains most of the quirks for the USB sound cards.

Af­ter that, it was just a mat­ter of fol­low­ing the count­less ex­am­ples found in the file, fig­ur­ing out some pa­ra­me­ters by us­ing printk, test­ing the re­sult, it­er­at­ing un­til it worked as ex­pected, and then craft­ing a patch that I sent to the alsa-de­vel mail­ing list.

I am now wait­ing for re­views, which will end ei­ther with me hav­ing to im­ple­ment a bet­ter so­lu­tion or with the patch get­ting ac­cepted di­rectly. I’ll keep you up to date.

EDIT 2017-01-15: My patch got ac­cepted as-is (link), and it will land in Linux 4.16 or 4.17.

EDIT 2017-01-21: My patch is part of the 4.16 sound pull re­quest, which means it will al­most cer­tainly be part of Linux 4.16.

Workaround un­til Linux is fixed

For some dis­tri­b­u­tions, it may take years un­til the fixed code lands. In the mean time, you may change pulseau­dio’s con­fig­u­ra­tion by adding the fol­low­ing line:

default-sample-rate = 48000

This will slightly in­crease your CPU con­sump­tion, but you will likely not be able to mea­sure it, so don’t sweat about it!

What’s next?

Here is a list of fea­tures I would like to see on the Linux desk­top:

  • Bat­tery sta­tus: Not sure this is even pos­si­ble with the cur­rent hard­ware, I will need to in­ves­ti­gate
  • Se­lect­ing pro­file: Right now, pro­files can only be changed us­ing a smart­phone. I would like to change that.

I am not com­mit­ing to im­ple­ment­ing any of this, but that would be nice to see.

That’s all, folks!

Comments