Author Topic: USB Audio in Sailfish  (Read 4319 times)

mgfm99

  • Newbie
  • *
  • Posts: 12
    • View Profile
USB Audio in Sailfish
« on: July 01, 2018, 02:20:16 pm »
I've been playing around with the most recent Community Build of Sailfish for the Gemini and thought I'd post a guide to using a USB DAC with the Gemini in Sailfish - the instructions for this I gleaned from a Google search of the IRC archives for sailfish OS adaptations.

The original Jolla 1 did not have USB OTG, so the UI interface was never developed for using peripherals; but with the community versions there have now been many devices which work with Sailfish and have USB OTG.

The Gemini recognizes USB audio DACs on insertion (or at least it does with an Audioquest Dragon Fly), but it won't play any music from any app to it.

To do that you need to do three things:

1. You need to block udev recognising the internal sound system (this won't affect the use of the internal speaker; but if you don't do this, running a udev detect with the new device attached will lead to a reboot):
Add a new file to /etc/udev/rules.d which blacklists the internal sound system before any pulseaudio rules are run: e.g.
89-pulseaudio-usb.rules with the content
ATTRS{id}=="mtsndcard", ENV{PULSE_IGNORE}="1"

2. You need to get pulseaudio to connect with the alsa definitions for usb audio devices; to do this, you only need to
rename usbaudio.conf.disabled to usbaudio.conf in /etc/pulse/xpolicy.conf.d;

3. Last, you need pulseaudio to register that the usb DAC is available in the system. As far as I can see, this needs to be done manually at the moment:
After restarting your Gemini in Sailfish, you need to open thumbterm and run (as user, not as root) 'pactrl load-module module-udev-detect'
On IRC it was suggested simply adding the load-module line to default.pa in /etc/pulse - but the module load is already there, and doesn't seem to react to external devices even after udev rules have been modified, so I found I needed to run this command manually. Didn't matter whether the DAC was already connected or not.

4. You can check this has worked by running as user pacmd list-sinks - there should now be an additional one at the end (i.e. a fifth device) with the details of your DAC.

5. At this stage, media players will output through your USB Audio device - but sound will be capped to 48Hz sample rate; to allow sample rates up to the highest your DAC will allow, edit daemon.conf in /etc/pulse to enable the entry alternate-sample-rate, by default this is set as 48000. For the Audioquest, you should set it to 96000.

6. You might find it useful to install alsa-utils and usbutils from https://build.merproject.org to check that things are being recognized by the kernel when first attached, and that alsa knows this is a soundcard.

7. Must be said that the sound is still somewhat glitchy - as it can be also in Android. However the tweaks in USBAudio Pro in Android enable one to get a perfect and excellent sound out of the Gemini; that uses its own driver, and unfortunately there is no equivalent in Sailfish, and the alsa standard driver is not of the same quality.

klampfenfreak

  • Newbie
  • *
  • Posts: 40
    • View Profile
USB Audio in Sailfish
« Reply #1 on: December 01, 2018, 06:35:51 am »
Strange, after that changes fingerterm could not rotate into landscape-inverted, anymore.  
Zoom H4n USB audio did not work at all, trying to play or record audio thru it.

Quote from: mgfm99
I've been playing around with the most recent Community Build of Sailfish for the Gemini and thought I'd post a guide to using a USB DAC with the Gemini in Sailfish - the instructions for this I gleaned from a Google search of the IRC archives for sailfish OS adaptations.

The original Jolla 1 did not have USB OTG, so the UI interface was never developed for using peripherals; but with the community versions there have now been many devices which work with Sailfish and have USB OTG.

The Gemini recognizes USB audio DACs on insertion (or at least it does with an Audioquest Dragon Fly), but it won't play any music from any app to it.

To do that you need to do three things:

1. You need to block udev recognising the internal sound system (this won't affect the use of the internal speaker; but if you don't do this, running a udev detect with the new device attached will lead to a reboot):
Add a new file to /etc/udev/rules.d which blacklists the internal sound system before any pulseaudio rules are run: e.g.
89-pulseaudio-usb.rules with the content
ATTRS{id}=="mtsndcard", ENV{PULSE_IGNORE}="1"

2. You need to get pulseaudio to connect with the alsa definitions for usb audio devices; to do this, you only need to
rename usbaudio.conf.disabled to usbaudio.conf in /etc/pulse/xpolicy.conf.d;

3. Last, you need pulseaudio to register that the usb DAC is available in the system. As far as I can see, this needs to be done manually at the moment:
After restarting your Gemini in Sailfish, you need to open thumbterm and run (as user, not as root) 'pactrl load-module module-udev-detect'
On IRC it was suggested simply adding the load-module line to default.pa in /etc/pulse - but the module load is already there, and doesn't seem to react to external devices even after udev rules have been modified, so I found I needed to run this command manually. Didn't matter whether the DAC was already connected or not.

4. You can check this has worked by running as user pacmd list-sinks - there should now be an additional one at the end (i.e. a fifth device) with the details of your DAC.

5. At this stage, media players will output through your USB Audio device - but sound will be capped to 48Hz sample rate; to allow sample rates up to the highest your DAC will allow, edit daemon.conf in /etc/pulse to enable the entry alternate-sample-rate, by default this is set as 48000. For the Audioquest, you should set it to 96000.

6. You might find it useful to install alsa-utils and usbutils from https://build.merproject.org to check that things are being recognized by the kernel when first attached, and that alsa knows this is a soundcard.

7. Must be said that the sound is still somewhat glitchy - as it can be also in Android. However the tweaks in USBAudio Pro in Android enable one to get a perfect and excellent sound out of the Gemini; that uses its own driver, and unfortunately there is no equivalent in Sailfish, and the alsa standard driver is not of the same quality.
« Last Edit: December 01, 2018, 06:37:45 am by klampfenfreak »

mgfm99

  • Newbie
  • *
  • Posts: 12
    • View Profile
USB Audio in Sailfish
« Reply #2 on: December 01, 2018, 01:31:08 pm »
[quote name='klampfenfreak' date='Dec 1 2018, 12:35 PM' post='290847']
Strange, after that changes fingerterm could not rotate into landscape-inverted, anymore.  
Zoom H4n USB audio did not work at all, trying to play or record audio thru it.

Did you install alsa-utils?

what does lsusb show when you run it?

What about aplay -l and aplay -L?

also you could try playing a test file from the command line using aplay and specifying the alsa device explicitly to see if anything can be routed to your dac.