Samba Configuration


# STEP13

# share points (useful for browsing/updating server files from Windows or Mac ) add the lines below at the end of the smb configuration:
#
# also, add the home storage shared point
# if you want to get a full access to the sd card content from windows/mac
# (attention ‘root’ access here)
#

  1. $ sudo nano /etc/samba/smb.conf

# edit samba configuration by commenting [home] entries and adding the settings bellow at end (playlists, music and storage access)

[playlists]
path = /var/lib/mpd/playlists
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = mpd

[music]
path = /mnt/media
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = mpd

[www]
path = /var/www/html
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = www-data

[Downloads]
path = /home/pi/Downloads
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

[scripts]
path = /home/pi/scripts
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

[sdcard]
path = /home/pi
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = root


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

# restart samba:

  1. $ sudo /etc/init.d/smbd restart

# or

  1. $ sudo systemctl restart smbd


# wait 5 sec and type the cmd below if shared points are NOT visible from your Windows network browser:

  1. $ sudo systemctl restart nmbd

# now install WS Discovery service to view linux machine from Windows Explorer Network.

  1. $ sudo apt install wsdd

# check the status of the service

  1. $ sudo systemctl status wsdd

# the music contains the songs files and playlists directory is empty but visible using the Windows network browser on your PC

# OPTIONAL: reboot your device

  1. $ sudo reboot

# IMPORTANT: it’s recommended to remove the [sdcard] shared point from smb.conf as soon as your installation is working correctly.

Click the button NEXT below to continue…

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...

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


# If your sound card order changes on boot, you can “play” with /etc/modprobe.d/alsa-base.conf to specify its order. For example, if you want your snd_usb_audio (USB DAC) card to be #1:

options snd_usb_audio index=1

You can also provide an index of -2 to instruct ALSA to never use a card as the primary one and ensure USB DAC never getting index 0:

options snd_usb_audio index=-2

This will change the order of the devices in the list (read the ALSA doc online to get more info on alsa-base.conf).

# check the card IDs after reboot with

  1. $ 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: MQA [D90 MQA], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# also to get the name of the driver list the sound modules with:

  1. $ cat /proc/asound/modules
 0 snd_bcm2835
 1 snd_usb_audio
 2 vc4
 3 vc4

# example of configuration for the raspberry PI 5 or PI 4, edit the alsa-base.conf

  1. $ sudo nano /etc/modprobe.d/alsa-base.conf
options snd_usb_audio index=-2

# on raspberry PI 5 and PI 4 with latest bookworm OS disable HDMI (vc4 kms driver) to be sure to get the card id 1 for your USB DAC.
# edit the config.txt and reboot
# comment: camera_auto_detect=1, dtoverlay=vc4-kms-v3d and max_framebuffers=2
#
and set display_auto_detect=0 see below

  1. $ sudo nano /boot/firmware/config.txt
# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected cameras
#camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=0

# Automatically load initramfs files, if found
auto_initramfs=1

# Enable DRM VC4 V3D driver
#dtoverlay=vc4-kms-v3d
#max_framebuffers=2

# then check with aplay -l

$ 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: MQA [D90 MQA], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

# reboot

  1. $ sudo reboot

# 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"
# uncomment pid_file if you do not use systemd 
#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"
}

decoder {
plugin "wildmidi"
enabled "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
}
# optional output to stream music using vorbis encoder to local device (phone, tablet, pc,...)
audio_output {
type            "httpd"
name            "Local Stream"
encoder         "vorbis"
#encoder        "lame"         # comment vorbis and use lame for iOS support
port            "8000"
quality         "5.0"           # do not define if bitrate is defined
#bitrate        "128"           # do not define if quality is defined
#format          "44100:16:1"
always_on       "yes"           # prevent MPD from disconnecting all listeners when playback
tags            "yes"           # httpd supports sending tags to listening streams.
}

# to get an high res stream from your MPD server change quality from “5.0” to “10.0”
# beware high quality stream needs a high speed WIFI/network to work smoothly

# optional output to stream music using MP3 encoder to local device (phone, tablet, pc,...)
audio_output {
type            "httpd"
name            "Local Stream MP3"
encoder         "lame"
#encoder        "lame"         # comment vorbis and use lame for iOS support
port            "8000"
quality         "0"           # do not define if bitrate is defined
#bitrate        "128"           # do not define if quality is defined
format          "44100:16:2"
always_on       "yes"           # prevent MPD from disconnecting all listeners when playback
tags            "yes"           # httpd supports sending tags to listening streams.
}

