Technology
 

Configuration

From Music Player Daemon Community Wiki

Contents


[edit] Initial Configuration

After installation, MPD won't work until you tell it where the media files are. You do that by changing the ~/.mpdconf file (for individual users) or /etc/mpd.conf for system-wide MPD. You may want to start with this:

port			"6600"
music_directory         "~/music"
playlist_directory      "~/.mpd/playlists"
db_file                 "~/.mpd/mpd.db"
log_file                "~/.mpd/mpd.log"

you will need to create the directories if they do not already exist. eg:

mkdir -p ~/.mpd/playlists

For those using linux, if you have a samba server with all your music, say that its share name is ALBUMS, and you mount it locally as /mnt/albums. Then have your db_file option to point at such place, i.e. /mnt/albums. This way, when you don't have the ALBUMS share mounted on your computer you will have your mpddb file with LOCAL files (note that the mount destination should be ~music as well), whereas when you have it mounted you will have your mpddb file with all your music. Note that this will not require creating mpddb files each and every time (just need to run /etc/init.d/mpd restart)

[edit] Audio Outputs

[edit] IceCast

MPD can stream to an IceCast (or other ShoutCast compatible) server. The following instructions assume that you have your IceCast server working and setup correctly. First grab the latest version of MPD from svn. (Note: version 0.11.5 and earlier, does not support streaming to a ShoutCast server! Check your install by running /usr/bin/mpd --version to see if shout is listed as an output format).

Sidenote: Since MPD 0.15 there is a built-in alternative to using IceCast. See below for more information.

[edit] Installation

You install it by using:

./autogen.sh --prefix=/path/to/dir
make
make install (this command may need root priveleges depending on the prefix chosen)

Once you have mpd installed from svn, you just have to edit your MPD config file (the default is at /etc/mpd.conf), or in the prefix that you chose during installation. Make sure that you have something like the following section in your config file:

################# SHOUT STREAMING ########################
#
# Set this to allow mpd to stream its output to icecast2
# (i.e. mpd is a icecast2 source)
#
audio_output {
        type              "shout"
        name              "my cool stream"
        host              "localhost"
        port              "8000"
        mount             "/mpd.ogg"
        password          "IceCast_mpd"
        quality           "5.0"   
#       bitrate           "64"
        format            "44100:16:1"

# Optional Parameters
       user            "source"
#       encoding        "mp3" # ogg by default
#       description     "here's my long description"
#       genre           "jazz"
} # end of audio_output
##########################################################

The lines above that start with a "#" are comment lines. The other lines have the following meaning:

  • type "shout" indicates that this output is to be streamed to a ShoutCast server.
  • name "my cool stream" sets the title of the stream, that your listeners will see.
  • host "localhost" is the hostname of the Shoutcast server. If the server does not run on the same machine as MPD, change this accordingly.
  • port "8000" is the port number on the server that MPD should connect to.
  • mount "/mpd.ogg" is the path from the server root where your stream will be broadcast. In this example, the URL of the stream will be http://localhost:8000/mpd.ogg.
  • password "IceCast_mpd" is the password used to broadcast on the server. Change this to the password required by your IceCast server.
  • quality "5.0" OR bitrate "64" set the quality of your stream. You can (and must) only set one of them. quality is for variable bitrate Ogg/Vorbis, and bitrate for constant bitrate. Quality 3 is the default for oggenc and sounds little better than a mp3 at 128 kbits.
  • format "44100:16:1" is the audio format of the stream. The first number is the sample rate in Hertz (Hz); 44100 Hz is equal to cd quality. The second number is the number of bits per sample; again 16 bits is the quality used on cd's. The third number is the number of channels; 1 channel is mono, 2 channels is stereo.
  • Will x:x:1 mix both channels or just use one of the channels?
  • user "source", description "here's my long description" and genre "jazz" set some metadata that will be added to the headers of your stream and can be viewed by listeners.
  • Add protocol parameter to change streaming protocol from icecast2 to "shoutcast" or "icecast1"

[edit] Supported Output Formats

Currently only OggVorbis is supported in mainline; MP3 is supported from version 0.14, with the optional parameter "encoding".

[edit] See also

Wikipage on Icecast2 configuration

Jonathan Fors' guide on MPD/Icecast streaming

FreeBSD MPD/Icecast setup

[edit] Built-in HTTP streaming

