misc.: I2S DAC Support

MusicLounge do not support I2S audio dac by default but it’s really easy to add the support of such cards.

Example 1 with Hifiberry DAC Plus RCA and Hiffiberry DAC+ PRO on Raspberry PI 4

Example 2 with Hifi Shield 2 (RCA) on Odriod C4

1- HIFIBERRY DAC And Raspberry PI 4

Make sure the board is correctly connected to the PI 4 and to the power supply (5V 3A)

# edit config.txt

pi@musiclounge:~ $ sudo nano /boot/config.txt

# add at end

dtoverlay=hifiberry-dacplus

CTRL+X to SAVE

List of Hifiberry device tree overlay:

DAC+ Standard/Pro/Amp2

dtoverlay=hifiberry-dacplus

DAC2 HD

dtoverlay=hifiberry-dacplushd

DAC+ ADC

dtoverlay=hifiberry-dacplusadc

DAC+ ADC Pro

dtoverlay=hifiberry-dacplusadcpro

Digi+

dtoverlay=hifiberry-digi

Digi+ Pro

dtoverlay=hifiberry-digi-pro

Reboot and That’s It!

Now check if card number is 1 using aplay -l

pi@musiclounge:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
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: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 [HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0

The trick here is to keep dtparam=audio=on (native headphone) to shift Hifiberry DAC to card number 1 to be dirrectly compatible with MusicLounge audio server settings.

if card number is different go HERE to reconfigure MPD and other audio services

2- HIFI SHIELD 2 AND ODROID C4

Make sure the board is correctly connected to the C4 and to the power supply ( more info available HERE ).

# Edit /media/boot/config.ini to edit the DTBO settings. Open that file and find the part shown below. The below settings different from the default, it adds a new section named overlay_hifishield and uses that section by the overlay_profile variable.

@musiclounge:~ $ sudo nano /media/boot/config.ini
; Device Tree Overlay
overlay_resize=16384
overlay_profile=hifishield
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32"
 
[overlay_hktft35]
overlays="hktft35"
 
[overlay_hifishield]
overlays="hifishield"

Reboot and That’s It!

Now check if card number is 1 using aplay -l

pi@musiclounge:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ODROIDHDMI [ODROID-HDMI], device 0: SPDIF-dit-hifi dit-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: ODROIDHIFI [ODROID-HIFI], device 0: TDM-B-pcm5102a-hifi multicodec-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

if card number is different go HERE to reconfigure MPD and other audio services


List of other Raspberry PI device tree overlay (untested):

502-dac
dtoverlay= hifiberry-dacplus
502-dac-pro
dtoverlay= hifiberry-dacplus
503hta-hybrid
dtoverlay= hifiberry-dac
adafruit-max98357
dtoverlay= hifiberry-dac
adafruit-uda1334a
dtoverlay= hifiberry-dac,i2s-mmap
allo-boss-dac
dtoverlay= allo-boss-dac-pcm512x-audio
allo-digione
dtoverlay= allo-digione
allo-katana-dac
dtoverlay= allo-katana-dac-audio
applepi-dac
dtoverlay= applepi-dac
audio-injector-isolated
dtoverlay= audioinjector-isolated-soundcard
audio-injector-ultra
dtoverlay= audioinjector-ultra
audiophonics-es9028q2m-dac
dtoverlay= i-sabre-q2m
bassfly
dtoverlay= hifiberry-dac
bassfly-mic
dtoverlay= googlevoicehat-soundcard
bassowl
dtoverlay= bassowl
es90x8q2m-dac
dtoverlay= es90x8q2m-dac
fe-pi-audio
dtoverlay= fe-pi-audio
generic-dac
dtoverlay= hifiberry-dac
hifibox-dac
dtoverlay= hifiberry-dacplus
iqaudio-amp
dtoverlay= iqaudio-dacplus,unmute_amp
iqaudio-dacplus
dtoverlay= iqaudio-dacplus,unmute_amp
iqaudio-digiplus
dtoverlay= iqaudio-digi-wm8804-audio
justboom-amp
dtoverlay= justboom-dac
justboom-dac
dtoverlay= justboom-dac
justboom-digi
dtoverlay= justboom-digi
mamboberry-dac
dtoverlay= hifiberry-dac
merus-amp
dtoverlay= merus-amp
nanosound-dac
dtoverlay= hifiberry-dacplus
osa-dacberry-one-plus
dtoverlay= hifiberry-dacplus
osa-dacberry-pro
dtoverlay= iqaudio-dacplus
phat-beat
dtoverlay= hifiberry-dac
phat-dac
dtoverlay= hifiberry-dac
piano-dac
dtoverlay= allo-piano-dac-pcm512x-audio
piano-dac-plus
dtoverlay= allo-piano-dac-plus-pcm512x-audio
picade-hat
dtoverlay= hifiberry-dac
pisound
dtoverlay= pisound
raspiaudio
dtoverlay= googlevoicehat-soundcard
raspidacv3
dtoverlay= raspidac3
rpi-dac
dtoverlay= rpi-dac
soekris-dac
dtoverlay= hifiberry-dac
speaker-phat
dtoverlay= hifiberry-dac
st400-dac-amp
dtoverlay= iqaudio-dacplus
taudac
dtoverlay= taudac
terraberry-dac2
dtoverlay= i-sabre-q2m

TROUBLESHOOTING: GENERAL


# TS6

# if MPD doesn’t start type this to get its status

  1. $ sudo systemctl status mpd

# if the error is related to /libavcodec.so.58: undefined symbol: bcm_host_is_fkms_active
# reinstall libraspberrypi0 pkg

  1. $ sudo apt install --reinstall libraspberrypi0
  1. $ sudo reboot

# NANO return this error (on Armbian / Debian):

Unable to create directory /root/.local/share/nano/: No such file or directory It is required for saving/loading search history or cursor positions.

# check if nano cmd is available using:

  1. sudo /bin/nano .bashrc

# if nano opens the file then you simply need to create the /root/.local/share/nano/ directories
# you can confirm the issue by using:

  1. sudo ls -l /root/.local/

# UPGRADE or DOWNGRADE YOUR KERNEL


# IMPORTANT:
# All information below is for Raspberry PI platform only, does not apply to other devices


# go to
https://github.com/Hexxeh/rpi-firmware/commits/master

# get the sha1 of the kernel
# for example: 4.19.118-v7 e1050e94821a70b2e4c72b318d6c6c968552e9a2

# then to install this old kernel 4.19.118-v7+ enter:

  1. $ sudo rpi-install e1050e94821a70b2e4c72b318d6c6c968552e9a2
  1. $ sudo reboot

# install pkg ends with error:
# “Failed to start The PHP 7.3 FastCGI Process Manager”
# type the cmd below to create the missing directory:

  1. $ sudo mkdir /var/run/php

MusicLounge: myMPD WEB Client


# STEP15

# install myMPD WEB Client
# use a simple Internet browser with your desktop PC, tablet or phone to play and browse your music library

# install dependencies, compile and install myMPD

  1. cd ~/Downloads/

# install git if the command is not found

  1. sudo apt install git
  1. $ sudo git clone https://github.com/jcorporation/myMPD.git
  2. $ cd myMPD
  3. $ sudo ./build.sh installdeps
  4. $ sudo ./build.sh release

# install

  1. $ sudo ./build.sh install

# configure mympd or update config (new version)
# /etc/mympd.conf is no longer used in recent version, check this link for more info:
# https://jcorporation.github.io/myMPD/configuration/

# to create initial configuration enter:

  1. $ sudo mympd -c

# configure http port to 8080
# edit and replace 80 to 8080 and CTRL+X to save

  1. $  sudo nano /var/lib/mympd/config/http_port

# deactivate SSL
# replace true to false and CTRL+X to save

  1. $ sudo nano /var/lib/mympd/config/ssl

# almost all other configuration like deactivate home page
# or auto-generated playlist (AKA myMPD smart playlist)
# are available from mympd web client directly

# ==========================================================
# configure mympd (old version)
# ==========================================================

  1. $ sudo nano /etc/mympd.conf

# change httpport = 80 to

httpport = 8080

# deactivate SSL

ssl = false

# if you want to deactivate home page and auto-generated playlist (AKA myMPD smart playlist)
# add the following in the mympd section

smartpls = false
home = false

# CTRL+O to save
# CTRL+X to exit

# ==========================================================

 

# activate myMPD service

  1. $ sudo systemctl start mympd
  2. $ sudo systemctl enable mympd

# reboot

  1. $ sudo reboot

# check the status

  1. $ sudo systemctl status mympd

# open your internet browser firefox or chromium or safari or other
# we already configure the web server nginx (see the corresponding page for more info)

# the ssl certificate is outdated and automatically generated by myMPD, nothing to worry about

# enter the IP of your audio server
http://192.168.XXX.XXX:8080

# Enjoy your music library from any remote device

# visit myMPD repository for more info:
https://github.com/jcorporation/myMPD

MusicLounge: Update MPD Database

 


# STEP14

 

# Congrats! MPD is installed and running!

# First Steps With Music Player Daemon

# it’s now time to update the tag db of MPD, we are using the client this time (mpc):
# type the following cmds to update the MPD database

  1. $ mpc update


# check the status to see if the update is done type:

  1. $ mpc status


# “Updating DB …” shouldn’t be in the status result (can take a while be patient, 1500 albums/19000 songs is about 10mn to be updated)

# loop with

  1. $ mpc status


# until the DB is updated

 


# STEP15

 

  1. $ mpc status


# play songs to check if everything is OKAY! đŸ˜‰

# use your MPD music player like MALP for Android
# select the correct ALSA audio output
# and to browse your library and enjoy your music!

Click the button NEXT below to continue with optional features like:

# – add a WEB Client to browse/play music from firefox, chrome, safari, edge, …
# – add IR remote control management
# – add DLNA (upnp) server/renderer
# – add Spotify connect
# – add Airplay renderer
# – Roon server/bridge
# – ALSA EQ

Browse your music library with MALP for Android

MusicLounge: Activate MPD


# STEP11

# activate service

  1. $ sudo systemctl enable mpd


# restart MPD

  1. $ sudo systemctl start mpd


# if you have an error in your conf file and MPD didn't start type the following to get the error line:

  1. $ sudo systemctl status mpd


# loop step 10/11 to fix mpd.conf until MPD start correctly without error (see previous step)


# STEP12

# create playlists directory if not exists

  1. $ ls -l /var/lib/mpd/
pi@musiclounge:~$ ls -l /var/lib/mpd/
total 28
drwxr-xr-x 2 root root   4096 Feb 25  2019 music
drwxr-xr-x 2 mpd  audio  4096 Feb 25  2019 playlists
-rw-r--r-- 1 mpd  audio   189 Jun 18 04:37 state
-rw-r--r-- 1 mpd  audio 12288 Jun 18 04:29 sticker.sql
-rw-r--r-- 1 mpd  audio   241 Jun 18 04:41 tag_cache

# SKIP THIS STEP if playlists directory exists (should be already created by MPD installation)

# if the directory does not exist, create it

  1. $ sudo mkdir /var/lib/mpd/playlists


# change user:group if not mpd:audio

  1. $ sudo chown mpd:audio /var/lib/mpd/playlists



# set permission if not already 755

  1. $ sudo chmod 755 /var/lib/mpd/playlists


Click the button NEXT below to continue...

MusicLounge: Configure MPD


# STEP10

# YOUR USB DAC MUST BE CONNECTED TO THE USB PORT AND READY

# edit the configuration of MPD with a DAC USB connected but before:

# identify your USB DAC ID (usually card 1):

  1. $ aplay -l

# in case of *No Soundcard Error*, read our tutorial to install ALSA correctly and prepare your Linux distribution

# to list of playback hardware devices (card 0, card 1, car 2….) and to get the index of your USB DAC

# report this index number in the line device “hw:x,0” of all audio output in mpd.conf see below

# the USB DAC should be indexed 1 or 2

# BEWARE if you disable the RASPBERRY PI HDMI port later (see the corresponding howto) the ID of your DAC will certainly change which require to modify mpd.conf audio output as well


# backup default MPD config mpd.conf into our Downloads/ directory

  1. $ sudo cp /etc/mpd.conf ~/Downloads/mpd.conf

# erase the current config and replace with the settings below

  1. $ sudo truncate -s 0 /etc/mpd.conf
  1. $ sudo nano /etc/mpd.conf

# replace with the settings below

# nano shortcut: CTRL + K to cut an entire line
# this settings use USB DAC on card 1 (hw:1,0), change the index accordingly if needed

# copy the lines below and right-click on nano editor to paste
#

music_directory "/mnt/media"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/tag_cache"
log_file "/var/log/mpd/mpd.log"
pid_file "/run/mpd/pid"
state_file "/var/lib/mpd/state"
sticker_file "/var/lib/mpd/sticker.sql"
user "mpd"
group "audio"
bind_to_address "any"
port "6600"
log_level "default"
restore_paused "yes"
#save_absolute_paths_in_playlists "no"
#metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,disc"
#metadata_to_use "+comment"
auto_update "no"
#auto_update_depth "3"
follow_outside_symlinks "yes"
follow_inside_symlinks "yes"
zeroconf_enabled "no"
zeroconf_name "Music DAC"
connection_timeout "120"
#password "password@read,add,control,admin"
#default_permissions "read,add,control,admin"
#
###############################################################################

# Database #######################################################################
#

#database {
# plugin "proxy"
# host "other.mpd.host"
# port "6600"
#}

# Input #######################################################################
#

input {
plugin "curl"
# proxy "proxy.isp.com:8080"
# proxy_user "user"
# proxy_password "password"
}

# QOBUZ input plugin
input {
enabled "no"
plugin "qobuz"
# app_id "ID"
# app_secret "SECRET"
# username "USERNAME"
# password "PASSWORD"
# format_id "N"
}

# TIDAL input plugin
input {
enabled "no"
plugin "tidal"
# token "TOKEN"
# username "USERNAME"
# password "PASSWORD"
# audioquality "Q"
}

# Decoder #####################################################################
#

decoder {
plugin "ffmpeg"
enabled "yes"
# gapless "no"
}

replaygain "off"
replaygain_preamp "0"
#replaygain_missing_preamp "0"
#replaygain_limit "yes"
volume_normalization "no"
filesystem_charset "UTF-8"

###############################################################################

audio_output {
type "alsa"
name "Default"
device "hw:1,0"
mixer_type "none"
dop "no"
}

audio_output {
type "alsa"
name "ALSA DAC DOP"
device "hw:1,0"
mixer_type "none"
dop "yes"
}

audio_output {
type "alsa"
name "ALSA DAC NoDOP"
device "hw:1,0"
mixer_type "none"
dop "no"
}

audio_buffer_size "4096"
#buffer_before_play "10%"
max_output_buffer_size "131072"
max_connections "128"

audio_output {
type "alsa"
name "ALSA EQ"
device "plug:plugequal"
# format "44100:16:2" # optional
# mixer_device "default" # optional
# mixer_control "PCM" # optional
# mixer_index "0" # optional
}



# CTRL+O to save
# CTRL+X to exit

# disable MPD user service as you run it on headless server:

  1. $ sudo rm /etc/xdg/autostart/mpd.desktop
  2. $ sudo systemctl --global disable mpd.service
  3. $ sudo systemctl --global disable mpd.socket

# MPD is now configured.
#

 


Control The Volume Good or Bad? - Read More...

# keep a Bit Perfect audio with a control of the volume, possible?
# yes, this is possible but only if this is supported by your USB DAC

# check if hardware volume is supported
# get the card number of your USB DAC
# (should be 1 if you only have 1 DAC connected)

  1. $ aplay -l
pi@musiclounge:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: S9Pro [Hidizs S9Pro], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: MQA [D90 MQA], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: SM1ODROIDC4 [SM1-ODROID-C4], device 0: fe.dai-link-0 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: SM1ODROIDC4 [SM1-ODROID-C4], device 1: fe.dai-link-1 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: SM1ODROIDC4 [SM1-ODROID-C4], device 2: fe.dai-link-2 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# in this example we have 2 DAC connected
# list mixer contents of the device 1

  1. $ amixer --card 1 scontents
 
pi@musiclounge:~$ amixer --card 1
pi@musiclounge:~$

# nothing for the topping D90

# now for the S9 Pro

  1. $ amixer --card 0 scontents
pi@musiclounge:~$ amixer --card 0
Simple mixer control 'PCM',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 127 [100%] [0.00dB] [on]
  Front Right: Playback 127 [100%] [0.00dB] [on]
Simple mixer control 'PCM',1
  Capabilities: pvolume pvolume-joined
  Playback channels: Mono
  Limits: Playback 0 - 127
  Mono: Playback 87 [69%] [-20.00dB]

# great! the hardware volume is supported on this DAC
# now we change the mpd.conf to add this dac with hardware volume control

  1. $ sudo nano /etc/mpd.conf

# add this at the end of your configuration
# hw:0 must changed to corresponding card number of your DAC

audio_output {
type "alsa"
name "Hidizs S9 Pro Mixer ON"
device "hw:0,0"
mixer_type "hardware"
mixer_control "PCM"
mixer_index "0"
dop "no"
}

# CTRL+O to save
# CTRL+X to exit

# that’s it!

# Our recommendation is to avoid using volume control in MPD configuration if
# a physical or integrated volume control is already included with your DAC

# in case you have no support of hardware mixer (volume) in your DAC capabilities
# but still want a “software” control of the volume here is the audio output to add to mpd.conf
# this is obviously not recommended

audio_output {
type "alsa"
name "ALSA Software Volume"
device "hw:1,0"
mixer_type "software"
dop "no"
}


Click the button NEXT below to continue…

MusicLounge: Music Player Daemon (MPD) Server



# STEP9

# install MPD (server)and MPC (music player)
# Music Player Daemon (MPD) Info:
# https://www.musicpd.org/

# create a simbolic link for backward compatibility with old version of MPD # which target by default the configuration file in /usr/local/etc/mpd.conf

  1. $ ls /usr/local/etc

# result should be empty or not found then type

  1. $ sudo rm -r /usr/local/etc

  1. $ sudo ln -s /etc /usr/local/

# type again and result should show the files of etc/ directory

  1. $ ls /usr/local/etc

# optional pkg update

  1. $ sudo apt update

# install MPD

  1. $ sudo apt install mpd mpc -y

# Check mpd version

  1. $ mpd -V

# should be 0.21.22 or greater
# if the version is lower then compile and install mpd
# ( version 0.21.22 works really well with Raspberry PI 4 and Odroid C4, latest version works with barbone PC as well )

# our recommendation is to start with the super stable 0.21.22 and later give the latest version of MPD a try (0.22.8 seems to be a good candidate as well).

# you decide, you have the full info here to compile and install MPD, this is one of the benefit to get a full control of your audio server.

Click NEXT button below to skip the compilation of MPD …


COMPILE AND INSTALL MPD - Click To Read More...

# check your gcc version:

  1. $ gcc --version
# if command not found install build-essential package
  1. $ sudo apt -y install build-essential

# skip the gcc install if version is 8.x+ or greater

  1. $ sudo apt install gcc-8-base

# FOR RASPBERRY PI 4 OWNERS:
# on compilation error increase swap file size,
# change default 100 to 1024

  1. $ sudo nano /etc/dphys-swapfile

CONF_SWAPSIZE=1024

# reboot if you change the swap size

  1. $ sudo reboot

# get url archive from https://www.musicpd.org/download.html
# download latest archive mpd-0.21.x.tar.xz into your home directory (Downloads/ for example)
https://www.musicpd.org/download/mpd/0.22/mpd-0.22.6.tar.xz

# be sure to select your /Downloads folder inside your home directory (create the folder Downloads if needed)

  1. cd ~/Downloads

# hyper stable MPD release

  1. $ sudo wget https://www.musicpd.org/download/mpd/0.21/mpd-0.21.22.tar.xz

# latest at this date:

  1. $ sudo wget https://www.musicpd.org/download/mpd/0.22/mpd-0.22.8.tar.xz

# extract (replace -version by the version of mpd mpd-0.21.22.tar.xz):

  1. $ sudo tar xf mpd-version.tar.xz

# enter directory:

  1. $ cd mpd-0.21.22

# install dependencies:

In any case, you need: a C++17 compiler (e.g. GCC 8 or clang 5) Meson 0.49.0 and Ninja Boost 1.58 pkg-config

  1. $ sudo apt-get install ninja-build
# the command below must includes a lot of dev libraries # be careful to double check it before validation with enter key #
$ sudo apt install meson g++ \
libpcre3-dev \
libmad0-dev libmpg123-dev libid3tag0-dev \
libflac-dev libvorbis-dev libopus-dev libogg-dev \
libadplug-dev libaudiofile-dev libsndfile1-dev libfaad-dev \
libfluidsynth-dev libgme-dev libmikmod-dev libmodplug-dev \
libmpcdec-dev libwavpack-dev libwildmidi-dev \
libsidplay2-dev libsidutils-dev libresid-builder-dev \
libavcodec-dev libavformat-dev \
libmp3lame-dev libtwolame-dev libshine-dev \
libsamplerate0-dev libsoxr-dev \
libbz2-dev libcdio-paranoia-dev libiso9660-dev libmms-dev \
libzzip-dev \
libcurl4-gnutls-dev libyajl-dev libexpat-dev \
libasound2-dev libao-dev libjack-jackd2-dev libopenal-dev \
libpulse-dev libshout3-dev \
libsndio-dev \
libmpdclient-dev \
libnfs-dev \
libupnp-dev \
libavahi-client-dev \
libsqlite3-dev \
libsystemd-dev \
libgtest-dev \
libboost-dev \
libicu-dev \
libchromaprint-dev \
libgcrypt20-dev 

# reboot maybe required here # check meson version (0.49 minimum)

  1. $ meson -v

# configure:

  1. $ sudo meson . output/release --buildtype=debugoptimized -Db_ndebug=true -Dsysconfdir=/etc

# check configuration:

  1. $ sudo meson configure output/release

# compile (could take a while… ):

  1. $ sudo ninja -C output/release

# install:

# stop mpd in case it’s running

  1. $ sudo systemctl stop mpd
  1. $ sudo ninja -C output/release install

# go to home directory

  1. $ cd ~/

# Congrats! MPD is compiled and installed

Click the button NEXT below to continue…