Page 1 of 1
script for quick switch between audio interfaces via commandline
Posted: Thu Sep 26, 2019 11:46 pm
by alignwaivers
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
Re: script for quick switch between audio interfaces via commandline
Posted: Fri Sep 27, 2019 5:47 am
by bluebell
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
AFAIK jackd's audio interface can't be changed on the fly. So you have to restart jack, e.g. with a shell script.
Re: script for quick switch between audio interfaces via commandline
Posted: Fri Sep 27, 2019 10:23 am
by Linuxmusician01
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
Re: script for quick switch between audio interfaces via commandline
Posted: Mon Oct 14, 2019 11:59 pm
by alignwaivers
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
Re: script for quick switch between audio interfaces via commandline
Posted: Tue Oct 15, 2019 12:04 pm
by Linuxmusician01
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
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.
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
And then:
Instead of:
Re: script for quick switch between audio interfaces via commandline
Posted: Sun Oct 20, 2019 10:25 pm
by nikgnomicradio
Code: Select all
I am primarily interested in switching the master instead of restarting jack completely.
do not see how you can switch out system device that is part of the command to start JACK without restarting
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 ?
I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
if they are non-identical devices, the Vendor ID (vid) and Product ID (pid) numbers can be assigned to ALSA index numbers
https://alsa.opensrc.org/MultipleUSBAudioDevices
Re: script for quick switch between audio interfaces via commandline
Posted: Mon Oct 21, 2019 6:50 am
by tavasti
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 ?
Instead of alsa_in and alsa_out, jack_load could be used.
Re: script for quick switch between audio interfaces via commandline
Posted: Mon Oct 21, 2019 1:28 pm
by merlyn
You
can switch device while JACK is running using
Code: Select all
jack_control dps device hw:<x>
jack_control sm
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.
Re: script for quick switch between audio interfaces via commandline
Posted: Sun Oct 27, 2019 12:24 pm
by alignwaivers
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/
Re: script for quick switch between audio interfaces via commandline
Posted: Sat Jul 18, 2020 5:19 pm
by Shadow_7
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).