Since version 0.15 there is a built-in HTTP streaming deamon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:

audio_output {    
	type		"httpd"    
	name		"My HTTP Stream"    
	encoder		"vorbis"		# optional, vorbis or lame    
	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"    
}

Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example in my case, using Winamp 5.5, I had to use http://192.168.178.5:8000/mpd.ogg rather than http://192.168.178.5:8000/.

Sidenote: In my (subjective) experience it seems that the CPU usage is much lower when using the built-in http streaming server than when using IceCast. And since I use MPD 24/7 this actually makes a difference.

[edit] Built-in HTTP streaming part 2: Use mpd to connect to the stream

MPD can both output and play streams:

You can have one mpd session on the server stream your music to another mpd session where you want to output the sound (client).

For example, your desktop computer at the opposite end of the room has fast, reliable and big hard disks with lots of excellent music whilst your laptop beside you has one slower, prone to overheating and smaller hard disk with less or no good music.


Here's how:

1. Setup a mpd session on the server to stream the output. This is done by editing the mpd.conf file (see above in part 1)
2. Restart mpd and there will be an output that steams your music on the specified port (default: 8000)
3. On the client (mpd or any other client that plays streams IE- VLC etc,,) add http://IP:PORT to the playlist.
For example, to use the mpd command line utility "mpc" to add a remote mpd stream from "192.169.0.1" on port "8000" to your local mpd playlist use the following command in a terminal:
mpc add http://192.169.0.1:8000
4. To play songs with your client computer from your remote mpd session (server) you must either use a mpd client (such as "gmpc") or connect via ssh and fill your playlist from there.
For a remote session to work in any mpd client that can't use a preconfigured ssh you must allow the client to connect to the configured control port on your remote mpd instance (default: 6600) by disabling or configuring any firewalls between them.

Troubleshooting:

If you have mpd and mpc installed on the client and can't get it to play the remote stream, create an executable shell script called something like "plaympd.sh" on the client computer with the following contents and run it from a terminal:
sudo /etc/init.d/mpd start  # start mpd
sudo /etc/init.d/mpd stop   # stop mpd
sleep 3                     # wait 3 seconds in case mpd automatically resumes playing the previous playlist
echo "Are you hearing what you expected to yet? [n=no / *=yes]"
read RSPN                   # allow user to input response
if [ "$RSPN" == "n" ]; then # only perform the following operations if there are still problems 
	mpc stop            # use mpc to stop mpd playing anything
	mpc clear           # use mpc to clear the mpd playlist
	mpc add http://192.169.0.1:8000 # use mpc to add remote stream to playlist
	mpc play            # use mpc to play the playlist
	echo "Hit enter to close."
	read RSPN           # wait for user to view any messages before exiting
fi
Replace "192.169.0.1:8000" with the "IP:PORT" combination of your remote mpd instance.
Replace "sudo" with "gksudo" if you would prefer to execute the script directly from within the Gnome Desktop.

[edit] PulseAudio

See the PulseAudio HOWTO.

[edit] JACK

[edit] libao / JACK

Check out the instructions at the alsa-project.org website on how to set up an ALSA device that forwards to JACK, then simply set this device as your output device in mpd.conf. Actually it seems to work only for the "ao" output type using the "alsa09" driver:

audio_output {    
    type        "ao"    
    driver      "alsa09"    
    options     "dev=devicename" # replace devicename with that of your .asoundrc without the leading 'pcm.'    
                                 # (i.e. "dev=jackplug", when you set up pcm.jackplug in your .asoundrc)    
    name        "Jack Output"    
}

[edit] native / JACK

Here is how to use jack in more recent versions of mpd:

audio_output {       
       type    "jack"       
       name    "my jack device"     
}

[edit] Enlightened Sound Daemon / EsounD / ESD

The Enlightened Sound Daemon, or ESD, intercepts and mixes digital audio streams before passing them to /dev/dsp, thereby letting multiple sound sources have simultaneous access to the sound hardware. MPD relies on libao, the cross-platform audio library, and, happily for ESD users, libao supports ESD.

