Skip to content

Instantly share code, notes, and snippets.

@Overemployed
Last active April 18, 2024 19:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Overemployed/f30db915ac5dcb0b3d17ea1b6310e5f2 to your computer and use it in GitHub Desktop.
Save Overemployed/f30db915ac5dcb0b3d17ea1b6310e5f2 to your computer and use it in GitHub Desktop.
Jacktrip running on PiKVM / Raspberry Pi with arch distro
#!/bin/bash
# Check if script is running as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# your personal machine running jacktrip
REMOTE_JACK_SERVER=nat.local
# change to any name to identify this jacktrip client
JOB_NAME=J1
BUFFER_SIZE=1024
# -d hw:1,0 for pikvm v3 hat
# -d hw:0,0 for others
AUDIO_DEVICE=-d hw:1,0
pacman -Syu
pacman -S --needed jack2 jacktrip njconnect jack-example-tools
# Checking if user 'jacktrip' already exists
if id "jacktrip" &>/dev/null; then
echo "User 'jacktrip' already exists. Skipping user creation."
else
useradd -M -r jacktrip -G audio
fi
cat > /etc/systemd/system/jack.conf <<EOF
JACK_NO_AUDIO_RESERVATION=1
JACK_OPTS=-d alsa $AUDIO_DEVICE -r 44100 -p $BUFFER_SIZE
JACKTRIP_OPTS=-C $REMOTE_JACK_SERVER -n 1 --remotename $JOB_NAME
EOF
cat > /etc/systemd/system/jackd.service <<EOF
[Unit]
Description=jackd
After=sound.target
[Service]
User=jacktrip
Type=simple
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
LimitRTTIME=infinity
EnvironmentFile=/etc/systemd/system/jack.conf
ExecStart=/usr/bin/jackd \$JACK_OPTS
Restart=always
RestartSec=2s
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/systemd/system/jacktrip.service <<EOF
[Unit]
Description=jacktrip
Requires=jackd.service
After=network.target jackd.service
[Service]
User=jacktrip
Type=simple
LimitRTPRIO=infinity
LimitMEMLOCK=infinity
LimitRTTIME=infinity
EnvironmentFile=/etc/systemd/system/jack.conf
ExecStartPre=jack_wait -w -t 5
ExecStart=/usr/bin/jacktrip \$JACKTRIP_OPTS
Restart=always
RestartSec=2s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable jackd.service
systemctl enable jacktrip.service
systemctl start jackd.service
systemctl start jacktrip.service
@Overemployed
Copy link
Author

To get the install.sh script to not hang, here are a few corrections... First is that the script should have the #!/bin/bash shebang as the first line. That makes sure the HERE documents work. The other 2 errors are inside the systemd unit file here docs. The $ needs to be \$ to escape the variable names (lines 32 and 54), so they are de-referenced inside the unit file from the environment file. What is happening when the script hangs is that jacktrip is starting with no command line options at all and not running in the background like a service is supposed to.

Thanks for the helpful tips. Updated the script.

@Fongoh-work
Copy link

i get the error "Job for jacktrip.service failed because the control process exited with error code.
See "systemctl status jacktrip.service" and "journalctl -xeu jacktrip.service" for details." when i ran the install.sh script. i changed the hostname to my IP. please advice

Screen Shot 2023-06-30 at 9 21 43 AM

@tatara-eth
Copy link

tatara-eth commented Oct 15, 2023

I'm at my wit's end with this setup. While the YouTube tutorials you provided were insightful, I'm still facing significant challenges.

Here's a breakdown of my situation:

I've set up a sound card on my PiKVM and another on my J1. I've connected the mic to the headphone jack and vice versa (following the color-coded example you provided with green & pink).

Initially, before plugging in any sound cards, I was able to listen to sound from my J1 PiKVM Web Interface from the HDMI cable. When I activated the sound card, the audio playback was routed through it instead of my HDMI. This meant I couldn't hear any playback from my PiKVM. However, I was able to transmit my voice from my Windows JackTrip Peer-to-Peer server to the PiKVM and then to the J1. But when I tried to adjust the settings to hear from the PiKVM web interface, I lost the ability to transmit my voice to the PiKVM and J1. It's like I can only have one or the other...

From what I can gather, the crux of the issue seems to be that PiKVM's Janus is using my sound card for audio playback. But when it does, it prevents jacktrip & jackd from starting since the hardware is already occupied by Janus.

Ideally, I'd like my HDMI to continue delivering audio playback from the J1 computer. But as soon as I plug in the sound cards, the HDMI audio output ceases. I still see the HDMI in my playback on my J1, but nothing goes to it. And if I default the HDMI still, even if I "test" the sound, the PiKVM doesn't hear anything from it.

I'm at a loss here. @Overemployed, when you set up your system, were you able to both receive playback and transmit through the mic using just the sound cards, without relying on HDMI?

For reference, my setup includes a PiKVM v4 Plus running Arch Linux PiKVM, while both the server and client operate on Windows.

Edit: Switched to using my Macbook instead of Windows, I plugged in and out my usb cards, and finally had a hw:1 instead of just hw:0.

