diyAudio logo

History of LINUX Audio MusicPlayerDaemon


Older Newer
Sun, 07 Dec 2008 20:00:03 . . . . (soundcheck)?


Changes by last author:

Added:
0.1 12/23/2008 soundcheck
0.2 03/05/2009 soundcheck Changelog: introduction of pipe output-plugin incl. examples for /brutefir/sox/ecasound , describing MPD internet (.pls) streaming setup
0.3 04/04/2009 soundcheck Changelog: .wav-tagging; nfs-mounts for Minion albumart access for .wav on network clients; enable "no" output option in /mpd.conf to mute new configured outputs on intial launch
0.4 04/18/2009 soundcheck Changelog: 1. Added "format" field to the pipe output config. It seems to be a must in the newest version. 2. change on ecasound format option
0.5 04/24/2009 soundcheck Changelog: Added setup instructions for 24/96 over pipe-out towards brutefir and ecasound
0.6 05/20/2009 soundcheck Changelog: Cleanup of output examples, Introduction of yet best SOX resample options, more detailed Minion setup, more detailed NFS setup
(used for albumarts over network), general cleanup.
0.7 05/21/2009 soundcheck Changelog: Introduced Example 7: output to Sox only and using its resampler, Example 4b: for realtimekernels - sox2ecasound 4496upsampling and ecasound in
realtime; pipe-out: general 32 bit transfer to resp. applications
0.8 07/17/2009 soundcheck Changelog: Cleanup and change of some dependencies for manual compilation

The music-player-daemon (MPD) is a great "daemonised" audio player. As the name suggests, it is truly working in the background, .
Thus it is also well suited for headless audio client PCs.

Due to it's No-Frills nature MPD sounds extremly well. The sound-quality is IMO better than Amarok, XMMS, Audacious, VLC -- you name it.

The daemon is started up during boot and waits for your commands.

One of the MPD key features I regard its client server architecture. You can access the daemon through different local and remote interfaces.
There is a huge number of different front-ends available.

My absolute preference is Minion written by Chris Seickel, because it is a Firefox Add-On and can be used on any Firefox capable client.

Within 5 minutes you can configure any Firefox client (PC,handheld,mobile...) in your network to play music on your audio PC.
IMO a very nice way to control your collection via (W-)LAN as intelligent remote control.

Example (How it could look like):

https://picasaweb.google.com/lh/photo/o2mqKbdjsCDQoPiPmBaP3w?feat=directlink


If you have more than one MPD daemon running in your network on different machines, you can control these with one Minion client.
You can easily build a system like the Sonos. Of course with more flexibility using your own equipment, soundcards and samplerates (e.g.24/192) and formats.... .


You are able to pair MPD with other audio engines. E.g. you could run brutefir (convolution engine) as a kind of "plugin" with MPD by using the
MPD pipe output plugin. You can do this of course with any other application such as SoX? or Ecasound which can read from STDIN (standard input/pipe).

MPD also supports .flac .mp3 m3u-playlists .pls-radio-streams asf. Any samplerates and 16/24/32 bitdepth are supported .

It also comes with the well performing libsample-rate support (145db SNR in Best Sinc mode) (Secret Rabbit Code)

Get yourself an idea about the endless features which come with the pairing/chaining of MPD with e.g. Sox, Ecasound, brutefir by reading the
respective man-pages. Entry level examples are given below. You just add whatever options you want.


Lets get started:

I hope below descriptions are readable and doable -- also for non Linux experts. Please report problems to https://www.diyaudio.com/forums/showthread.php?threadid=93315

I tested below under Ubuntu(Studio) Intrepid/Jaunty and Linux Mint 7 "Gloria":


Open a terminal (under Accessories):

Install the required packages first (don't type the dollar-sign):

$sudo apt-get install mpd gmpc mpc

Configurations:

$mkdir ~/.mpd
$mkdir ~/.mpd/playlist

The autostart and config-file location should be configured if automatic start during boot is that what you like.
Just uncomment (takes the hashes away) lines in the respective config file and fill in your mpd.conf path.

$ sudo gedit /etc/default/mpd

START_MPD=true
MPDCONF=/etc/mpd.conf

To start it manually or from a script you need to set:

START_MPD=false
MPDCONF=/etc/mpd.conf

save&exit


To manually start MPD, as soon as your config file is configured, type:

$ mpd

Optional: To start it with realtime priorities (on rt-kernels e.g. Ubuntu Studio) start with e.g.

$ chrt -f -p 80 mpd


NOTE: If "MPDCONF=/etc/mpd.conf" is not configured or a different config file shall be used you need to add the config-file option as argument: mpd /etc/mpd.conf


The configuraton file you're gonna prepare according to below. Change USER and YOURCARD and "music directory" variable according to your setup - your account-id (to find that one out type "whoami")
and choose just any name for your outputs/soundcards)

