2019-09-21 09:15:08 +02:00
#!/bin/bash
# This script is intended to setup a clean Raspberry Pi system for running Jamulus
2019-09-21 12:47:58 +02:00
OPUS = "opus-1.1"
2019-09-21 17:57:41 +02:00
NCORES = $( nproc)
2019-09-21 10:23:39 +02:00
2019-09-25 18:06:54 +02:00
# install required packages
2019-09-28 07:23:11 +02:00
pkgs = 'alsamixergui build-essential qt5-default libasound2-dev cmake libglib2.0-dev'
2019-09-25 18:06:54 +02:00
if ! dpkg -s $pkgs >/dev/null 2>& 1; then
read -p "Do you want to install missing packages? " -n 1 -r
echo
if [ [ $REPLY = ~ ^[ Yy] $ ] ] ; then
sudo apt-get install $pkgs -y
fi
fi
2019-09-21 10:23:39 +02:00
# Opus audio codec, custom compilation with custom modes and fixed point support
if [ -d " ${ OPUS } " ] ; then
echo "The Opus directory is present, we assume it is compiled and ready to use. If not, delete the opus directory and call this script again."
else
2019-09-21 09:15:08 +02:00
wget https://archive.mozilla.org/pub/opus/${ OPUS } .tar.gz
tar -xzf ${ OPUS } .tar.gz
rm ${ OPUS } .tar.gz
cd ${ OPUS }
2019-09-21 10:23:39 +02:00
./configure --enable-custom-modes --enable-fixed-point
2019-09-21 17:57:41 +02:00
make -j${ NCORES }
2019-09-21 18:18:29 +02:00
mkdir include/opus
cp include/*.h include/opus
2019-09-21 12:47:58 +02:00
cd ..
fi
2019-09-21 17:57:41 +02:00
# Jack audio without DBUS support
if [ -d "jack2" ] ; then
echo "The Jack2 directory is present, we assume it is compiled and ready to use. If not, delete the jack2 directory and call this script again."
else
git clone https://github.com/jackaudio/jack2.git
cd jack2
git checkout v1.9.12
2019-09-22 09:33:01 +02:00
./waf configure --alsa --prefix= /usr/local --libdir= $( pwd ) /build
2019-09-21 17:57:41 +02:00
./waf -j${ NCORES }
2019-09-22 09:33:01 +02:00
mkdir build/jack
cp build/*.so build/jack
cp build/common/*.so build/jack
cp build/example-clients/*.so build/jack
2019-09-21 17:57:41 +02:00
cd ..
2019-09-28 09:30:04 +02:00
# give audio group rights to do realtime
if grep -Fq "@audio" /etc/security/limits.conf; then
echo "audio group already has realtime rights"
else
sudo sh -c 'echo "@audio - rtprio 95" >> /etc/security/limits.conf'
sudo sh -c 'echo "@audio - memlock unlimited" >> /etc/security/limits.conf'
fi
2019-09-21 17:57:41 +02:00
fi
2019-09-21 09:15:08 +02:00
2019-09-22 11:19:29 +02:00
# optional: FluidSynth synthesizer
if [ " $1 " = = "opt" ] ; then
2019-09-22 11:51:43 +02:00
if [ -d "fluidsynth" ] ; then
2019-09-22 11:19:29 +02:00
echo "The Fluidsynth directory is present, we assume it is compiled and ready to use. If not, delete the fluidsynth directory and call this script again."
else
2019-09-29 08:19:19 +02:00
#TODO if the normal jack package is not installed, fluidsynth compiles without jack support
2019-09-22 11:19:29 +02:00
wget https://github.com/FluidSynth/fluidsynth/archive/v2.0.6.tar.gz -O fluidsynth.tar.gz
tar -xzf fluidsynth.tar.gz
rm fluidsynth.tar.gz
2019-09-22 11:51:43 +02:00
mv fluidsynth-* fluidsynth
cd fluidsynth
2019-09-22 11:19:29 +02:00
mkdir build
cd build
cmake ..
make -j${ NCORES }
2019-09-22 11:51:43 +02:00
wget https://data.musical-artifacts.com/hammersound/claudio_piano.sf2
2019-09-22 11:19:29 +02:00
cd ../..
fi
fi
2019-09-21 10:23:39 +02:00
# compile Jamulus with external Opus library
cd ..
2019-09-28 09:30:04 +02:00
qmake "CONFIG+=opus_shared_lib" " INCLUDEPATH+=distributions/ ${ OPUS } /include " " QMAKE_LIBDIR+=distributions/ ${ OPUS } /.libs " "INCLUDEPATH+=distributions/jack2/common" "QMAKE_LIBDIR+=distributions/jack2/build/common" Jamulus.pro
2019-09-21 17:57:41 +02:00
make -j${ NCORES }
2019-09-21 12:47:58 +02:00
2019-09-21 15:08:56 +02:00
# get first USB audio sound card device
ADEVICE = $( aplay -l| grep "USB Audio" | head -1| cut -d' ' -f3)
echo " Using USB audio device: ${ ADEVICE } "
2019-09-28 14:28:51 +02:00
# write Jamulus ini file for setting the client name and buffer settings
2019-09-23 19:57:28 +02:00
JAMULUSINIFILE = "Jamulus.ini"
2019-10-05 13:06:12 +02:00
NAME64 = $( echo " Raspi $( hostname) " | cut -c -16| tr -d $'\n' | base64)
2019-10-01 16:50:47 +02:00
if [ " $NCORES " -gt "1" ] ; then
echo -e " <client>\n <name_base64> ${ NAME64 } </name_base64> " > ${ JAMULUSINIFILE }
echo -e " <autojitbuf>1</autojitbuf>\n <jitbuf>3</jitbuf>\n <jitbufserver>3</jitbufserver>" >> ${ JAMULUSINIFILE }
echo -e " <audiochannels>2</audiochannels>\n <audioquality>1</audioquality>\n</client>" >> ${ JAMULUSINIFILE }
else
echo -e " <client>\n <name_base64> ${ NAME64 } </name_base64> " > ${ JAMULUSINIFILE }
echo -e " <autojitbuf>1</autojitbuf>\n <jitbuf>3</jitbuf>\n <jitbufserver>3</jitbufserver>" >> ${ JAMULUSINIFILE }
echo -e " <audiochannels>0</audiochannels>\n <audioquality>0</audioquality>\n</client>" >> ${ JAMULUSINIFILE }
fi
2019-09-23 19:34:12 +02:00
2019-09-28 21:11:31 +02:00
# taken from "Raspberry Pi and realtime, low-latency audio" homepage at wiki.linuxaudio.org
#sudo service triggerhappy stop
#sudo service dbus stop
#sudo mount -o remount,size=128M /dev/shm
2019-09-21 12:47:58 +02:00
# start Jack2 and Jamulus in headless mode
2019-09-21 21:18:34 +02:00
export LD_LIBRARY_PATH = " distributions/ ${ OPUS } /.libs:distributions/jack2/build:distributions/jack2/build/common "
2019-09-21 10:23:39 +02:00
2019-09-22 11:19:29 +02:00
if [ " $1 " = = "opt" ] ; then
2019-10-05 10:33:41 +02:00
distributions/jack2/build/jackd -R -T --silent -P70 -p16 -t2000 -d alsa -dhw:${ ADEVICE } -p 256 -n 3 -r 48000 -s &
2019-09-25 18:06:54 +02:00
./Jamulus -n -i ${ JAMULUSINIFILE } -j -c jamulus.fischvolk.de & >/dev/null &
2019-09-22 11:19:29 +02:00
sleep 1
2019-10-05 10:33:41 +02:00
./distributions/fluidsynth/build/src/fluidsynth -o synth.polyphony= 25 -s -i -a jack -g 0.4 distributions/fluidsynth/build/claudio_piano.sf2 & >/dev/null &
2019-09-22 11:19:29 +02:00
sleep 3
2019-09-22 20:48:56 +02:00
./distributions/jack2/build/example-clients/jack_connect "Jamulus:output left" system:playback_1
./distributions/jack2/build/example-clients/jack_connect "Jamulus:output right" system:playback_2
2019-09-22 11:51:43 +02:00
./distributions/jack2/build/example-clients/jack_connect fluidsynth:left "Jamulus:input left"
./distributions/jack2/build/example-clients/jack_connect fluidsynth:right "Jamulus:input right"
2019-09-22 11:19:29 +02:00
aconnect 'USB-MIDI' 128
2019-09-24 16:15:35 +02:00
2019-09-24 16:25:10 +02:00
# if hyperion is installed, set red color
if [ ! -z " $( command -v hyperion-remote) " ] ; then
hyperion-remote -c red
fi
2019-09-24 16:15:35 +02:00
# watchdog: if MIDI device is turned off, shutdown Jamulus
while [ ! -z " $( amidi -l| grep "USB-MIDI" ) " ] ; do
sleep 1
done
2019-09-25 18:06:54 +02:00
killall Jamulus
2019-09-24 16:15:35 +02:00
killall fluidsynth
echo "Cleaned up jackd, Jamulus and fluidsynth"
2019-09-24 16:25:10 +02:00
# if hyperion is installed, reset color
if [ ! -z " $( command -v hyperion-remote) " ] ; then
hyperion-remote --color black
hyperion-remote --clearall
fi
2019-09-22 11:51:43 +02:00
else
2019-10-05 10:33:41 +02:00
distributions/jack2/build/jackd -R -T --silent -P70 -p16 -t2000 -d alsa -dhw:${ ADEVICE } -p 128 -n 3 -r 48000 -s &
2019-09-25 18:06:54 +02:00
./Jamulus -n -i ${ JAMULUSINIFILE } -c jamulus.fischvolk.de &
echo "###---------- PRESS ANY KEY TO TERMINATE THE JAMULUS SESSION ---------###"
read -n 1 -s -r -p ""
killall Jamulus
2019-09-22 11:19:29 +02:00
fi