Skip to content

08. Further optimisation & options

guussie edited this page May 7, 2017 · 17 revisions

Advanced MPD setting

Check mpd version:

sudo mpd -V

Recommended changes to the mpd.conf file in /etc directory Comment out the state_file to disable the resuming of last state when mpd starts up

#state_file "/var/lib/mpd/state"

Set the bind_to_address to be any, to enable you to connect external mpd clients

bind_to_address "any"

Set the Audio Output

audio_output {  
    type        "alsa"  
    name        "My ALSA Device"  
    device      "hw:0,0"    # optional  
    #format      "44100:16:2"    # optional  
    #mixer_device   "default"   # optional  
    #mixer_control  "PCM"       # optional  
    #mixer_index    "0"     # optional  
}

If you are using a USB DAC that does not support hardware volume control you can try enabling software volume control

mixer_type "software"

If you are feeling adventurous you can try compiling the latest version of mpd:

Install MPD and MPC (Client)

sudo apt-get install mpd mpc

Install the pre-requirements

sudo apt-get install aptitude wget binutils gcc make subversion autoconf automake autotools-dev libtool pkg-config build-essential libncurses5-dev libncursesw5-dev gcc libglib2.0-dev

sudo apt-get install libfaad2 libfaad-dev libflac8 libflac-dev libogg0 libogg-dev libvorbis0a libvorbis-dev libid3tag0 libid3tag0-dev libmad0 libmad0-dev libcue-dev libcue1 libasound2 libasound-dev libasound2-dev libao-dev libwavpack-dev libwavpack1 libsamplerate0 libsamplerate-dev libmikmod2-dev libmikmod2 libmikmod-dev libshout-dev libavformat-dev libavcodec-dev libavutil-dev libaudiofile-dev libcurl4-openssl-dev libmms-dev libmms0 libtwolame-dev libtwolame0 libmp3lame-dev git-core libboost1.46-all  

sudo su

cd /home/pi

Get the latest version from http://www.musicpd.org/download/mpd/stable/

Like this

wget http://www.musicpd.org/download/mpd/stable/mpd-0.19.2.tar.gz

And then extract the files

tar -zxvf <name>.tar.gz

Then

cd mpd-0.19.2

./autogen.sh

Configure some options

./configure --disable-bzip2 --disable-iso9660 --disable-zzip --enable-id3 --disable-sqlite --enable-ffmpeg --enable-alsa --disable-wave-encoder --enable-pipe-output --enable-httpd-output --disable-recorder-output --disable-sndfile --enable-oss --enable-shout --disable-pulse --disable-ao --enable-mad --disable-inotify --disable-ipv6 --enable-curl --enable-mms --enable-wavpack --disable-lame-encoder --disable-twolame-encoder --enable-vorbis --enable-lsr --enable-mikmod --with-zeroconf=auto

make

make install

/etc/init.d/mpd stop
echo DAEMON=/usr/local/bin/mpd >>/etc/default/mpd
/etc/init.d/mpd start

su pi
cd

Using a wireless LAN

Open the interfaces file

 sudo nano /etc/network/interfaces

Edit the file to make the file look like this

 auto lo

 iface lo inet loopback
 iface eth0 inet dhcp

 allow-hotplug wlan0
 iface wlan0 inet manual
   wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
 iface default inet dhcp
 wireless-power off

Open the supplicant file

 sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Edit the fie like this

 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 update_config=1

 network={
  ssid="mywlan"
  proto=WPA RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="mypassword"
}

Check the configuration after reboot

iwconfig

Troubleshooting USB sound cards

References:

http://blog.scphillips.com/2013/01/sound-configuration-on-raspberry-pi-with-alsa/

http://stackoverflow.com/questions/22283154/configuring-volume-control-for-usb-dac-to-be-used-via-mpd

Check active usb devices:

lsusb

Check sound cards:

aplay -l

aplay -L

Volume control:

get the sound card info first:

amixer info

get the id for the volume control

amixer controls

get the current volume level

amixer cget numid=2 #numid should be the number found in the previous step