# to get an high quality MP3 stream from your MPD server
# set the quality for VBR from “0” the highest quality to “9” the lowest quality.
# beware high quality stream needs a high speed WIFI/network to work smoothly

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

# to get the stream, select “Local Stream” or “Local Stream MP3” audio output in myMPD or any MPD client
# then open VLC app for example and type the address http://musiclounge:8000 in Open Network Stream and play.

# OPTIONAL: You can skip this step if a server distribution is installed
# but for desktop distro you have to disable MPD user service
# because you run it as a 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 server is now configured.
# Click NEXT button to activate Music Player Daemon


# TROUBLESHOUTING

# if the error is releated to audio device not found, read again the first chapter of this tutorial to configure modprobe correctly and ensure your USB DAC card ID is 1 or edit all your configuration including MPD to change the plugin hardware id (“plughw:X,0”)

# in case of error (generally occurs within 5s just after playing):

alsa_output: Decoder is too slow; playing silence to avoid xrun

# adding the following lines to all your audio output in mpd configuration (/etc/mpd.conf) may help
#

buffer_time "200000"
period_time "5084"

#
# edit mpd.conf and scroll to audio output area to add the 2 lines

  1. $ sudo nano /etc/mpd.conf
.
.
.
audio_output {
type "alsa"
name "Default"
device "hw:1,0"
mixer_type "none"
dop "no"
buffer_time "200000"
period_time "5084"
}

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

#
# in case of non fatal binding error

server_socket: bind to '0.0.0.0:8000' failed (continuing anyway, because binding to '[::]:8000' succeeded): Failed to bind socket: Address already in use

# a binding already exists due to ipv6, however mpd is running correctly. if you do not need ipv6 support follow these instructions to disable it by using sysctl command and by adding the kernel option ipv6.disable=1 https://www.wikihow.com/Disable-Ipv6-on-Linux


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 and only with PCM

# 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"
}

# another example with Topping D50 III DAC on card id 1

audio_output {
type "alsa"
name "Topping D50 III VOL ID1"
device "hw:1,0"
mixer_device "hw:1"
mixer_type "hardware"
mixer_control "D50\ III"
mixer_index "1"
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…

Local Music Library Or USB Hard Drive

# using a local music library is very easy, simply add all your music inside /mnt/media, this folder is shared on the local network and is also available from host \\MUSICLOUNGE\music (read the SAMBA configuration for more info)

# using an external USB hard drive for your music library is also easy but the disk must be powered (even an SSD) with an external adapter.

# so make sure the usb hard drive is powered with an external adapter and plug the usb cable on the server board (rPI 4 or C4 or Pc),

Install exFAT File System

# exFAT file system is not installed by default on all distributions and you may need it
# to install exFAT do the following:

  1. $ sudo apt-get install exfat-fuse
  2. $ sudo apt-get install exfat-utils
  3. $ sudo reboot

Configuration

# start to list disks attached to find where is located

  1. $ sudo fdisk -l
Device Boot Start End Sectors Size Id Type
/dev/sda1 63 1953520064 1953520002 931.5G 7 HPFS/NTFS/exFAT

# /dev/sda1 is our usb hard drive location


# now get its UUID and file system

  1. $ sudo blkid
/dev/sda1: LABEL="SAMSGBKUP" UUID="9A2B-8FC2" TYPE="exfat" PARTUUID="5b0a6a10-01"

# here we have 9A2B-8FC2 as UUID and exfat file system

Auto-Mounting Drive

# normally if the MusicLounge audiophile server is correctly installed the /mnt/media directory is already there, check this:

  1. $ ls /mnt/media

# creates the directory if needed:

  1. $ sudo mkdir /mnt/media

# edit fstab to mount the disk at startup

  1. $ sudo nano /etc/fstab

# add this line WITH YOUR UUID and correct file system

# comment with # prefix any other line with /mnt/media)

UUID=9A2B-8FC2 /mnt/media exfat defaults,auto,umask=000,users,rw 0 0

# CTRL + X and Y to save

# before rebooting it’s important to test your fstab configuration

  1. $ sudo mount -a

# edit and check fstab configuration again if the command return an error

# reboot

  1. $ sudo reboot

# check your music library

  1. $ ls /mnt/media

Update MPD Database

# to update database use your favorite MPD client (MALP or DroidMyMPD or myMPD on your web browser) or open SSH session and type:

  1. $ mpc update

# that’s it!
# your music library is now on local disk

Tips

# to mount an exFat hard dive manually

  1. $ sudo mount -t exfat /dev/sda1 /mnt/media

# to unmount

  1. $ sudo umount -f /mnt/media