layout | title |
---|---|
post |
README for mpd-configure |
The mpd-configure
bash script creates a valid configuration file for
mpd, optimised for bit perfect playback of any digital audio file,
including those of high resolution.
With default settings the script uses the first available alsa audio
interface by using its hardware address (in the form of hw:x,y
), and
has automagic procedures for things like the music directory and
directory where files are stored, the number of items in the music
direcory and the UPNP name. When multiple audio interfaces are found,
the user is presented with a choice.
More information is available at the following pages:
The latest stable version of the script may be cloned from github using git
:
git clone https://github.com/ronalde/mpd-configure.git
Using git has the added benefit that updating the script to the latest version is as easy as:
## cd /path/to/git-clone
git pull
Alternatively, the tarball of the current stable
master can be downloaded and
unpacked in the current directory using wget
and tar
:
wget https://lacocina.nl/mpd-configure -O - | tar --strip-components=1 -zxf -
Run the script with default settings to display the contents of the resulting mpd configuration file:
bash mpd-configure
The output of the scripts can simply be redirected to a file (in this
example mympd.conf
):
bash mpd-configure > mympd.conf
Although the same may be achieved by using the -o
or --output
command line parameters or setting CONF_MPD_CONFFILE
on the command
line. This has the benefit that the script detects if the target file
exists, in which case the user is prompted to overwrite it, while
making an automated backup of the original file:
bash mpd-configure -o "mympd.conf"
# or:
CONF_MPD_CONFFILE="mympd.conf" ./mpd-configure
Additional setting are available using environment variables or using
the file ./mpd-configure.conf
and
configuration snippet files in the
./confs-available/
directory.
For example to specify CONF_MPD_MUSICDIR
which sets the
music_directory
and saving the resulting mpd configuration file in
mympd.conf
, use:
CONF_MPD_MUSICDIR="/srv/media/music" ./mpd-configure -o "/etc/mpd.conf"
By default mpd-configure
prompts the user to overwrite the specified
file if it exists, and makes a backup of it.
A fully automated example which does not prompt the user (-n
), uses the
first available USB Audio Class interface (-l u
) and sets some paths, while
creating a backup of the original /etc/mpd.conf
in case it exists:
CONF_MPD_MUSICDIR="/srv/media/music" CONF_MPD_HOMEDIR="/var/lib/mpd" \
bash mpd-configure -l u -n -o "/etc/mpd.conf"
To see all available command line options run the script with -h
or --help
:
bash mpd-configure -h
Also see
- Detailed usage instructions for more information on the usage and available settings.
- Usage a as systemd service
mpd-configure
relies on the accompanying bash
script alsa-capabilities
for getting
information about the available audio output interfaces from
alsa. However, alsa-capabilities
may be run from the commandline independently from mpd-configure
. It will then
display each alsa audio output interface with its capabilities, like
the type (ie. Analog, Digital or USB Audio Class) and the native
(digital) audio formats it supports, as well as other properties, like
it's character device (in /dev/snd
) and the file to watch or monitor
(in /proc/asound
).
The interfaces returned by the script may be reduced by setting
prefab or custom filters. These options can be displayed by running
the script with the -h
help option, eg:
bash alsa-capabilities -h
The script can also run 'directly' from github using:
bash <(wget -q -O - "https://lacocina.nl/alsa-capabilities")
To specify an option (like -l usb
) use the following syntax:
bash <(wget -q -O - "https://lacocina.nl/alsa-capabilities") -l usb
To display the alsa playback interfaces on a remote host to which you have ssh access, use:
ssh ${username}@${remotehost} "bash <(wget -q -O - "https://lacocina.nl/alsa-capabilities")"
Proper detection of the sample rates each format supports on an
interface currently is very slow for non-USB Audio cards. It therefore
is a non-default option, -s
or --samplerates
.
- It is recommended to mute all output interfaces because the script will play (pseudo) random noise on each interface.
Usage:
bash alsa-capabilities -s
The mpd-monitor script displays the way a digital audio file is streamed from storage (eg. a file), though MPD, to the (USB)DAC.
Usage:
bash <(wget -q -O - "https://lacocina.nl/mpd-monitor")
Or, when mpd is running on a remote host to which you have (key based) ssh access, execute:
bash <(wget -q -O - "https://lacocina.nl/mpd-monitor") -m $MPD_HOST -p $MPD_PORT -u $SSH_USER -d ${MUSICDIR}
For example:
bash <(wget -q -O - "https://lacocina.nl/mpd-monitor") -m mpd -u root -d /srv/media/music
- The mpd-monitor script is in a testing state.
I created this script to assist users in turning mpd in an audiophile digital music player. See the article How to turn Music Player Daemon (mpd) into an audiophile music player.
It does this by creating a proper formatted audio_output
configuration snippet for mpd's alsa audio output
plugin
using the sound cards hardware address and turning all options off
which might cause mpd to alter the incoming sound. For example:
## start processing `01_output-audio-alsa.conf'
audio_output {
type "alsa"
name "Peachtree 24/192 USB X - USB Audio"
device "hw:1,0"
auto_resample "no"
auto_format "no"
auto_channels "no"
}
replaygain "off"
mixer_type "none"
## done processing
After creating a mpd configuration file, mpd
can be told to use this
configuration file with:
mpd ./mpd.conf
To use the generated configuration file system wide, it can be copied
to the system wide mpd configuration file when you want to run mpd
as a system daemon:
sudo bash mpd-configure -o "/etc/mpd.conf"
sudo systemctl restart mpd
For debugging or testing purposes one may set the INCLUDE_COMMENTS
and/or DEBUG
parameters through the mpd-configure.conf
file or on
the command line, eg:
DEBUG="True" INCLUDE_COMMENTS="True" bash mpd-configure
In dynamic environments in which hardware may be altered each boot, connected to whatever USB DAC, the script could be put in a logon script or systemd service file.
The script is fast and stable enough to function as a systemd
service. By setting Before=mpd.service
and Wants=mpd.service
in
the service file systemd makes sure mpd-configure is run before mpd is started, and
tries to start mpd.
The bash script ./examples/bash-example.sh demonstrates the way alsa-capabilities can be used from another bash script.
This demo script returns the monitoring file of the file specified as an argument:
bash examples/bash-example.sh hw:1,0
Result:
the audio card with alsa hardware address hw:1,0 can be monitored with:
/proc/asound/card1/stream0
Assuming your in the mpd-configure
directory, run:
python examples/get-interfaces.py
The python script
./examples/get-interfaces.py
uses a helper bash script
(./examples/get-interfaces-for-python.sh),
which in turn sources alsa-capabilities
.
For my LTPS-environments the script directory can be copied to the
home directory of the auto logon user specified in
/var/lib/tftpboot/ltsp/i386/lts.conf
. It's ~/.profile
should be
edited to run the script and start mpd
using the script generated
~/.mpd/mpd.conf
, ie:
systemctl stop mpd && \
CONF_MPD_MUSICDIR="/srv/media/music" CONF_MPD_HOMEDIR="/var/lib/mpd" \
bash ~/mpd-configure/mpd-configure -l usb -n -q --nobackup -o "~/.mpd/mpd.conf" && \
systemctl start mpd
Preferences can be set in the file mpd-configure.conf
. By default all
preferences are commented out.
The script uses configuration file snippets in the
./confs-available/
directory. By symlinking
them to the ./confs-enabled/
directory, they will
be included by mpd-configure
in the resulting mpd configuration
file. Any bash variable in those configuration snippets, will be
expanded to their calculated values by the script.
DEBUG
Output values of variables and program flow to std_err for easier
debugging. Possible values:
- commented out: disabled (Default).
1
(or non-empty): enabled.
INCLUDE_COMMENTS
Include commented and empty lines from configuration snippet files in
the generated mpd configuration file:
- commentend out: disabled (Default).
1
(or non-empty): enabled
CONF_MPD_CONFFILE
Path to where the generated mpd configuration file will be
written. Possible values:
-
commented out: don't write to a file (Default). One may redirect the output of the script using:
bash mpd-configure > /path/to/mpd.conf
-
/path/to/mpd.conf
: use the path specified.
LIMIT_INTERFACE_TYPE
A keyword which limits the type of alsa interfaces to be returned:
Possible values:
usb
,digital
oranalog
- Comment it out (or leave it empty) to prevent filtering.
Default value:
- commented out (or empty ""): do not limit the interfaces that will be found.
LIMIT_INTERFACE_FILTER
The available output devices (after filtering with
LIMIT_INTERFACE_TYPE
when applicable) may be further limited using a
regular expression (which thus is case sensentive) which should match
the output of:
LANG=C aplay -l | grep ^card
If for example the output is like this:
card 0: MID [HDA Intel MID], device 0: HDMI 0 [HDMI 0]
card 1: receiv [Pink Faun USB 32/384 USB receiv], device 0: USB Audio [USB Audio]
... you could use one of the following values to match the second line
(which in this example matches the alsa hw:1,1
interface, eg. the
second interface of the second sound card):
"USB Audio"
"[uU][sS][bB] \w+ "
but not
"USB audio"
Possible values:
- empty or commented out: no filtering is applied
Some regular expression
: use the (first) interface which matches the regexp.
Default value:
- commented out (or empty ""): use the first available interface.
Handling of pulseaudio
OPT_DISABLE_PULSEAUDIO
Disable pulseaudio by modifyin the current users' ~/.pulseaudio/client.conf
Possible values:
- non-empty (
1
or "True") disables pulseaudio. - Comment it out (or leave it empty) to prevent disabling of pulseaudio.
Default value:
- commented out (or empty ""): do not disable it.
OPT_STOP_PULSEAUDIO
Temporary disable and stop pulseaudio during detection of alsa
interfaces. After the script pulseaudio's client configuration and run
state will restored.
Possible values:
- non-empty (
1
or "True") temporary disables and stops pulseaudio. - Comment it out (or leave it empty) to prevent temporary disabling and stopping of pulseaudio.
Default value:
- commented out (or empty ""): do not disable it.
See the configuration snippet files and accompanying README
in
./confs-available
for additional parameters and and explanation for
their functions.
MPD specific:
- How to turn Music Player Daemon (mpd) into an audiophile music player.
- What digital audio format does your USB DA-converter support and use?
- Music Player Daemon (MPD)
LTSP specific: