#!/bin/sh
#
# jacksetup.sh [version 1] 24/07/2007
#
# Damo's Realtime Audio Tweaker:
# Sick of pops and clicks in audio (jack) when you load cpu?
# Sick of manually tweaking realtime priorities?
# Sick of MIDI events losing synch?
# Want XMMS (and all other audio stuff) to run through jack with 100% perfection?
# Me too, I fiddled for a while, then came up with the following solution:
#
# Step 1: Make sure you are running Ingo patched realtime kernel
# Step 2: cat /proc/interrupts
# Make sure your soundcard has unique IRQ
# If s/c is sharing IRQ, you need to set module options
# in /etc/modprobe.d/alsa-base
# eg for intel ac97, add a line such as:
# options intel8x0 irq=5
# then reboot (or rmmod all soundcard modules and reload).
# (5 should be a free IRQ)
#
########## Configuration ##########
# Note the IRQ of soundcard... set it here:
SOUNDCARD_IRQ=5
# Note the IRQ of rtc... set it here:
RTC_IRQ=8
######## End Configuration ########
# REALTIME AUDIO SCHEDULING:
# This will setup solid jack performance:
if [ ! -x "/usr/bin/chrt" ] ; then
gksudo apt-get install schedutils
fi
TIMER=`pidof "posix_cpu_timer"`
SCARD=`pidof "IRQ-${SOUNDCARD-IRQ}"`
RTC=`pidof "IRQ-${RTC_IRQ}"` # Vital settings:
gksudo "chrt -p 99 ${RTC}" # Sets realtime clock to REALTIME!!
gksudo "chrt -p 85 ${SCARD}" # Sets soundcard to near realtime
gksudo "renice -20 ${RTC}" # "
gksudo "renice -20 ${SCARD}" # "
gksudo "renice -20 ${TIMER}" # "
gksudo "killall -q esd"
qjackctl &
##### NEEDS TWEAKING TO MATCH QJACKCTL:
sleep 3 # Set jack to autostart, set this 1 second higher than qjackctl delay
##### END
JACK=`pidof "jackd"`
chrt -p 70 ${JACK} # Sets jack rt priority just below soundcard
gksudo "renice -20 ${JACK}" # "
# Name of favourite jack-enabled player:
PLAYER=xmms
OPTIONS=
${PLAYER} ${OPTIONS} &
sleep 1
chrt -p 65 `pidof ${PLAYER}` # Sets player priority below jack
gksudo "renice -20 `pidof ${PLAYER}`" # "
# Enjoy solid audio performance, regardless of cpu load!
# You shouldnt get those ugly hard frame drops anymore
# If you get legitimate buffer drops (xruns will be reported by jack)
# it must be your jack buffer settings,
# set higher buffer...
#
# Damo