Configuration to let libao, ESD, and MPD work together can be done in either of two ways. The libao configuration file, /etc/libao.conf, sets the default libao sound driver, using the syntax default_driver=x, where x is an available driver. As of version 0.8.5, the drivers are oss, esd, arts, alsa, alsa09, nas, irix, and sun. Setting a system-wide libao default with default_driver=esd should do the trick. Alternatively, the MPD configuration file /etc/mpd.conf can also specify the libao ESD driver as follows: driver "esd". This overrides the libao default and works equally well.

If you want to play your music on another host (perhaps becuase the computer with the speakers doesn't have enough hard drive space for your music), this seems to work:

audio_output {
        type      "ao"
        driver    "esd"
        options   "host=jurp5-desktop:16001" 
        name      "esd"
}

[edit] Permissions Problems

Testing on a Debian GNU/Linux (unstable) system revealed permission problems when ESD version 0.2.35 is used with a standard Debian configuration of MPD version 0.11.5.

First issue: the mpd user does not have the right to execute a shell. Change this by executing (as root):

  # chsh -s /bin/true mpd

Second issue: if you want to be able to connect to spawned esd with other applications, you'll need to add in /etc/esound/esd.conf:

spawn_options=-tcp -public -terminate -nobeeps -as 5

These also can be overcome by changing settings in /etc/mpd.conf so as to relocate MPD's log, state, and database files from /var to a normal user directory, and by changing the default MPD user accordingly. For example, for user dwrob:

# required
playlist_directory "/mnt/peedee/MP3/Playlists"
music_directory    "/mnt/peedee/MP3/Music"
port               "6600"
# log_file         "/var/log/mpd/mpd.log"
log_file           "/home/dwrob/.mpd/mpd.log"
# error_file       "/var/log/mpd/errors.log"
error_file         "/home/dwrob/.mpd/errors.log"

# optional, but HIGHLY RECOMMENDED
#db_file           "/var/lib/mpd/mpddb"
db_file            "/home/dwrob/.mpd/mpddb"

# user             "mpd"
user               "dwrob"

# optional, but recommended
# state_file       "/var/lib/mpd/state"
state_file         "/home/dwrob/.mpd/state"

[edit] ESD not working in Ubuntu

If the ESD output doesn't work in Ubuntu, you might try setting the following lines in /etc/esound/esd.conf:

auto_spawn=1
spawn_options=-noterminate -nobeeps -as 5

[edit] ALSA dmix Output

There's a couple of different configuration options here. The easiest is to edit mpd.conf as follows:

audio_output {
        type                    "alsa"
        name                    "Sound Card"
        options                 "dev=dmixer"
        device                  "plug:dmixer"
}

An additional option is as follows: When you want to allow users to dmix their played sounds to mpd output sound if you run mpd from init scripts you need either to configure ALSA dmix plugin, either don't forget to set the ipc_* stuff well, because without it only root would be able to dmix other sounds.

Sample /etc/asound.conf configuration:

pcm.dmixer { 
    type dmix 
    ipc_key 1024
    ipc_key_add_uid false
    ipc_perm 0666			# mixing for all users
    slave { 
        pcm "hw:0,0" 
        period_time 0 
        period_size 1024 
        buffer_size 8192
        rate 44100
    }
    bindings { 
        0 0 
        1 1 
    } 
} 

pcm.dsp0 { 
    type plug 
    slave.pcm "dmixer" 
} 

pcm.!default { 
    type plug 
    slave.pcm "dmixer" 
} 

pcm.default { 
   type plug 
   slave.pcm "dmixer" 
} 

ctl.mixer0 { 
    type hw 
    card 0 
}

[edit] ALSA MPD software volume control

The following is what is needed to get a working software volume control that can be controlled by alsamixer, as well as the mpd volume control. This allows mpd to be lowered in volume, but not the other sounds on your system (or vice-versa)

An alternative to this ALSA configuration would be to simply add the following to /etc/mpd.conf and restart mpd:

mixer_type "software"

[edit] Create asound.conf

First, the following lines are required in /etc/asound.conf. Note the software mixer mpdvol with the name "MPD". This will be used when editing the /etc/mpd.conf file. The software mixer "softvol" controls the level of the other sounds on your computer, and has the generic name of "Software".

# the sound card
pcm.real {
  type hw
  card 0
  device 0
}

# the ipc stuff is needed for permissions, etc.
pcm.dmixer {
  type dmix
  ipc_key 1024
  ipc_perm 0666
  slave.pcm "real"
  slave {
    period_time 0
    period_size 1024
    buffer_size 8192
    rate 44100  
  }
  bindings {
    0 0
    1 1 
  }
}

ctl.dmixer {
  type hw
  card 0
  }

# software volume
pcm.softvol {
  type softvol
  slave.pcm "dmixer"
  control {
    name "Software"
    card 0
  }
}
# mpd volume control
pcm.mpdvol {
  type softvol
  slave.pcm "dmixer"
  control {
    name "MPD"
    card 0
  }
}
# ctrl for mpd volume
ctl.mpdvol {
  type hw
  card 0
}

# input
pcm.input {
        type dsnoop
        ipc_key 3129398
        ipc_key_add_uid false
        ipc_perm 0660
        slave.pcm "810"
}

# duplex device
pcm.duplex {
        type asym
        playback.pcm "softvol"
        capture.pcm "input"
}

# default devices
pcm.!default {
  type plug
  slave.pcm "duplex"
}

# for oss devices
pcm.dsp0 {
  type plug
  slave.pcm "duplex"
}

[edit] Edit mpd.conf

Next, the following lines need to be edited in /etc/mpd.conf:

The device line in the audio_output below should be set to the device name for the mpd volume that was specified above in the asound.conf file. Note that the mixer_device line uses the same device as the device line in the audio_output section, but that the mixer_control line should be set to the NAME that was given in asound.conf.

audio_output {
        type                    "alsa"
        name                    "Alsa Software Volume"
	device			"mpdvol"
}

and

mixer_type                      "alsa"
mixer_device                    "mpdvol"
mixer_control                   "MPD"


You will need to restart the mpd daemon before these settings to work. If they aren't working, you may try rebooting your system. You should see a listing for the volume for MPD using gnome-alsamixer or alsamixer. You can also control the volume setting using any other client for mpd (mpc, ncmpc, gmpc, sonata, etc.). It doesn't affect the other sounds on your system!

[edit] ALSA select digital audio out

Example to select the digital audio output (not the (default?) analog out):

.asoundrc (usually already present in home directory). This example is for a nforce3 board. Settings for other chip sets will vary, see Alsa-Project for more examples.

pcm.intel8x0 {
   type hw
   card 0
}
 
pcm.!default {
   type plug
   slave.pcm "spdif"
   slave.rate 48000
}

ctl.intel8x0 {
   type hw
   card 0
}

Now the corresponding entry in mpd.conf. The device name must match the slave.pcm name in the .asoundrc file:

audio_output {
        type                    "alsa"
        name                    "My ALSA Device"
        device                  "spdif"
}

May this save somebody some time...


Another example, how to activate the 2nd device on the first audio hardware: Hercules Fortissimo IV ice1724 with kernel 2.6.26 and Alsa 1.0.17: .asoundrc:

pcm.ice1724 {
    type hw
    card 0
}

pcm.!iec958 {
    type plug
    slave.pcm "hw:0,1"
}

pcm.!default {
    type plug
    slave.pcm "hw:0,1"
}

ctl.ice1724 {
    type hw
    card 0
}

Now the corresponding entry in mpd.conf. The 'plughw' did the trick, it matches the "hw:0,1" entry from the Alsa .asoundrc file !

audio_output {
        type                    "alsa"
        name                    "My ALSA Device"
        device                  "plughw:0,1"
}

[edit] ALSA select digital audio out (bit-perfect)

The examples above might produce bit-perfect output, however I've tested the example below and can confirm that it works with a CMI 8768 card. I've successfully played 96KHz FLAC with mpd using this configuration.

In /etc/mpd.conf:

audio_output {
        type                    "alsa"
        name                    "SPDIF"
        device                  "cards.pcm.iec958"
}

For an explanation of bit-perfect audio, go here: http://www.mythtv.org/wiki/index.php/Bit_Perfect_Digital_Audio_Playback

[edit] OSS

This seems to work:

audio_output {
        type      "ao"
        driver    "oss"
        options   "" 
        name      "oss"
}

[edit] FIFO Output

The fifo plugin writes raw PCM data to a FIFO (First In, First Out) file.  The data can be read by another program. Available from mpd 0.14. Example config:

audio_output {
        type                    "fifo"
        name                    "My FIFO"
        path                    "/tmp/mpd.fifo"
}

[edit] Generic Decoder Support

Later versions of mpd may support Generic Decoders to decode files and streams.