Ensure jackd and jacktrip services are enabled and running using systemctl:
On the PiKVM,
bash
sudo systemctl enable jackd.service
sudo systemctl start jackd.service
sudo systemctl enable jacktrip.service
sudo systemctl start jacktrip.service
Start the JACK Daemon with the desired settings:

bash
jackd -d alsa -r 48000 -p 1024 -d hw:1,0
Connect to the JackTrip server on your MacBook:

bash
jacktrip -C [Server IP]
On your MacBook:
Open two terminal windows.

In the first terminal, start the JACK Daemon:

bash
jackd -d coreaudio -r 48000 -p 1024
In the second terminal, start the JackTrip server:

bash
jacktrip -S

Although it's working, I have to be really careful because it's using my integrated MacBook mic. There is no physical mute button which means I have to really make sure that I'm muted in chat. But so glad it worked. Was pulling my hair out for the last two-three days.

-- Edit 2 days in --
This is such a PITA. Every time I close the pikvm browser, I have to go and connect/disconnect the physical usb sound cards. And now the above scripts are even working in the sense that now when I run those scripts, audio from the HDMI isn't coming through and no microphone data is being transmitted.

@josephum
Copy link

josephum commented Dec 1, 2023

After the last pikvm upgrade, I tried to upgrade the jacktrip package and it is broken with the rtaudio dependency.
I saw that the repository has the old version of jacktrip with the new rtaudio.
https://archlinuxarm.org/packages/armv7h/jacktrip
Anyone tried a workaround?

@tatara-eth
Copy link

I'm getting the same issue. @josephum have you found a solution? I had to uninstall jacktrip to get sound back to my pikvm through HDMI, but now I can't use jacktrip.

@josephum
Copy link

josephum commented Dec 7, 2023

I'm getting the same issue. @josephum have you found a solution? I had to uninstall jacktrip to get sound back to my pikvm through HDMI, but now I can't use jacktrip.

Try to uninstall all the jack/jacktrip packages first:
pacman -Rscnd jack2 jacktrip njconnect jack-example-tools

Then go to package cache to rollback with the packages that worked before:
cd /var/cache/pacman/pkg/
pacman -U file:///rtaudio-5.2.0-2-armv7h.pkg.tar.xz
pacman -U file:///xdg-utils-1.1.3+45+g301a1a4-1-any.pkg.tar.xz
pacman -U file:///jacktrip-1:1.9.0-1-armv7h.pkg.tar.xz
pacman -U file:///jack2-1.9.22-1-armv7h.pkg.tar.xz
pacman -U file:///njconnect-1.6-3-armv7h.pkg.tar.xz
pacman -U file:///jack-example-tools-4-1-armv7h.pkg.tar.xz

Works here!

@Thonysmi
Copy link

I'm getting the same issue. @josephum have you found a solution? I had to uninstall jacktrip to get sound back to my pikvm through HDMI, but now I can't use jacktrip.

Try to uninstall all the jack/jacktrip packages first: pacman -Rscnd jack2 jacktrip njconnect jack-example-tools

Then go to package cache to rollback with the packages that worked before: cd /var/cache/pacman/pkg/ pacman -U file:///rtaudio-5.2.0-2-armv7h.pkg.tar.xz pacman -U file:///xdg-utils-1.1.3+45+g301a1a4-1-any.pkg.tar.xz pacman -U file:///jacktrip-1:1.9.0-1-armv7h.pkg.tar.xz pacman -U file:///jack2-1.9.22-1-armv7h.pkg.tar.xz pacman -U file:///njconnect-1.6-3-armv7h.pkg.tar.xz pacman -U file:///jack-example-tools-4-1-armv7h.pkg.tar.xz

Works here!

please what can i do if it a new installation.
i cannot downgrade because the old packages are not there so what can i do.
please i need an urgent resolution

@josephum
Copy link

Go to https://archlinuxarm.org/packages. Download and install the packages individually. Use the versions you see above

@Thonysmi
Copy link

Go to https://archlinuxarm.org/packages. Download and install the packages individually. Use the versions you see above

they do no has the old version in the site they only have the version 6

@josephum
Copy link

Go to https://archlinuxarm.org/packages. Download and install the packages individually. Use the versions you see above

they do no has the old version in the site they only have the version 6

Please check this archive http://tardis.tiny-vps.com/aarm/repos/2023/11/01/armv7h/extra/

@Skripturz
Copy link

Hey @Overemployed,

so I have a problem that I think you might be able to help me with and I would greatly appreciate if you can but pretty much I have a piKVM and I want to use the mic from my person local computer on my remote work computer. In the piKVM support chat I was informed about your Jacktrip running on piKVM and I wanted to know would your solution help me with this?

@anthonyolanre
Copy link

anthonyolanre commented Dec 13, 2023 via email

@Skripturz
Copy link

Hello I can help you do this.