The outputs you need to configure according to your own setup.
I'll just list certain examples, which should help to understand how it is done in general. "man mpd.conf" will get you more information about the configuration options. (Note: If you install from git sources the man pages are usually not up2date)

Note: If you configure MPD autostart during boot, make sure that "USER" (insert your account id) is configured, otherwise you might end up with permission problems on certain MPD generated files. These become "root" and are not readable/writeable by normal users.

$sudo gedit /etc/mpd.conf

user "USER"

port "6600"


music_directory "/home/USER/music"
playlist_directory "/home/USER/.mpd/playlist"
db_file "/home/USER/.mpd/tag_cache"
log_file "/home/USER/.mpd/mpd.log"
error_file "/home/USER/.mpd/errors.log"
pid_file "/home/USER/.mpd/pid"


audio_output {
type "alsa"
name "YOURCARD1-HW-analog-4416" # choose your own identifier. This will show up in the MPD-GUI
device "plughw:0,0" # optional the setting obvioulsy depends on the used interface and soundcard instead of plughw you might use use hw
format "44100:16:2" # optional - stream will be sampled to this format
auto_resample "no" # this is ALSA telling not to touch the stream
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}

###########BELOW examples are optional

audio_output {
type "alsa"
name "YOURCARD2-PLUGHW-digital-4416"
device "plughw:1,1" # optional the setting obvioulsy depends on the used interface and soundcard instead of hw usually plughw
format "44100:16:2" # optional - stream will be resampled by MPD & libsamplerate to listed format
auto_resample "no" # this is ALSA telling not to touch the stream
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}


audio_output {
type "alsa"
name "YOURCARD2-PLUGHW-analog-2496"
device "plughw:1,0" # optional the setting obvioulsy depends on the used interface and soundcard instead of hw usually plughw
format "96000:24:2" # optional - stream will be resampled by MPD & libsamplerate to listed format
auto_resample "no" # this is ALSA telling not to touch the stream
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}

samplerate_converter "0" # optional this is the setting for libsamplerate . Secret Rabit Code - Best Sinc=0 - put a hash in front of the line to deactivate it.


Below I'd like to introduce a great feature: "output to pipe" or in Linux terms STDOUT.

The pipe plugin has been introduced with MPD revision 0.15.

You still need to install MPD from sources (described further down) until 0.15 gets officially introduced by Ubuntu.


Below some examples how to configure it:


Example 1: Output to brutefir
Straight 44/16 transfer (works also if set to 32 bit under "format" and brutefir-conf )

audio_output {
type "pipe"
name "pipe-brutefir-4416"
format "44100:16:2"
command "brutefir -nodefault /path-to-yourconf/brut/brutconf4416-pipe 2>/dev/null"
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}


Example 2: Output to Sox and further to brutefir.
MPD internal 32 bit processing will be kept.
Selected is the optimum Sox sample rate conversion setting

audio_output {
type "pipe"
name "pipe-sox2brut-plughw0-9624up"
format "44100:32:2"
command "sox -traw -esi -b32 -c2 -r44100 - -t raw -e si -b32 -c2 - rate -s -v -I -a 96000 | brutefir -nodefault /path-to-yourconf/brut/brutconf9624-pipe 2>/dev/null"
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}

-------------------------------------------
NOTE::::
Brutefir config-file example:

In-& Output:
device: "file" {path: "/dev/stdin"; };
sample: "S32_LE"; # sample format
-------------------------------------------


Example 3: Output to ecasound
Straight 44/16 (works also if set to 32 bit under "format" and ecasound command )


audio_output {
type "pipe"
name "pipe-eca-plughw0-4416"
format "44100:16:2"
command "ecasound -q -f:s16_le,2,44100,i -b 256 -i:stdin -o:alsaplugin,0,0 2>/dev/null
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}

Example 4: Output to Sox upsampling to 96khz and playback with ecasound

audio_output {
type "pipe"
name "pipe-sox2eca-plughw0-4496up"
format "44100:16:2"
command "sox -t raw -e si -b16 -c2 -r44100 - -t raw -e si -b32 -c2 - rate -s -v -I -a 96000 | ecasound -q -b:64 -f:s32_le,2,96000,i -i:stdin -o:alsaplugin,0,0 2>/dev/null"
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}

Example 4b: For systems with realtimekernel: Output to Sox upsampling to 96khz and playback with ecasound in realtime mode

audio_output {
type "pipe"
name "pipe-sox2eca-plughw0-4496up"
format "44100:16:2"
command "sox -t raw -e si -b16 -c2 -r44100 - -t raw -e si -b32 -c2 - rate -s -v -I -a 96000 | ecasound -q -B:rt -r:80 -b:32 -f:s32_le,2,96000,i -i:stdin -o:alsaplugin,0,0 2>/dev/null"
enable "no" # this disables this output at inital system start, as soon as configurations are done MPD remembers the current settings
}


Example 5: Output of 24/96 material over pipe to ecasound

MPD outputs S24_LE or S32_LE data. Usually 24/96 basematerial is coded as S24_3LE (plain 3 bytes).
To get ecasound and brutefir properly connected to the pipe output it needs to be configured S32_LE for 24bit data.


audio_output {
type "pipe"
name "pipe-eca-plughw0-2496"
format "96000:32:2"
command "ecasound -q -f:s32_le,2,96000,i -b:64 -i:stdin -o:alsaplugin,0,0 2>/dev/null
enable "no"
}

Example 6: Output of 24/96 material over pipe to brutefir


MPD config:

audio_output {
type "pipe"
name "bipe-brut-plughw0-2496"
format "96000:32:2"
command "brutefir -nodefault /path-to-yourconf/brut/<brutconf2496-pipe> 2>/dev/null"
enable "no"
}

-------------------------------------------
NOTE::::
Brutefir config-file example:

In-& Output:
device: "file" {path: "/dev/stdin"; };
sample: "S32_LE"; # sample format
-------------------------------------------


Example 7: Output of Sox, upsampling 44.1 to 96khz

audio_output {
type "pipe"
name "pipe-sox-plughw0-src4496up"
format "44100:32:2"
command "sox -traw -esi -b32 -c2 -r44100 - -talsa -esi -b24 -c2 plughw:0,0 rate -s -v -I -a 96000 2>/dev/null"
enable "no"
}


Save&exit

NOTE: The new 0.15-git version allows to disable the outputs at startup (not yet documented). To avoid that multiple outputs are routed to the same device, just add -- enable "no" -- as option to
each of your outputs. Your default output you set to enable "yes" . You can change the setup as soon as soon as MPD is up'n running.


NOTE: The first thing you do. Check the output assignments as soon as the application is started. Make sure that you deactivate the outputs with MPC or Minion which are not needed!!!


To generally check if MPD is running after reboot, type:

$ ps -edf | grep mpd


Restart and regenerate database, in case you've applied changes to your collection/directories

$ killall mpd
$ sudo /usr/bin/mpd --create-db /etc/mpd.conf

or

$sudo invoke-rc.d mpd force-restart


Now, let's get Minion installed:

Search for "Minion" in the add-on database or look it up here:

https://addons.mozilla.org/en-US/firefox/addon/6324

You can also load the latest "unstable" revision (what I strongly recommend, since it is pretty reliable) of Minion here: https://code.google.com/p/musicpm/

Download the .xpi file on the right hand side (e.g. 1.99.25) save it to disk. Then open it with Firefox using "open file".
It'll be automatically installed. Remove the old one.

Now you'll find in the lower right corner of the Firefox frame a yellow button "Launch Music Player Minion". Here you can launch the player Window.
The button right beside that yellow button is the settings button.

NOTE: The settings button shows "RED" if Minion is not connected to the mpd daemon. It switches to "GREEN" if you are connected.

Minion Networking setup:

Under "Settings/ManageServers?" you now need to fill in the IP address of your MPD-audioserver. Minion needs to know where to connect.

There are 3 fields of interest:

Server Description: This string will show up in the Minion Menu. Choose whatever you like.
Host: Here you enter the ip address or the hostname of the mpd-server. (Note: "hostname" only works if it is mapped in /etc/hosts on your local machine, see NFS setup below)
If you are situated on your server "localhost" can stay as it is.
Port: Stays the way it is - 6600. It can be changed if you choose a different port in your mpd.conf file.

You just add another server if you want to control different servers or daemons. This way you can control quite easily multiple servers (e.g. living room/kitchen/bedroom in the house)


Run $ifconfig to find out about your local IP address. This address you need to have to fill in on the remote host.

NOTE: On DHCP networks, the IP address for a client gets assiged randomnly. This won't be much of a problem if you always use the same clients and keep the same boot order.
However, if you start connecting different clients, you'll face problems in your setup later on. Your IP adresses get shuffeld around. This will cause problems with your MPD setup.
(But similar problems you'll face with network printers, NAS etc.)
The only way around this is to make your IP adresses permanent for at least your servers. I'll explain how to do it in the Network Wiki later on.


Minion Albumarts:

You can also make use of albumarts for .wav-files in Minion. An albumart-file called "folder.jpg" must exist in each and every album folder.
In the Minion settings under "general/custom albumart" you just tick "Use custom album cover" and enter

file:///path/to/music_dir/{Path}/folder.jpg

(3 slashes are correct!!!!)

Of course you need to replace /path/to/music_dir with the full path to your own music directory respetively your mounted directory on the client.

If you want to have the albumarts shown on all clients, you need to mount the music-directory over the network.

That's a piece of cake:


Some generic and also important network setup instructions:

Install following packages: sudo apt-get install nfs-common nfs-kernel-server samba samba-common smbfs

On the MPD server:

1. Map IP address and hostname on your server

Lookup your local IP address: Type $ifconfig -- lookup the "inet addr:"-field
Lookup you local hostname: $hostname

Now you have to enter these values at the bottom of a file called /etc/hosts

sudo gedit /etc/hosts

192.xxx.x.xxx <yourserverhostname>

save&exit


2. Now we need to grant permission to the client to mount the particular music-data directory via NFS

sudo gedit /etc/exports

/<your>/<musicdir>/ <yourclienthostname>(rw,no_subtree_check,async,all_squash)

save&exit


3. Reboot the server to activate all network related settings properly.


On the client:

sudo apt-get install nfs-common nfs-kernel-server samba samba-common smbfs

1. Map IP address and hostname on your client

Checkout your local IP address. Type:

$ifconfig

(lookup the "inet addr:"-field)

Lookup you local hostname. Type:

$hostname

Now you have to enter these values at the bottom of /etc/hosts

sudo gedit /etc/hosts

192.xxx.x.xxx <yourclienthostname>

save&exit

2. Now we need to generate a mountpoint. Here we can mount the music directory of our server.

e.g.

sudo mkdir /media/music

3. Finally we need to edit the /etc/fstab to mount the drive at system boot.

Put below line at the bottom of the file.

sudo gedit /etc/fstab


<yourserverhostname>:/<your>/<musicdir>/ /media/music nfs rw,hard,intr 0 0


save&exit

Reboot the systems and configure the AlbumartPath? in Minion on your client:


NOTE: With above NFS network mount setup you'll also have access to your collection (through /media/music) on the client now. You can play your file with any other application locally.


MPC:

Mpc is "the" MPD command line player. If you have followed the instructions it is installed already.

type $ man mpc for directions

try just some easy commands:

mpc playlists
mpc load <a playlist as shown in above command output>
mpc play
mpc stop

of course you can use at the same time Minion. Load the playlist with Minion and control it with MPC works great.

The flexibility you get is just great.


You should also have a look at the offivcal MPD Wiki: https://wiki.ubuntuusers.de/MPD.
The forum is a good place for getting support https://www.musicpd.org/forum/

There are endless scripts and frontends available. I guess you'll like it.


Installing from sources

Installing MPD from sources shouldn't be a huge challenge, even for beginners. And I really recommend this. (E.g 0.15-git supported 24bit at least half a year earlier then the official MPD release, or
as described above the pipe function as introduced with 0.15-git. Within Ubuntu you might see this end of 2009.)

Install dependencies first ( I am not really sure if this is complete for now!?!?)

See over here: https://mpd.wikia.com/wiki/Dependencies

you can do it with:

sudo apt-get build-dep mpd

or
sudo apt-get install -y git-core git automake build-essential
sudo apt-get install -y linux-headers-$(uname -r) libasound2 libasound2-dev libpulse-dev libshout3-dev libspeex-dev libjack0.100.0-dev libbio2jack0-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libavutil-dev libmp4v2-dev libmpeg4ip-dev liba52-0.7.4-dev libmad0-dev libaudio-dev
sudo apt-get install -y libglib2.0-dev libogg-dev libfaac-dev libfaad-dev libflac-dev libflac++-dev libaudiofile-dev zlib1g-dev libsamplerate0
sudo apt-get install -y libmp3lame-dev libid3tag0-dev libmpcdec-dev libmms-dev libcurl4-gnutls-dev libmikmod2-dev libao-dev libao libsamplerate0-dev

Now we'll get the sources:

cd /usr/src
sudo git clone git://git.musicpd.org/master/mpd.git

NOTE: To update the package frequently you can just run "cd /usr/src/mpd && sudo make clean && sudo git pull" at this point. You can skip "the sudo git clone...."

Configuration:

cd /usr/src/mpd
sudo ./autogen.sh --prefix=/usr --enable-pipe-output # check in the output if all your features are configured, otherwise you need to install corresponding libraries

NOTE: By running "./autogen.sh --help" you'll see all compile options.

Compilation:

sudo make
sudo make install


That's about it. Your old binary and files are now overwritten. Now you can start MPD as described above.


MPD RAMDISK PLAYBACK

MPD is not supporting full file buffering or playback from RAMDISK. With an easy workaround you can achieve ramdisk playback.

1. Initial setup:

cd <your-musicdir> # this is the music directory as defined in /etc/mpd.conf
ln -s /dev/shm AAA # AAA will later on show up as album folder, choose whatever name you like, I've chosen AAA-RAMDISK because it'll be always first in the list
mpd --create-db /etc/mpd.conf # introduce AAA to the mpd database NOTE: This can take a long time. You can keep track of the progress if you run a "tail -f <your-mpd.log-file>" on your MPD logfile.

Lets talk about basic playback (assuming MPD is running already):

rm -f /dev/shm/*wav # clear ram
cp <your-musicdir>/<album>/*wav /dev/shm # copy all tracks to RAM
mpc update AAA # update the mpd - database with new RAMDISK content
mpc clear # clear old playist
mpc ls AAA | mpc add # add new files to playlist

Above can easily be used to generate a shell script - PM me if you want the one I am using.


MPD - PLAYBACK OF INTERNET RADIO STREAMS (MPD rev. 0.15 recommended for proper tagging)

Example:

Initial:

touch /your/mpd-base-dir/playlists/<your-radio-playlist>.m3u
chmod 666 !$
echo "https://<your-url>" > /your/mpd-base-dir/playlists/<your-radio-playlist>.m3u #choose whatever playlist name you like
mpc update # load the new playlist to the database


Examples (Note: Below links change from time to time, they might not work.):

Radio-AmbientChill?-Groove_Salad-128.m3u
https://scfire-dtc-aa03.stream.aol.com:80/stream/1018

Radio-Country-181FM_KickinCountry?-128.m3u
https://scfire-dtc-aa01.stream.aol.com:80/stream/1075

Radio-Country-1FM_AbsoluteCountry?-128.m3u
https://scfire-dtc-aa04.stream.aol.com:80/stream/1019

Radio-Country-Got_County_Top_4-128.m3u
https://64.62.164.208:2082

Radio-Jazz-181FM_TheBreeze?-128.m3u
http:/216.155.137.149:8004

Radio-Jazz-1FM_Bay_Smooth_Jazz-128.m3u
http:/66.220.3.50:9010

Radio-Jazz-Smooth_Jazz_Cafe-192.m3u
https://72.8.159.118:8004


Operation:

Use Minion or

mpc clear # delete the current playlist
cat /your/mpd-base-dir/playlists/radio-Got_Radio-New-Country.m3u | mpc add # add radio stream to current playlist
mpc play
mpc # will show you the stream/title/artist details


That'll be it. You can also select the playlist via your prefered GUI the same way as you handle all other playlists.


WAV-Tagging:

A great unique new feature recently has been introduced to Minion with rev. 1.99.24. Now it is possible to enjoy tagging for the .wav-format.
Chris called it "tag-guess-feature". Minion is looking at filenames and tries to extract the respective tag-fields out of it.

It looks for

<Tracknumber>-<Artist>-<Album>-<Tracktitle>.wav


If you have your filenames structured like that (I do), you will enjoy a nice .wav-tagging.

You might end up in reshuffling and/or cleaning up your tags. At least I did. And this is gonna be a hell lot of work.

The key "guess" indicator is the field separator. It is assumed to be a "dash".

Minion's field separation logic:

The first field will always be the Track-Number, the 2nd field will always be the Track-Artist, and the last field will always be the Track-Title.
Everything in between must be "Album".


For the time being you need to configure a special key in Firefox to enable the feature.

1. Open Firefox and type "about:config" in the address field .
2. Right click in the main window-field- select: "new""boolean"
3. add "extensions.mpm.guess_tags"
4. set to true
5. Restart FF


WIKI END----------------------------------------------