How to Configure Loseless Apple Music in Linux

How to Configure Loseless Apple Music in Linux

Compression strips away some data from the original file in order to minimize the file size. This difference in quality is noticeable and even more so on good headphones.

Some micro-nuances and details are loss and instruments have a slightly softer attack due to compression.

Uncompressed vs Compressed Audio Signal (From: LedgerNote

Current Methods and why they don't work

Since Apple Music does not have a native Linux client, most of us would use Apple Music Web or Cider. Unfortunately, the web version of Apple Music does not support loseless. The same could be said for Cider, it is pretty much a wrapper of Apple Music Web.

Another method is to use an Android emulator or a Windows virtual machine. The problem with this is that it is very resource-intensive and messy to setup. To make things worse, the android emulator from Android Studio has a noticeable hissing sound in the background when playing music.

The Solution

We can use Waydroid. Not only is it very light due to its container-based approach, it also does not have a hissing sound in the background.

Before we get started, let's change the supported sampling rates of Pipewire.

1) Check if you're using Pulseaudio or Pipewire:

pactl info | grep "Server Name"

The output should mention Pipewire and look similar to this:

Server Name: PulseAudio (on PipeWire 1.0.0)

If the output doesn't mention Pipewire, switch to Pipewire.

2) Copy pipewire config files to home directory

cp /usr/share/pipewire ~/.config/pipewire

3) Replace default.clock.rate and default.clock.allowed-rates in pipewire.conf with the following values:

default.clock.rate = 44100
default.clock.allowed-rates = [ 44100 48000 88200 96000 176400 192000 352800 384000 ]

4) Restart Pipewire service

systemctl restart --user pipewire.service
systemctl restart --user pipewire-pulse.service

Waydroid Installation

The method of installing will differ from distro to distro. Read the docs here. I will be showing how I installed waydroid in Arch Linux.

Pre-requisites

  1. Intel or AMD GPU. If using an Nvidia GPU, you can use integrated graphics if your CPU supports it. If not, you can still use Software rendering. However, when I tried software rendering, my PC was laggy while playing music. (Was running a Ryzen 5 3600 and GTX 1070 so your mileage may vary) Avoid using software rendering as much as possible.
  2. (Optional) Use Wayland instead of Xorg. If using Xorg, take a look at https://github.com/waydroid/waydroid/issues/195.

(For Arch Users Only) Installation Instructions

You do not need to switch to Linux-Zen kernel or recompile your Linux kernel.

Scroll to 1.4.2 DKMS modules of the Arch Wiki.

  1. Install binder_linux-dkms from the AUR and load the kernel module binder_linux.

  2. Install waydroid from the AUR.

Configuring Waydroid

  1. Once waydroid is installed, you are given an option to initialize it with or without Google Apps installed. I personally prefer without so I ran this command:
waydroid init

OR If you want to have Google Apps pre-installed, run this:

waydroid init -s GAPPS
  1. Enable the waydroid-container.service
sudo systemctl enable --now waydroid-container.service
  1. Launch Waydroid
waydroid show-full-ui
  1. Install Apple Music

If you have Google Apps pre-installed, download Apple Music from the Play Store.

If not, download the lastest Apple Music apk from APKPure or a similar site. After that, run:

waydroid app install $path_to_apple_music_apk

Media Controls Workaround

Since waydroid doesn't support MPRIS, we can not play, pause, or skip music using our keyboard. We can only do it by switching back to waydroid and controlling music through Apple Music itself.

  1. The workaround I thought of is to use KDE Connect. Install KDE Connect in your desktop and waydroid emulator. After the installation, connect both devices by opening the KDE Connect app in your waydroid emulator. A prompt will appear and ask you to connect both devices.

  2. Open the KDE Connect app in your waydroid emulator and click on the (...) icon on the top-right corner to go to settings. and enable Media Player Control and Multimedia controls.

  1. Open the KDE Connect app in your desktop and enable Multimedia control receiver and MprisRemote.

Once you've done all the steps, enjoy!