Android DAC bit-perfect playback – (chroot for rooted android)

Last week, I bought a new pair of in-ear earphones Jays q-Jays to challenge my old Ultimate Ears 700 I own since six years.
I already resolder two times a new jack cable. That’s the problem only when you repair… it lasts too long.

With these really good q-Jays, I looked to bring perfect to my cyanogenmod android phone with a portable dac like the S.M.S.L M2 (Sabre).
It is quite simple in fact, since we don’t want to mess up with the audio stack of the phone, let’s chroot:

  • a vanilla linux distribution – debian/devuan
  • alsa
  • mpd

 

To get a running linux distribution running in a chroot, I suggest Linux Deploy, running smoothly with a single ‘.img’ file. The distribution takes at most 2GB on a sdcard.
There’s many tutorials to help you on this.

You should had mountpoints from android, like the add-in sdcard if you have one. Mine is in “/storage/3530-6635” for example. I simply added it to LinuxDeploy mountpoints.

Next, you just need to log on your new chrooted linux, and make the config:

# apt-get install mpd mpc alsa-base alsa-oss alsa-utils 

Configure your alsa gear:

# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: rt5647audio [rt5647-audio], device 0: Saltbay Audio (*) []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: rt5647audio [rt5647-audio], device 1: Deep Buffer Audio (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: rt5647audio [rt5647-audio], device 2: Low Latency Audio (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: rt5647audio [rt5647-audio], device 4: Saltbay Voip (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: rt5647audio [rt5647-audio], device 5: Saltbay Probe snd-soc-dummy-dai-5 []
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: DAC [SMSL M2 DAC], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Edit /etc/asound.conf, we are only interested by our DAC here:

pcm.!default { type hw card DAC }
ctl.!default { type hw card DAC }

Edit /etc/mpd.conf, bit-perfect:

# My mountpoint
music_directory "/storage"

....
# It is a dedicated chroot... run as root to simplify
use     "root"

...
audio_output {
	type "alsa"
        # Output from aplay -L, 'default' should work anyway
	#device "plughw:CARD=DAC,DEV=0"
	device "default"
        # The name of the card
	name "DAC"
	use_mmap "yes"
        # bit perfect
	auto_resample "no"
	auto_channels "no"
	auto_format "no"
        # Volume control from the S.M.S.L M2
	mixer_type "disabled"
	period_time "50000"
  	buffer_time "2500000"
        # No DSD for the M2.
        # dsd_usb "yes"
}

input {
	plugin "curl"
}



And it's done.


# mpc update
Updating DB (#1) ...

Be sure to configure linuxdeploy to start mpd when activating the chroot, you can also activate the 'auto_update' option in mpd.conf.
In LinuxDeploy, I am using the sysv init to start services. This way is more elegant to start/stop your services in the chroot.
The init level at 3 for my running level (which means /etc/rc3.d/S* scripts will be executed).
You have to remove at least the K09halt from /etc/rc6.d... or your android phone will reboot when you close the chroot.

The beauty in all this is having you own dedicated chrooted linux server running mpd.

Once the chroot loaded (LinuxDeploy>start), you can access your mpd player via any mpd client from your android (mine is M.A.L.P), targeting host: localhost.

# mpc
Miles Davis - Yesternow
[playing] #2/2  11:45/25:34 (45%)
volume: n/a   repeat: off   random: off   single: off   consume: off

# cat /proc/asound/DAC/pcm0p/sub0/hw_params 
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 2
rate: 96000 (96000/1)
period_size: 4800
buffer_size: 174762

PS: To activate the S.M.S.L M2 with android OTG mode, USB Host Diagnostics is doing the job.

PS2: I just received a hidizs ap60, with latest firmware, and it works perfectly without any OTG problem. Sound is great and the AP60 is displaying the right rate - bit-perfect - iso with the flac file you are playing. You can check it against a default player on android which indicates the upscaling provided by the audio layer of android (fixed 192k).

1 thought on “Android DAC bit-perfect playback – (chroot for rooted android)

Leave a Reply

Your email address will not be published. Required fields are marked *