Skip to content

Instantly share code, notes, and snippets.

@coreymwamba
Last active September 18, 2016 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymwamba/b0d1cb75f843de02a9efd3768ac96e40 to your computer and use it in GitHub Desktop.
Save coreymwamba/b0d1cb75f843de02a9efd3768ac96e40 to your computer and use it in GitHub Desktop.
This is a simple script that brings up a Yad interface when I plug in my USB audio card. The interface then activates JACK. JACK is then killed when I remove the card. You won't be able to do this for a normal user through Udev, since it is a root process. This script is run from the autostart section of my window manager (JWM).
#!/bin/bash
#you will need to modify the device names for JACK...
choose_params() {
qy=$(yad --form --item-separator="|" --field "Purpose:CB" "CD|Live|HD")
jackparams=$(echo $qy | awk -F '|' '{print $1}')
case $jackparams in
CD)
jackd -dalsa -r44100 -p4096 -n3 -D -dhw:Device &
export JACK_SAMPLE_RATE=44100
export JACK_SETTING="REC"
;;
HD)
jackd -dalsa -r48000 -p4096 -n3 -D -dhw:Device &
export JACK_SAMPLE_RATE=48000
export JACK_SETTING="HD"
;;
Live)
jackd -R P88 -dalsa -r96000 -p64 -n2 -s -S -D -dhw:Device &
export JACK_SAMPLE_RATE=48000
export JACK_SETTING="LIVE"
;;
esac
}
while true; do
inotifywait -m /dev/snd/ -e create -e delete | while read dir action card; do
#this could probably be better implemented to work on a wider range of systems
if [ $card == "controlC1" ]; then
if [ $action == "CREATE" ]; then
sleep 2
choose_params
elif [ $action == "DELETE" ];then
pkill -9 jackd
unset JACK_SAMPLE_RATE
unset JACK_SETTING
fi
fi
done
done
@coreymwamba
Copy link
Author

You may be wondering about the sample rate numbers. This script was written for my system and a cheap Xenta Sound Pocket.

No matter what I don't record at 96kHz because it REALLY doesn't matter. Our ears can theoretically perceive frequencies up to around 22kHz; and Nyquist still applies. If the sample rate is higher than about 50kHz, you're recording things that cannot be heard and may not be perceived. If your sound "is better" at 96kHz it's because all the distortion that you were getting at lower sample rates has been pushed into a frequency range that you cannot hear. The quality of the hardware that is more important than the sample rate. There will (of course) be people who say "no, but [fill in anecdote showing how much of an audiophile they are here]" but belief is a powerful thing that drives us all to odd conclusions.

But the sound card I have has lower latency when I trick it into duplexing at 96kHz. This makes it much better for live looping and audio processing.

If the numbers upset you, just change the numbers to suit you.

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