Videos buffer while running sonic pi in ubuntu

Hi , i have just installed sonic-pi in ubuntu 18.04. However i notice that when sonic pi and super collider servier is running. I am unable to run youtube videos / media vidoes in browser (chrome and mozzilla) . As soon as i quit the sonic-pi programe, the video resumes without any glitches .Is there some setting as such one needs to change ?

Hi @tim,

this is because:

“Basically once you start Jack Pulse won’t be available because Alsa/Jack have occupied you soundcard (that is why, if you want to listen to some mp3 files during such a session e. g. you will have to use a Jack-capable music player like audacious).” (see: Jackd/ALSA (Linux) best practices for SP?)

You can run Pulse audio through Jack to solve the problem - though up to now I have not yet found a reliable configuration (but that is probably me being to stupid :wink: ).

thanks for the reply ! it is i guess applicable for streaming videos from youtueb as well. Kind of sucks when you have follow along tutorials :slight_smile: you want to follow

Well, yes, if you follow the guide linked whenever you will start Jack Pulse audio (which Chrome and Firefox use) routing through Jack which is a seamless experience once it works. (Linux still suffers from competing sound systems. On the other hand Jack is a great program; it is a pity that not all applications know how to use it - like e. g. Firefox).

I assume you don’t start Jack manually, right? In other words, you will let SP take care of starting Jack. If this is the case, then the mentioned solution might not be applicable. But you can just try to follow the instructions and then start qjackctl before you start SP.

If you will try that, let me know whether it works…

I have to correct myself. Actually I have configured this solution and checked it again: it works if I use qjackctl to start Jack

(I used to start Jack via jackd -S -d alsa --device hw:0 --rate 48000 --period 1024).

Hi i actually did how you mentioned. Start the qjacktctl with the command as you mentioned above but still i could not run vidoes in youtube , while sonic pi was up and running

I just checked and found out that I have another script running which I got from here: brummer10 / pajackconnect. I am not sure if you have to install pulseaudio-module-jack, the instructions seem to suggest otherwise.

So here is part of my qjackctl configuration …

… and here is the script which you can see being called after start resp. shutdown of qjackctl:

pajackconnect
#!/bin/bash
#+
# This script is intended to be invoked via QjackCtl to start up and
# shut down JACK on a system running PulseAudio. It handles the
# necessary setup to make the two work together, so PulseAudio clients
# get transparently routed through JACK while the latter is running, or
# if pulseaudio is suspend by pasuspender, do nothing
#
# Usage: in QjackCtl’s Settings window, in the “Options” tab, enter
# the command
#
# pajackconnect start &
#
# in the field labelled “Execute script after Startup”, and put
#
# pajackconnect stop &
#
# in the field labelled “Execute script on Shutdown”.
#
# pajackconnect reset &
#
# in the field labelled “Execute script after Shutdown”.
#
# for use jack without pulseaudio, add in Qjackctl setting window
# in the serverpath field 'pasuspender -- ' before 'jackd', save settings
# as "No Pulse" for example. Remove 'pasuspender -- ',
# and save settings as 'Pulse'. Now you can select from the
# Qjackctl setting window, if you would start jack with or without pulse.
#
# References:
# PulseAudio: <http://www.freedesktop.org/wiki/Software/PulseAudio/>
# JACK: <http://jackaudio.org/>
#
# Copyright 2014 by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>. This
# script is licensed CC0
# <https://creativecommons.org/publicdomain/zero/1.0/>; do with it
# what you will.
#
# overall script formating by Hermann Meyer
# added possibility to run jack with suspend pulse by Hermann Meyer
# added save and restore previous used pulseaudio ports by Hermann Meyer
# added reload pulse jack modules after resume from suspend
# (needs to be called by a systemd.service file) by Hermann Meyer
#-


# variable to fetch pasuspender status
p=`ps ax | grep '[p]asuspender'`
if [ "${XDG_RUNTIME_DIR-}" != "" ]
then
  pajack_dir="$XDG_RUNTIME_DIR/pulse"
else
  pajack_dir="/tmp/pajackconnect-${LOGNAME-${USER-}}"
fi
mkdir -m 700 -p "$pajack_dir"

function restart() {
	# reload pulse jack module after resume from suspend.
	# give the system time to reload pulse deamon before load the modules.
	sleep 5
	# if command-line option restart is given
	# check if pasuspender waiting for jack, if so, exit here. Nothing more
	# to do.
	# echo "restart"
	if [[ "$p"  =~ "jackd" ]]; then
		#echo "pasuspender is active"
		exit 0
	else
		# check if pulse jack modules are loaded
		jc=`pacmd list | grep jack-sink`
		# check if jack is running
		ja=`pidof jackd | wc -w`
		# check if pulseaudio is running
		pa=`pidof pulseaudio | wc -w`
		# write results to log file
		date +%H:%M:%S  >>"$pajack_dir/pajack.log"
		echo 'jack-sink =' $jc  >>"$pajack_dir/pajack.log"
		echo 'jack =' $ja >>"$pajack_dir/pajack.log"
		echo 'pulse =' $pa >>"$pajack_dir/pajack.log"
		if [[ ! "$jc" =~ "jack" ]] && [[ "$ja" == "1" ]]; then
			# if pulseaudio didn't run, let's try start it
			if [[ ! "$pa" == "1" ]]; then
				sleep 5
				pulseaudio -D
				echo reload pulseaudio >>"$pajack_dir/pajack.log"
				sleep 10
			fi
			# if jack is running and pulse jack modules aren't loaded,
			# let's load them and set them as default ports
			pacmd load-module module-jack-sink channels=2
			pacmd load-module module-jack-source channels=2
			pacmd unload-module module-suspend-on-idle
			pacmd set-default-sink jack_out
			# move around source port, seems to make pulseaudio work with jack
			# otherwise it seems that pulseaudio is connected, but it didn't work.
			pacmd set-default-source jack_in && sleep 1
			source=`cat "$pajack_dir"/pasourcej`
			pacmd set-default-source $source && sleep 1
			pacmd set-default-source jack_in
			# echo "pa source switched"
			echo reloaded jack modules >>"$pajack_dir/pajack.log"
		else
			echo already run >>"$pajack_dir/pajack.log"
		fi
	fi
	}

function start() {
	# if command-line option start is given
	# check if pasuspender waiting for jack, if so, exit here. Nothing more
	# to do.
	if [[ "$p"  =~ "jackd" ]]; then
		#echo "pasuspender is active"
		exit 0
	else
		# if pasuspender isn't waiting for jack, let's fetch the current
		# ports, pulseaudio use, save them to "$pajack_dir", for later use.
		#echo "pasuspender is NOT active"
		sink=`pacmd list short sinks |  sed -n "/Default sink name/p"| sed "s/Default sink name://"`
		echo $sink >"$pajack_dir"/pasinkj
		source=`pacmd list short sinks |  sed -n "/Default source name/p"| sed "s/Default source name://"`
		echo $source >"$pajack_dir"/pasourcej
		# load the pulseaudio jack module and set them as default ports
		pacmd load-module module-jack-sink channels=2
		pacmd load-module module-jack-source channels=2
		pacmd unload-module module-suspend-on-idle
		pacmd set-default-sink jack_out
		# move around source port, seems to make pulseaudio work with jack
		# otherwise it seems that pulseaudio is connected, but it didn't work.
		pacmd set-default-source jack_in && sleep 1
		pacmd set-default-source $source && sleep 1
		pacmd set-default-source jack_in
		#echo "pa source switched"
	fi
}

function stop() {
	# if command-line option stop is given
	# again, check if pasuspender waiting for jack, if not, unload the pulse
	# jack module and reload the module-suspend-on-idle.
	if [[ ! "$p"  =~ "jackd" ]]; then
		#echo "pasuspender is NOT active"
		pacmd unload-module module-jack-sink
		pacmd unload-module module-jack-source
		pacmd load-module module-suspend-on-idle
	else
		# if pasuspender waiting for jack, add a timeout to pasuspender
		# to allow a smooth reset action afterward.
		#echo "pasuspender is active"
		pasuspender -- sleep 5 &
	fi
}

function reset() {
	# if command-line option reset is given
	# check if we have add a timeout to pasuspender, if so, exit here.
	if [[ "$p"  =~ "sleep" ]]; then
		#echo "pasuspender is active"
		exit 0
	else
		# fetch the previous saved pulse audio ports and set them back
		# as default ports for pulseaudio. Done.
		sink=`cat "$pajack_dir"/pasinkj`
		source=`cat "$pajack_dir"/pasourcej`
		pacmd set-default-sink $sink
		pacmd set-default-source $source
		#echo "pasuspender is NOT active"
	fi
}

# check for given command-line option
case "$1" in
	restart)
		restart
		;;
	start)
		start
		;;
	stop)
		stop
		;;
	reset)
		reset
		;;
	*)
		echo $"Usage:\n\t $0 {restart|start|stop|reset}\n"
		exit 1
esac

exit 0

I hope that helps…

You can use pulseaudio-module-jack to enable pulseaudio connected devices to play through jack. Thus you could use chrome browser and sonic-pi at the same time. Look at this link
I followed the answer relating to Ubuntu 20.04 by Bruno Grieder, running on my Pi4. I think it should be OK with Ubuntu 18.04 as well.

Thank you guys , i finally made it work ! Thanks a lot , appreciate it