set the volume to maximum

sudo amixer cset numid=2 100%

fix the current soundcard settings in the configuration file

sudo alsactl store

Adding a real time clock for proper synchronisation with a Songcast source

Adding a real time clock only makes sense if you want to use your player in a multi-room environment. The Songcast source can be a Mac or PC or a Linn DS player. be aware that all your players need to have the real time clock.

Get the Piface Real Time Clock mini board from www.farnell.com. You can get more information on the Piface web site:

PiFace Real Time Clock

The little board can be put over the GPIO pins of the Raspberry Pi. No soldering is needed and the pins will continue to be available for other peripherals.

The links in the PiFace documentation don't work well, so just follow the instructions below.

You will first need to make sure the Raspberry Pi is set to the right time.

sudo raspi-config

Make sure to set the right time zone for your Pi under Internationalisation Options.

Then select Advanced Options. Now select I2C. Make sure I2C is used and loaded at boot time.

Now install the software:

sudo nano install-piface-real-time-clock.sh

Enter the text below

#!/bin/bash
#: Description: Enables the required modules for PiFace Clock.

#=======================================================================
# NAME: set_revision_var
# DESCRIPTION: Stores the revision number of this Raspberry Pi into
#              $RPI_REVISION
#=======================================================================
set_revision_var() {
    rev_str=$(grep "Revision" /proc/cpuinfo)
    # get the last character
    len_rev_str=${#rev_str}
    chr_index=$(($len_rev_str-1))
    chr=${rev_str:$chr_index:$len_rev_str}
    if [[ $chr == "2" || $chr == "3" ]]; then
        RPI_REVISION="1"
    else
        RPI_REVISION="2"
    fi
}

#=======================================================================
# NAME: enable_module
# DESCRIPTION: Enabled the I2C module.
#=======================================================================
enable_module() {
    echo "Enabling I2C module."
    module="i2c-bcm2708"
    modules_file="/etc/modules"
    # if $module not in $modules_file: append $module to $modules_file.
    if ! grep -q $module $modules_file; then
        echo $module >> $modules_file
    fi
}

#=======================================================================
# NAME: start_on_boot
# DESCRIPTION: Load the I2C modules and send magic number to RTC, on boot.
#=======================================================================
start_on_boot() {
	    echo "Changing /etc/rc.local to load time from PiFace Clock."

    # remove exit 0
    sed -i "s/exit 0//" /etc/rc.local

    if [[ $RPI_REVISION == "1" ]]; then
        i=0  # i2c-0
    else
        i=1  # i2c-1
    fi

    cat >> /etc/rc.local << EOF
modprobe i2c-dev
modprobe i2c:mcp7941x
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-$i/device/new_device
hwclock -s
EOF
}

#=======================================================================
# MAIN
#=======================================================================
# check if the script is being run as root
if [[ $EUID -ne 0 ]]
then
    printf 'This script must be run as root.\nExiting..\n'
    exit 1
fi
RPI_REVISION=""
set_revision_var &&
enable_module &&
start_on_boot &&
printf 'Please *reboot* and then set your clock with:

    sudo date -s "14 JAN 2014 10:10:30"

'

Ctrl-X, Y, Enter

sudo chmod +x install-piface-real-time-clock.sh
sudo ./install-piface-real-time-clock.sh
sudo reboot

That's it! You don't need to set the time as the time was already correctly set through rasps-config.

CPU Frequency Scaling

Source: Debian CPU Frequency Scaling

You may want to use this in case you have a player that disappears from the network, for instance when you use a wifi connection. The settings described here will put the Raspberry Pi in performance mode all the time. Combined with switched off power management for the wifi dongle, this will give you the best availability of the player.

I have found that this setting is not necessary for a player connected through an ethernet cable.

Check the current setting:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Set up automatic setting:

sudo apt-get install cpufrequtils sysfsutils
sudo nano /etc/default/cpufrequtils

Make sure the file contains the following text:

# valid values: userspace conservative powersave ondemand performance
# get them from cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 
GOVERNOR="performance"

Configure sysfs:

sudo nano /etc/sysfs.conf

Add the following line at the end of the file:

devices/system/cpu/cpu0/cpufreq/scaling_governor = performance

And reboot

sudo reboot

Controlling mediaplayer in custom situations

The following commands are available

'setStandbyMode?value=<true or false>' - Set the StandyMode
'getStandbyMode' - Get the Current StandbyMode
'nextTrack' - Play the Next Track in Playlist
'previousTrack' - Play the Previous Track, if track has played for more than 5 secs current track is started again
'stopTrack' - Stop the Current Track
'pauseTrack' - Pauses the Current Track
'playTrack' - Plays the Current Track, if Paused will resume, if track not playing will attempt to play Next Track 
'incVolume' - Increase the Volume
'incVolume' - Decrease the Volume
'muteVolume?value=<true or false>' - Mute the Volume
'changeSource?value=' - Change the Source
'getSourceName' - Source Name
'getPlayerStatus' - Current Status of the Player
'setVolume?value=<x>' - Set the Volume, value between 0 and 100
'radioNextChannel' - play the next radio channel
'radioPreviousChannel' - play the previous radio channel

The commands can be activated with curl:

curl http://localhost:8088/myapp/mediaplayer/setStandbyMode?value=true

For an application of this, see the description for a small integrated digital streamer (DSi).

Creating and adding a configuration file for a non-Linn remote control

Source: Integrate LIRC in Mediaplayer

Before you create your own lirc configuration file for your remote, check this link for configuration files:

Lirc Remotes Configuration Files

Install lirc

sudo apt-get install lirc

Edit the /etc/modules file

sudo nano /etc/modules

Add the following two lines, choosing the GPIO pins that are not already being used

lirc_dev  
lirc_rpi gpio_in_pin=23 gpio_out_pin=14

or use any other free pins.

Edit your /etc/lirc/hardware.conf file

sudo nano /etc/lirc/hardware.conf

To be:

########################################################
    # /etc/lirc/hardware.conf
    #
    # Arguments which will be used when launching lircd
    LIRCD_ARGS="--uinput"

    # Don't start lircmd even if there seems to be a good config file
    # START_LIRCMD=false

    # Don't start irexec, even if a good config file seems to exist.
    # START_IREXEC=false

    # Try to load appropriate kernel modules
    LOAD_MODULES=true

    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"
    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"
    MODULES="lirc_rpi"

    # Default configuration files for your hardware if any
    LIRCD_CONF=""
    LIRCMD_CONF=""
    ########################################################

Restart lirc to pickup theses changes (sometimes a reboot is needed)

sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start

To test if you are receiving IR signals

sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0

You should see something like this:

space 16777215
pulse 14131078
space 8687
pulse 4599
space 657
pulse 1656
space 648
pulse 505
space 600
pulse 1710
space 653
pulse 507
space 593
pulse 559

To List the IR commands you can program enter

irrecord --list-namespace

To create a config file, first stop lirc

sudo /etc/init.d/lirc stop

The put lirc into record mode

irrecord -d /dev/lirc0 ~/lircd.conf

And follow the instructions.

You should end up with a config file similar to:

#
# contributed by 
#
# brand:                       /root/lircd.conf
# model no. of remote control: 
# devices being controlled by this remote:
#

begin remote

  name  TEAC_H300
  bits           16
  flags SPACE_ENC
  eps            30
  aeps          100

  header       8682  4597
  one           646  1664
  zero          646   508
  ptrail        616
  repeat       9263  2290
  pre_data_bits   16
  pre_data       0xA156
  gap          40067
  repeat_gap   95502
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0xE916
          KEY_POWER2               0xA156C936
          KEY_VOLUMEDOWN           0x7986
          KEY_VOLUMEUP             0xF906
          KEY_KP1                  0xA956
          KEY_KP2                  0x29D6
          KEY_KP3                  0x31CE
          KEY_KP4                  0x24DB
          KEY_KP5                  0xB14E
          KEY_KP6                  0x8976
      end codes

end remote

Copy this to /etc/lirc/lircd.conf

sudo cp lircd.con /etc/lirc/lircd.conf

Install the MediaPlayer LIRC plugin in the mediaplayer/plugins directory.

In mediaplayer/plugins/LIRC directory should be two files:

LIRCIntegration.jar LIRCConfig.xml

The LIRCConfig.xml maps the mediaplayer events to the lirc commands.

At the moment there are two types of events:

Volume (Up/Down)
SourceChanged (Name of Source as configured in the InputSources.xml file)  
StandbyChanged (true (in Standby) or false(not in Standby))  

My LIRCConfig.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Mappings>
<Mapping>
    <Event>VolumeInc</Event>
    <Command>irsend SEND_ONCE MM1 KEY_VOLUMEUP</Command>
    <!-- Command>notepad.exe UP</Command -->
</Mapping>

<Mapping>
    <Event>VolumeDec</Event>
    <Command>irsend SEND_ONCE MM1 KEY_VOLUMEDOWN</Command>
    <!-- Command>notepad.exe DOWN</Command -->
</Mapping>

<Mapping>
    <Event>StandbyChanged</Event>
    <Name>true</Name>
    <Command>irsend SEND_ONCE TEAC_H300 KEY_POWER</Command>
</Mapping>

<Mapping>
    <Event>StandbyChanged</Event>
    <Name>false</Name>
    <Command>irsend SEND_ONCE TEAC_H300 KEY_POWER</Command>
</Mapping>

</Mappings>

If you are having trouble creating the lircd.conf file, run irrecord in raw mode:

irrecord --force -d /dev/lirc0 ~/lircd.conf

Working with Device Tree

Source: Raspberry Pi Device Tree

Edit config.txt in /boot :

sudo nano /boot/config.txt

Edit the file as necessary:

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment one of these lines to enable an audio interface
#dtoverlay=hifiberry-amp
#dtoverlay=hifiberry-dac
#dtoverlay=hifiberry-dacplus
#dtoverlay=hifiberry-digi
#dtoverlay=iqaudio-dac
#dtoverlay=iqaudio-dacplus

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Uncomment this to override the defaults for the lirc-rpi module
#dtparam=gpio_out_pin=16
#dtparam=gpio_in_pin=17
#dtparam=gpio_in_pull=down

Troubleshooting LIRC

If you have problems controlling an external amp with the LIRC plugin for mediaplayer, you can try the following:

Test if you are using the correct name for the remote control you want to emulate:

irsend LIST "" ""

This should list the name of your remote control. If the name is incorrect, check the lircd.conf file in /etc/lirc.

Send a command to the external device:

irsend SEND_ONCE CLASSIK KEY_VOLUMEUP

(Change the name of the remote and the name of the command as required)

Determine your Raspberry Pi Hardware Version

Source: http://ozzmaker.com/check-raspberry-software-hardware-version-command-line/

cat /proc/cpuinfo
MODEL AND PI REVISION 256MB HARDWARE REVISION CODE FROM CPUINFO
Model B Revision 1.0 256MB 0002
Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) 256MB 0003
Model B Revision 2.0 256MB 0004
Mounting holes 0005
0005
0006
Model A 256MB 0007
Mounting holes 256MB 0007
0008
0009
Model B Revision 2.0 512MB 000d
Mounting holes 000e
000f
Model B+ 512MB 0010
Compute Module 512MB 0011
Model A+ 256MB 0012
Pi 2 Model B 1GB a01041 (Sony, UK)
a21041 (Embest, China)
PiZero 512MB 900092(no camera connector)
900093(camera connector)
Pi 3 Model B 1GB a02082 (Sony, UK)
a22082 (Embest, China)

Kernel info:

name -a

Remote Desktop

Download Microsoft Remote Desktop on your PC or MAC

On the Raspberry Pi:

sudo apt-get install xrdp

Now use Remote Desktop to access your RPi.

More info: http://www.raspberrypiblog.com/2012/10/how-to-setup-remote-desktop-from.html