Bit Perfect Liva and Music Player Setup

Oooh. Bit Perfect. Perfect bits! Pure unadulterated ones and zeroes reaching your ears as the artist intended! You too can have audiophile quality music playback! Maybe… Audiophilism can be crazy and we can get lost in the weeds. So as long as your standards aren’t super high, these steps that I’ve learned along my Linux journey should get you a “bit perfect” set up.

Linux Mint uses pulse audio for controlling its sound. Pulse audio mixes the sound so you can have it play multiple sources like your youtube video and system sounds at the same time. People like this convenience. But by doing this, it also does strange things to your music, making it bit imperfect. ALSA, which I will be using as the backbone of this Liva music player, does not mess with your audio. Your music player can be set to send the sound to your ALSA device directly bypassing pulse audio.

The music player I’ve chosen is mpd (music player daemon). All it does is keep a database of your music and play the music. It has no built in UI for controlling the music! What the? Separate clients for iOS, android, Mac, PC that allow you to control your music can be installed though. Yes! And some aren’t even ugly.

I’ve configured mpd to look at my iTunes library using a network share.

Install necessary packages

sudo apt-get install mpd ncmpcpp pavucontrol nf-common

mpd — Our music player. Music Player Daemon.
ncmpcpp — Command line gui front end for mpd. It’s very customizeable and so geeky cool.
pavucontrol — pulse audio volume control. (The verdict is still out whether this is necessary)
nfs-common — allows me to mount my nfs share I have set up on my mac. This is where I keep my itunes library that I use for mpd.

Adding your iTunes library to mpd.

Create an NFS share of your itunes library.

I chose NFS because it seemed fastest to me. I believe samba is built into OS X Mavericks and also mint for that matter, but I always like to complicate things. Note, that I am using a Mac and use an Airport extreme as my router, so the ip address of the network starts with 10.0.1, if you’re using another router, it might be something like 192.168.0 or 127.0.0. I also leave my Mac on all the time so I can access the drives.

On the Mac, in terminal:

sudo nano /etc/exports

Add this line:

"/Path/To/iTunes/iTunes Music" -ro -mapall=nobody -network 10.0.1 -mask 255.255.255.0

Then run this to refresh the nfsd:

sudo nfsd disable
sudo nfsd enable

Run this to see your mountpoints:

showmount -e

Reboot because why not.

Adding the share to the Liva and mpd.

On my router, airport extreme, I’ve given my Mac with the itunes library a static ip address of 10.0.1.5. This is so I can easily mount my nfs onto the Liva.

Now in the terminal of the Liva do this:

sudo nano /etc/fstab

And add this line:
10.0.1.5:/Path/To/iTunes/iTunes\040Media/Music /var/lib/mpd/music/ nfs rsize=8192,tcp,intr,cto,nfsvers=3,ro,noatime,nobootwait,bg 0 0

This mounts the shared drive to the default location where mpd will look for your music. You can look up what each of nfs options do here.

Reboot.

Use df -h to see if it mounted correctly.

The Bit Perfection Part

Connect your USB dac to your Liva. Run:

aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC282 Analog [ALC282 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: DAC [HiFimeDIY DAC], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: DAC [HiFimeDIY DAC], device 1: USB Audio [USB Audio #1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

My usb dac analog out (hifimediy) according to this is card 1, device 0. Device 1 is the spdif out, I think.

I edit/create the following file to let the Liva know what device I’d like to make my default ALSA output. By the way, I use nano for editing files in CLI.

sudo nano /etc/asound.conf

I’m actually not sure how necessary this file is for mpd. This is probably more useful for shairport (airplay emulator that I will get into on another post), since it defaults to sending to alsa, and it needs to know which device to send the signal to. Others may suggest updating the .asoundrc file. These files essentially do the same thing, except asound.conf is the system wide configuration while asoundrc is for that particular user.

Fill it in with something like this. Replace the card and device number with your own.

pcm.!default {
type hw
card 1
device 0
}

We then set up something similar in mpd. I won’t go into detail about setting up mpd, but I will show what’s needed to get bit perfect output out of mpd.

sudo nano /etc/mpd.conf

Then go to this section:

audio_output {
    type        "alsa"
    name        "HIFIMEDIY"
    device      "hw:1,0"    # optional
    mixer_device    "hw:1"      # optional
    #format     "44100:16:2"    # optional
    mixer_type  "hardware"  # optional
    #mixer_control  "PCM"       # optional
    #mixer_index    "0"     # optional
}

type — alsa
name — HIFIMEDIY — It doesn’t really matter what you name it.
device — hw:1,0 — Fill this out based on what aplay -l tells you.
mixer_type — hardware — This dac has a hardware mixer. If your dac doesn’t have a hardware mixer, set it to “disabled”.
mixer_device — hw:1 — Since it does have a hardware mixer, we need to tell it what it is otherwise comment out the mixer device if you don’t have a hardware mixer.
format — This is commented out so it doesn’t convert the native format of the sound file.

Now let’s use pavucontrol to turn off the DAC profile from being used in Cinnamon. In Cinnamon, go to Menu > Sound & Video > PulseAudio Volume Control. Go to Configuration tab, and click the profile drop down of your DAC. Select Off, then X out. I’m not certain if this step is really necessary.

Let’s play some music!

On the Liva, in terminal, do this:

ncmpcpp

You should see your new geeky chic mpd client music player. It will know where everything is by default if you have a standard install. You can customize the look and feel creating / editing the config file located at ~/.ncmpcpp/config.

For reference, this my config file.

mpd_music_dir = "/var/lib/mpd/music"
playlist_disable_highlight_delay = "0"
playlist_display_mode = "columns"
browser_display_mode = "columns"
incremental_seeking = "yes"
autocenter_mode = "yes"
header_visibility = "yes"
statusbar_visibility = "yes"
fancy_scrolling = "yes"
follow_now_playing_lyrics = "yes"
display_screens_numbers_on_start = "yes"
ignore_leading_the = "yes"
lyrics_database = "1"
song_columns_list_format = "(10)[blue]{l} (30)[green]{A} (30)[magenta]{b} (50)[yellow]{t}"
colors_enabled = "yes"
main_window_color = "white"
header_window_color = "cyan"
volume_color = "red"
progressbar_color = "cyan"
statusbar_color = "white"
color1 = "cyan"
color2 = "cyan"
active_column_color = "cyan"
active_window_border = "blue"
media_library_left_column = "A"
display_bitrate = "yes"

ncmpcpp

Now in ncmpcpp, type u. This will update your mpd database. Type 5 to see your music library. It should already have at least a few songs. Navigate to one of those songs and press enter. Music!

Checking for bit perfectness

In ncmpcpp, play a song that you know is high resolution. Type q to quit ncmpcpp. mpd will continue playing. Then in the terminal do this:

cat /proc/asound/card1/pcm0p/sub0/hw_params

And of course change the card number to your own.

You should see something like this:

access: RW_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 2
rate: 96000 (96000/1)
period_size: 12000
buffer_size: 48000

Format: S24_3LE tells you it is 24 bit, and rate: 96000 tells you the sample rate is 96000. That’s what the file should be so, it isn’t being bit imperfected! I can’t really confirm that this is the end all be all fool proof way of checking for bit perfectness, but based on the internet, this is the best way.

1 Comment

Leave a Comment

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