Browse Source

Update pulse2jack script to better handle already-running pulseaudio

tags/v0.9.0
falkTX 13 years ago
parent
commit
69cae2008f
2 changed files with 91 additions and 47 deletions
  1. +83
    -45
      data/cadence-pulse2jack
  2. +8
    -2
      src/cadence_aloop_daemon.py

+ 83
- 45
data/cadence-pulse2jack View File

@@ -1,42 +1,53 @@
#!/bin/bash #!/bin/bash
# Script to stop current pulseaudio and restart it in JACK mode
# Script to bridge/start pulseaudio into JACK mode


INSTALL_PREFIX="X-PREFIX-X" INSTALL_PREFIX="X-PREFIX-X"


IsPulseAudioRunning()
{
PROCESS=`ps -e | grep pulseaudio`
if [ "$PROCESS" == "" ]; then
false
else
true
fi
}
# ----------------------------------------------


if [ ! -d ~/.pulse ]; then if [ ! -d ~/.pulse ]; then
mkdir -p ~/.pulse
mkdir -p ~/.pulse
fi fi


if [ ! -f ~/.pulse/client.conf ]; then if [ ! -f ~/.pulse/client.conf ]; then
echo "autospawn = no" > ~/.pulse/client.conf
echo "autospawn = no" > ~/.pulse/client.conf
else else
if (! cat ~/.pulse/client.conf | grep "autospawn = no" > /dev/null); then
sed -i '/autospawn =/d' ~/.pulse/client.conf
echo "autospawn = no" >> ~/.pulse/client.conf
fi
if (! cat ~/.pulse/client.conf | grep "autospawn = no" > /dev/null); then
sed -i '/autospawn =/d' ~/.pulse/client.conf
echo "autospawn = no" >> ~/.pulse/client.conf
fi
fi fi


if [ ! -f ~/.pulse/daemon.conf ]; then if [ ! -f ~/.pulse/daemon.conf ]; then
echo "rlimit-rttime = -1" > ~/.pulse/daemon.conf
else
if (! cat ~/.pulse/daemon.conf | grep "rlimit-rttime = -1" > /dev/null); then
sed -i '/rlimit-rttime =/d' ~/.pulse/daemon.conf
echo "default-sample-format = float32le" > ~/.pulse/daemon.conf
echo "realtime-scheduling = yes" >> ~/.pulse/daemon.conf
echo "rlimit-rttime = -1" >> ~/.pulse/daemon.conf echo "rlimit-rttime = -1" >> ~/.pulse/daemon.conf
fi
echo "exit-idle-time = -1" >> ~/.pulse/daemon.conf
else
if (! cat ~/.pulse/daemon.conf | grep "default-sample-format = float32le" > /dev/null); then
sed -i '/default-sample-format = /d' ~/.pulse/daemon.conf
echo "default-sample-format = float32le" >> ~/.pulse/daemon.conf
fi
if (! cat ~/.pulse/daemon.conf | grep "realtime-scheduling = yes" > /dev/null); then
sed -i '/realtime-scheduling = /d' ~/.pulse/daemon.conf
echo "realtime-scheduling = yes" >> ~/.pulse/daemon.conf
fi
if (! cat ~/.pulse/daemon.conf | grep "rlimit-rttime = -1" > /dev/null); then
sed -i '/rlimit-rttime =/d' ~/.pulse/daemon.conf
echo "rlimit-rttime = -1" >> ~/.pulse/daemon.conf
fi
if (! cat ~/.pulse/daemon.conf | grep "exit-idle-time = -1" > /dev/null); then
sed -i '/exit-idle-time =/d' ~/.pulse/daemon.conf
echo "exit-idle-time = -1" >> ~/.pulse/daemon.conf
fi
fi fi


# ----------------------------------------------

PLAY_ONLY="no"

case $1 in case $1 in
-h|--h|--help)
-h|--h|--help)
echo "usage: $0 [command] echo "usage: $0 [command]


-p, --play Playback mode only -p, --play Playback mode only
@@ -49,37 +60,64 @@ NOTE:
activate PulseAudio with both playback and record modes. activate PulseAudio with both playback and record modes.
" "
exit exit
;;
;;


-p|--p|--play)
-p|--p|--play)
PLAY_ONLY="yes"
FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa
;;
;;


*)
*)
FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa
;;
;;
esac esac


if (IsPulseAudioRunning); then
# ----------------------------------------------

IsPulseAudioRunning()
{ {
echo "PulseAudio is running, stopping it..."
killall pulseaudio
env sleep 0.2

if (IsPulseAudioRunning); then
{
echo "Failed, force kill..."
pkill -KILL pulseaudio
env sleep 0.2
}
else
echo "Success!"
fi
PROCESS=`ps -e | grep pulseaudio`
if [ "$PROCESS" == "" ]; then
false
else
true
fi
} }
fi


if (`pulseaudio --daemonize --high-priority --realtime --disallow-module-loading --exit-idle-time=-1 --file=$FILE -n`); then
echo "Initiated PulseAudio successfully!"
if (IsPulseAudioRunning); then
{
if (`jack_lsp | grep "PulseAudio JACK Sink:" > /dev/null`); then
{
echo "PulseAudio is already running and bridged to JACK"
}
else
{
echo "PulseAudio is already running, bridge it..."

if [ "$PLAY_ONLY" == "yes" ]; then
{
pactl load-module module-jack-sink > /dev/null
pacmd set-default-source jack_in > /dev/null
}
else
{
pactl load-module module-jack-sink > /dev/null
pactl load-module module-jack-source > /dev/null
pacmd set-default-sink jack_out > /dev/null
pacmd set-default-source jack_in > /dev/null
}
fi

echo "Done"
}
fi
}
else else
echo "Failed to initialize PulseAudio!"
{
if (`pulseaudio --daemonize --high-priority --realtime --disallow-module-loading --exit-idle-time=-1 --file=$FILE -n`); then
echo "Initiated PulseAudio successfully!"
else
echo "Failed to initialize PulseAudio!"
fi
}
fi fi

+ 8
- 2
src/cadence_aloop_daemon.py View File

@@ -3,7 +3,7 @@


# Imports (Global) # Imports (Global)
from ctypes import * from ctypes import *
from os import system
from os import path, system
from sys import version_info from sys import version_info
from signal import signal, SIGINT, SIGTERM from signal import signal, SIGINT, SIGTERM
from time import sleep from time import sleep
@@ -52,7 +52,13 @@ def shutdown_callback(arg):
# run alsa_in and alsa_out # run alsa_in and alsa_out
def run_alsa_bridge(): def run_alsa_bridge():
global sample_rate, buffer_size global sample_rate, buffer_size
system("killall alsa_in alsa_out zita-a2j zita-j2a pulseaudio")
killList = "alsa_in alsa_out zita-a2j zita-j2a"

# On KXStudio, pulseaudio is nicely bridged & configured to work with JACK
if not path.exists("/usr/share/kxstudio/config/pulse/daemon.conf"):
killList += " pulseaudio"

system("killall %s" % killList)


#if (False): #if (False):
system("env JACK_SAMPLE_RATE=%i JACK_PERIOD_SIZE=%i alsa_in -j alsa2jack -d cloop -q 1 2>&1 1> /dev/null &" % (sampleRate, bufferSize)) system("env JACK_SAMPLE_RATE=%i JACK_PERIOD_SIZE=%i alsa_in -j alsa2jack -d cloop -q 1 2>&1 1> /dev/null &" % (sampleRate, bufferSize))


Loading…
Cancel
Save