Enable replaygain permanently using custom shell script (volumio-mpdcorr.sh)

Dear fellow volumio users. I have searched quite some time to find a solution to permanently add replaygain support to volumio without having to bother with the configuration after a change in the settings of ‘Playback Options’. Because i found none, i figured it out myself and created a shell script (volumio-mpdcorr.sh) that enables replaygain and some other audio related options that are partly not exposed on the volumio web interface. I have been using this solution for about three months and have not encountered any problems at all. Therefore i decided to share my solution to the public.


Explanation:
When following the steps described below my shell script volumio-mpdcorr.sh will do the following:

  1. create mpdcorr.sh in the /usr/bin folder
  2. configure mpdcorr.sh to ajust /etc/mpd.conf to:
  • enable gapless mp3 playback
  • enable replaygain and set it to AUTO
  • disable replaygain preamp
  • disable volume normalization
  • set audio buffer size to 12288kb
  • set buffer before play to 40%
  1. make mpdcorr.sh executable
  2. stop systemd unit mpd.service
  3. adjust systemd unit mpd.service (to run mpdcorr.sh before itself) and restart it

If you want to use different settings feel free to adjust my shell script according to your needs.


Disclaimer:
You use this at your own risk. I can not be held responsible for any technical difficulties, errors or damages to your hardware or life.


How to use volumio-mpdcorr.sh:

  1. enable ssh via http://YourVolumioIP/dev/
  2. login to volumio via ssh using a terminal
  3. type touch volumio-mpdcorr.sh
  4. type nano volumio-mpdcorr.sh
  5. copy and paste the following in the terminal

#!/bin/bash

###create mpdcorr.sh in /usr/bin
touch /usr/bin/mpdcorr.sh

###configure mpdcorr.sh
echo “#!/bin/bash” >> /usr/bin/mpdcorr.sh
echo “#configure mpd.conf for:” >> /usr/bin/mpdcorr.sh
##enable gapless_mp3_playback
echo “” >> /usr/bin/mpdcorr.sh
echo “#gapless_mp3_playback -> YES” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/<gapless_mp3_playback>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<gapless_mp3_playback>/s/”."/“yes”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh
##enable replaygain and set to AUTO
echo “” >> /usr/bin/mpdcorr.sh
echo “#replaygain -> AUTO” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/<replaygain>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<replaygain>/s/”.
"/“auto”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh
##disable replaygain_preamp
echo “” >> /usr/bin/mpdcorr.sh
echo “#replaygain_preamp -> O” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/<replaygain_preamp>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<replaygain_preamp>/s/”."/“0”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh
##disable volume_normalization
echo “” >> /usr/bin/mpdcorr.sh
echo “#volume_normalization -> NO” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/<volume_normalization>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<volume_normalization>/s/”.
"/“no”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh
##set audio_buffer_size to 12288
echo “” >> /usr/bin/mpdcorr.sh
echo “#audio_buffer_size -> 12288” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/<audio_buffer_size>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<audio_buffer_size>/s/”."/“12288”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh
##set buffer_before_play to 40%
echo “” >> /usr/bin/mpdcorr.sh
echo “#buffer_before_play -> 40%” >> /usr/bin/mpdcorr.sh
echo “sed -i ‘/\buffer_before_play>/s/#//’ /etc/mpd.conf” >> /usr/bin/mpdcorr.sh
echo “sed -i '/<buffer_before_play>/s/”.
"/“40%”/’ /etc/mpd.conf" >> /usr/bin/mpdcorr.sh

###make mpdcorr.sh executable
chmod 0755 /usr/bin/mpdcorr.sh

###stop mpd.service
systemctl stop mpd.service

###modify and restart mpd.service
sed -i ‘/^ExecStart=.*/i ExecStartPre=/usr/bin/mpdcorr.sh’ /lib/systemd/system/mpd.service
systemctl daemon-reload
systemctl start mpd.service
echo mpdcorr.sh has successfully been created and activated

  1. press CTRL+O to save CTRL-X to exit nano
  2. type chmod +x volumio-mpdcorr.sh to make the shell script executable
  3. type sudo ./volumio-mpdcorr.sh to execute the shell script and wait for completion
  4. reboot volumio by typing sudo reboot now
  5. disable ssh via http://YourVolumioIP/dev/