script for quick switch between audio interfaces via commandline
Moderators: MattKingUSA, khz
-
- Established Member
- Posts: 5
- Joined: Thu Sep 26, 2019 11:38 pm
script for quick switch between audio interfaces via commandline
So I switch so much back and forth between my usb audio interface and my internal soundcard (when I take my laptop elsewhere), it gets a little tedious managing all the settings manually (in cadence) whenever I switch.
A slightly better step would be to create two separate rooms in claudia and switch between loading those. But I'm wondering, is there a way of switching between audio devices in the command line? Haven't had success with this but have put much effort into doing so. Any insights would be greatly appreciated, thanks
p.s. would be fine to use claudia to switch 'rooms' if I could do so from the terminal, but as far as I'm aware this is not a feature and claudia takes no arguments when run in the command line
A slightly better step would be to create two separate rooms in claudia and switch between loading those. But I'm wondering, is there a way of switching between audio devices in the command line? Haven't had success with this but have put much effort into doing so. Any insights would be greatly appreciated, thanks
p.s. would be fine to use claudia to switch 'rooms' if I could do so from the terminal, but as far as I'm aware this is not a feature and claudia takes no arguments when run in the command line
- bluebell
- Established Member
- Posts: 1910
- Joined: Sat Sep 15, 2012 11:44 am
- Location: Saarland, Germany
- Has thanked: 111 times
- Been thanked: 116 times
Re: script for quick switch between audio interfaces via commandline
AFAIK jackd's audio interface can't be changed on the fly. So you have to restart jack, e.g. with a shell script.alignwaivers wrote:So I switch so much back and forth between my usb audio interface and my internal soundcard (when I take my laptop elsewhere), it gets a little tedious managing all the settings manually (in cadence) whenever I switch.
A slightly better step would be to create two separate rooms in claudia and switch between loading those. But I'm wondering, is there a way of switching between audio devices in the command line? Haven't had success with this but have put much effort into doing so. Any insights would be greatly appreciated, thanks
p.s. would be fine to use claudia to switch 'rooms' if I could do so from the terminal, but as far as I'm aware this is not a feature and claudia takes no arguments when run in the command line
Linux – MOTU UltraLite AVB – Qtractor – http://suedwestlicht.saar.de/
- Linuxmusician01
- Established Member
- Posts: 1526
- Joined: Mon Feb 23, 2015 2:38 pm
- Location: Holland
- Has thanked: 756 times
- Been thanked: 137 times
Re: script for quick switch between audio interfaces via commandline
I made a shell script for personal use on my various Linux machines. Maybe it's almost what you mean. You can find it here and it looks like this:
Code: Select all
┌─────────────────────────────────────┐
│ Audio menu │
└─────────────────────────────────────┘
Use ↑ and ↓ keys to select and Enter
to execute.
Jack audio daemon: start
: kill
Check Midi : port numbers
: output
Check Alsa : device/card numbers
Pulseaudio : start
: stop
: PAVUControl
Config file : create/edit
: delete
: view
Help
Exit
-
- Established Member
- Posts: 5
- Joined: Thu Sep 26, 2019 11:38 pm
Re: script for quick switch between audio interfaces via commandline
That's an awesome script! Thanks for sharing that
Unfortunately I am primarily interested in switching the master instead of restarting jack completely.
Do you know if that might be possible if you change the device based on the config file?
I found a useable solution (thanks to Falktx for pointing me in the right direction)
jack_control dps device "hw:USB,0" #(my audio interface)
jack_control sm
HERE's the new problem. I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
I hope to find a way to clear / reset jack's memory of the devices so when I plug in the NEW device my script tries to connect to that "hw:USB,0" and ignores the old one.
The only way I know how to do that now is by stopping jack
Unfortunately I am primarily interested in switching the master instead of restarting jack completely.
Do you know if that might be possible if you change the device based on the config file?
I found a useable solution (thanks to Falktx for pointing me in the right direction)
jack_control dps device "hw:USB,0" #(my audio interface)
jack_control sm
HERE's the new problem. I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
I hope to find a way to clear / reset jack's memory of the devices so when I plug in the NEW device my script tries to connect to that "hw:USB,0" and ignores the old one.
The only way I know how to do that now is by stopping jack
- Linuxmusician01
- Established Member
- Posts: 1526
- Joined: Mon Feb 23, 2015 2:38 pm
- Location: Holland
- Has thanked: 756 times
- Been thanked: 137 times
Re: script for quick switch between audio interfaces via commandline
I don't think that I know exactly what you want but I think that it's not possible. One cannot change between audio devices without restarting Jack I think.alignwaivers wrote:That's an awesome script! Thanks for sharing that
Unfortunately I am primarily interested in switching the master instead of restarting jack completely.
Do you know if that might be possible if you change the device based on the config file?
I found a useable solution (thanks to Falktx for pointing me in the right direction)
jack_control dps device "hw:USB,0" #(my audio interface)
jack_control sm
HERE's the new problem. I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
I hope to find a way to clear / reset jack's memory of the devices so when I plug in the NEW device my script tries to connect to that "hw:USB,0" and ignores the old one.
The only way I know how to do that now is by stopping jack
You might also try the commands that you already know w/ sound card names instead of sound card numbers. Like for instance:
Code: Select all
cat /proc/asound/cards
0 [CMI8738 ]: CMI8738-MC6 - C-Media CMI8738
C-Media CMI8738 (model 55) at 0xd000, irq 20
1 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xf7c10000 irq 45
Code: Select all
alsamixer -c "CMI8738"
Code: Select all
alsamixer -c "0"
- nikgnomicradio
- Established Member
- Posts: 109
- Joined: Wed Feb 07, 2018 9:31 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: script for quick switch between audio interfaces via commandline
Code: Select all
I am primarily interested in switching the master instead of restarting jack completely.
maybe if started JACK with dummy device, then alsa_in and alsa_out commands to load ALSA device
would that allow ALSA device to be removed and replaced later without disturbing JACK ?
if they are non-identical devices, the Vendor ID (vid) and Product ID (pid) numbers can be assigned to ALSA index numbersI switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
https://alsa.opensrc.org/MultipleUSBAudioDevices
-
- Established Member
- Posts: 2047
- Joined: Tue Feb 16, 2016 6:56 am
- Location: Kangasala, Finland
- Has thanked: 369 times
- Been thanked: 208 times
- Contact:
Re: script for quick switch between audio interfaces via commandline
Instead of alsa_in and alsa_out, jack_load could be used.nikgnomicradio wrote: maybe if started JACK with dummy device, then alsa_in and alsa_out commands to load ALSA device
would that allow ALSA device to be removed and replaced later without disturbing JACK ?
Linux veteran & Novice musician
Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: script for quick switch between audio interfaces via commandline
You can switch device while JACK is running using
You can if you're using jackdbus. Does jack_control do anything if you're using jackd?
@alignwaivers there must be a unique identifier for each card. If you do you'll get the card indexes which you can use as hw:<x> rather than the name of the card.
Code: Select all
jack_control dps device hw:<x>
jack_control sm
@alignwaivers there must be a unique identifier for each card. If you do
Code: Select all
aplay -l
-
- Established Member
- Posts: 5
- Joined: Thu Sep 26, 2019 11:38 pm
Re: script for quick switch between audio interfaces via commandline
thanks for the insights, the one issue is going by the hw:#, means you always have to plug audio devices in the same order.
Fortunately I found some good options for renaming the devices https://jackaudio.org/faq/device_naming.html
and also a completely separate solution: https://github.com/SpotlightKid/
Fortunately I found some good options for renaming the devices https://jackaudio.org/faq/device_naming.html
and also a completely separate solution: https://github.com/SpotlightKid/
Re: script for quick switch between audio interfaces via commandline
With jack2 (jackdbus) you can change many things on the fly. Via jack_control as others have mentioned. The device, the sample rate, the bit width, and such. You can do similar things with pulseaudio via pacmd / pactl.
Another option would be the set everything up with alsa's loopback device (snd_aloop) and have two alsaloop's in the .bash_history to route that to the real devices. Although each layer adds a bit of latency. And alsaloop can be a bit unstable. To the point that I run it inside an infinite loop.
$ while true; do alsaloop -C hw:Loopback,1,0 -P pulse -t 50000; sleep 1; done
And kind of a lazy way to use jack on snd_aloop and route that to pulseaudio, if you're pulse is over a network, or you trust your jack configuration skills more than your pulseaudio skillset. The loopback device output is it's input, which would make it work for playback, not so much for capture. Although many apps that capture lets you explicitly select your input device(s).
Another option would be the set everything up with alsa's loopback device (snd_aloop) and have two alsaloop's in the .bash_history to route that to the real devices. Although each layer adds a bit of latency. And alsaloop can be a bit unstable. To the point that I run it inside an infinite loop.
$ while true; do alsaloop -C hw:Loopback,1,0 -P pulse -t 50000; sleep 1; done
And kind of a lazy way to use jack on snd_aloop and route that to pulseaudio, if you're pulse is over a network, or you trust your jack configuration skills more than your pulseaudio skillset. The loopback device output is it's input, which would make it work for playback, not so much for capture. Although many apps that capture lets you explicitly select your input device(s).