On Wed, 13 Dec 2023 at 07:44, Skripturz @.> wrote: @.* commented on this gist. ------------------------------ Hey @Overemployed https://github.com/Overemployed, so I have a problem that I think you might be able to help me with and I would greatly appreciate if you can but pretty much I have a piKVM and I want to use the mic from my person local computer on my remote work computer. In the piKVM support chat I was informed about your Jacktrip running on piKVM and I wanted to know would your solution help me with this? — Reply to this email directly, view it on GitHub https://gist.github.com/Overemployed/f30db915ac5dcb0b3d17ea1b6310e5f2#gistcomment-4791309 or unsubscribe https://github.com/notifications/unsubscribe-auth/ANFZEJ3ZPIFQ76QZUYNIKKTYJFFDDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCNZUGU2DMNJUU52HE2LHM5SXFJTDOJSWC5DF . You are receiving this email because you commented on the thread. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

Hey @anthonyolanre

Thank you, I'm using a piKVM v4 plus. Im not sure how to get started, so far I've ordered the usb sound cards and 3.5mm audio jack cables. Is this jacktrip the answer to my issue? btw you can also reach me on discord with the same username :)

@guessmeguest
Copy link

i get the error "Job for jacktrip.service failed because the control process exited with error code. See "systemctl status jacktrip.service" and "journalctl -xeu jacktrip.service" for details." when i ran the install.sh script. i changed the hostname to my IP. please advice

Screen Shot 2023-06-30 at 9 21 43 AM

I have the same issue too. How can I fix this error?

@anthonyolanre
Copy link

anthonyolanre commented Dec 20, 2023 via email

@guessmeguest
Copy link

Thank you, that cleared the error. But, when run the jacktrip command it gives below error. any idea on how to fix it ? I made sure the variables are correct.

root@pikvm kvmd-webterm]# jackd -d alsa -r 48000 -p 1024 -d hw:1,0
jackdmp 1.9.22
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
Copyright 2016-2023 Filipe Coelho.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_inprocess.so'
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_internal_metro.so'
no message buffer overruns
no message buffer overruns
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_intime.so'
no message buffer overruns
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
Failed to connect to session bus for device reservation: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead

To bypass device reservation via session bus, set JACK_NO_AUDIO_RESERVATION=1 prior to starting jackd.

Audio device hw:1,0 cannot be acquired...
Cannot initialize driver
JackServer::Open failed with -1
Failed to open server

@Thonysmi
Copy link

Thonysmi commented Dec 24, 2023 via email

@Thonysmi
Copy link

Thonysmi commented Dec 24, 2023 via email

@Thonysmi
Copy link

Thonysmi commented Dec 24, 2023 via email

@Thonysmi
Copy link

Thonysmi commented Dec 24, 2023 via email

@anthonyolanre
Copy link

anthonyolanre commented Dec 24, 2023 via email

@Thonysmi
Copy link

Thonysmi commented Dec 24, 2023 via email

@tatara-eth
Copy link

tatara-eth commented Jan 10, 2024

I'm getting the same issue. @josephum have you found a solution? I had to uninstall jacktrip to get sound back to my pikvm through HDMI, but now I can't use jacktrip.

Try to uninstall all the jack/jacktrip packages first: pacman -Rscnd jack2 jacktrip njconnect jack-example-tools

Then go to package cache to rollback with the packages that worked before: cd /var/cache/pacman/pkg/ pacman -U file:///rtaudio-5.2.0-2-armv7h.pkg.tar.xz pacman -U file:///xdg-utils-1.1.3+45+g301a1a4-1-any.pkg.tar.xz pacman -U file:///jacktrip-1:1.9.0-1-armv7h.pkg.tar.xz pacman -U file:///jack2-1.9.22-1-armv7h.pkg.tar.xz pacman -U file:///njconnect-1.6-3-armv7h.pkg.tar.xz pacman -U file:///jack-example-tools-4-1-armv7h.pkg.tar.xz

Works here!

Thank you, this seemed to solve my issue!

Note: There was an issue installing the jacktrip package, so I had to dig into this archive you provided: http://tardis.tiny-vps.com/aarm/repos/2023/11/01/armv7h/extra/ and manually installed all the dependencies it needed before I could successfully install the older version of jacktrip. This process looked something like this:

1. Find a dependency that I'm missing:
wget http://tardis.tiny-vps.com/aarm/repos/2023/11/01/armv7h/extra/qt5-base-5.15.11+kde+r138-1-armv7h.pkg.tar.xz
2. Install dependency after the download is complete:
sudo pacman -U qt5-base-5.15.11+kde+r138-1-armv7h.pkg.tar.xz

This can look entirely different for you depending on the dependencies it's asking you to install. Once I've installed all the dependencies (even the dependencies that my jacktrip dependencies needed)... I then attempted to reinstall the jacktrip package.

Appreciate you, @josephum for providing that archive.

@837
Copy link

837 commented Jan 26, 2024

I hope this helps someone else as well.

I did all of the above, services are enable and I have a connection from peer, I can also connect the inputs and outputs through qjackctl on my macbook.
BUT, I had zero sound coming through, neither in nor output.

I finally figured it out: With my PiKVM v4 I needed to set the AUDIO_DEVICE setting in the jack.conf:
AUDIO_DEVICE=-d hw:1,0 to AUDIO_DEVICE=-d hw:0,0 <-- 0,0 instead 1,0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment