View previous topic :: View next topic |
Author |
Message |
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 512
|
Posted: Mon Jun 24, 2024 6:36 pm Post subject: [Solved] ALSA audio routing |
|
|
Hi folks
I've just converted a computer that I use every day from Fedora to Gentoo. I'm running a pretty minimal system by modern standards -- no Gnome/KDE, no systemd, no pipewire/pulse. I use plain old ALSA for audio and most stuff works fine.
This computer has multiple audio devices. All the software I use provides a way to select the ALSA device but -- and this is the problem -- the method of doing this is different in every piece of software. Frankly, it's a bit of a nuisance.
I can set a default ALSA device in one of the ALSA config files. I can even keep a collection of files config files and symlink them to the ALSA config.
But I thought it might be nice if I didn't have to. What I'm looking for is a utility that lists the known ALSA devices, and then sets the user-selected one as the default. It would just write defaults into a config file. Of course, this won't give me a way to change output devices on the fly, as pipewire does; but I don't really have a need to do that.
I think I could probably throw something together in a few hours, but I can't help thinking that such a utility must already exist. I'm aware that most people don't use raw ALSA any more, but we did exactly that for about fifteen years. Somebody must surely have implemented a default ALSA switcher in that time?
If anybody knows of such a thing, feel free to share. Thanks.
BR, Lars.
Last edited by lars_the_bear on Wed Jun 26, 2024 8:37 am; edited 1 time in total |
|
Back to top |
|
|
ormorph n00b
Joined: 18 Jun 2024 Posts: 27
|
Posted: Mon Jun 24, 2024 8:51 pm Post subject: |
|
|
Have you tried this? Run asoundconf-gtk and select the device, the file ~/.asoundrc will be created, works for the user. You need to log in again. Just install this ebuild with patches into the local overlay and install. Works via GUI. |
|
Back to top |
|
|
Chiitoo Administrator
Joined: 28 Feb 2010 Posts: 2726 Location: Here and Away Again
|
Posted: Tue Jun 25, 2024 11:59 am Post subject: |
|
|
Don't know of an existing thing like that, but would creating specific PCMs for specific applications to use work?
Or do you often change what device you use for what? _________________ Kindest of regardses. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 512
|
Posted: Tue Jun 25, 2024 12:12 pm Post subject: |
|
|
Chiitoo wrote: | Don't know of an existing thing like that, but would creating specific PCMs for specific applications to use work?
Or do you often change what device you use for what? |
I didn't know it was possible to set specific pcms for applications. I mean, most applications have a command-line switch or menu option to change the device; I'd prefer not to have to do this for all applications.
When my laptop is docked, I like music to play through my USB dock. When it's not, I would prefer it to play through headphones. So it's not really an application issue, but a docked/undocked issue. But even when docked, sometimes I want the web browser to use the USB DAC (Spotify) and sometimes headphones (Zoom).
Honestly -- this seems such a common requirement, that it would surprise me if nothing were implemented. The asoundconf-gtk mentioned by @ormorph kind-of works, but it picks up ALSA devices as separate cards, which is a bit odd. But it produces a load of syntax error messages, which might be relevant.
BR, Lars. |
|
Back to top |
|
|
ormorph n00b
Joined: 18 Jun 2024 Posts: 27
|
Posted: Tue Jun 25, 2024 1:52 pm Post subject: |
|
|
lars_the_bear wrote: | The asoundconf-gtk mentioned by @ormorph kind-of works, but it picks up ALSA devices as separate cards, which is a bit odd. But it produces a load of syntax error messages, which might be relevant.
|
Although it cursed, it still worked as it should. I added a patch, now the swearing on escape symbols is gone. You can re-download and install asoundconf. |
|
Back to top |
|
|
Chiitoo Administrator
Joined: 28 Feb 2010 Posts: 2726 Location: Here and Away Again
|
Posted: Tue Jun 25, 2024 3:59 pm Post subject: |
|
|
lars_the_bear wrote: | I didn't know it was possible to set specific pcms for applications. I mean, most applications have a command-line switch or menu option to change the device; I'd prefer not to have to do this for all applications. |
I first had in mind something like, create a PCM in '.asoundrc' for each device, then just set the program use that device via means of said program.
After your reply, I did remember, or at least I though I remembered that there is a way to start applications so that they use a specific one (probably via command-line), but I couldn't quite find what I was remembering.
I did find something [1] over at stackoverflow, which seems quite nice actually, and I think I will use it myself for some things.
This solution uses environment variables to set the PCM. Using that post as an example, I can now set which recording device I want to use by default like so (especially useful for things that don't support ALSA at all, and only show 'default' (<cough> CEF <cough>)):
Code: | pcm.!default
{
type asym
playback.pcm loopAndReal
capture.pcm
{
type asym
@func getenv
vars [ DEF_DEV ]
default loopRecord
}
hint
{
show on
description "das defaults"
}
}
|
Then I run the program either normally, and it uses the 'loopRecord' PCM, run it 'DEF_DEV="somePCM" program' and it uses 'somePCM' instead.
Still need to run via a the command-line, or a wrapper, but at least I feel it's more nice than re-defining the defaults via external means (also just need to restart the application).
Aside from that, JACK comes to mind, but then it's not plain ALSA any longer.
1. https://stackoverflow.com/a/17107500 _________________ Kindest of regardses. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 512
|
Posted: Wed Jun 26, 2024 8:35 am Post subject: |
|
|
Thanks for the suggestions. In the end, I just hacked something up in Java. It only took an hour.
The problem with anything that already exists is that it's likely not to work with modern Python/Perl/GTK/whatever. For all it's faults, Java is forever
BR, Lars. |
|
Back to top |
|
|
ormorph n00b
Joined: 18 Jun 2024 Posts: 27
|
Posted: Wed Jun 26, 2024 6:49 pm Post subject: |
|
|
lars_the_bear wrote: | The problem with anything that already exists is that it's likely not to work with modern Python/Perl/GTK/whatever. For all it's faults, Java is forever
|
Nothing is eternal, everything moves in a spiral. Here is an example of a program in pytde for capturing video from the screen (wrapper for ffmpeg). But it would seem that something based on kde3 is already dead. However this works on python-3.12. But there’s nothing you can do about it, there’s nowhere to be without witchcraft these days |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5071 Location: Bavaria
|
Posted: Wed Jun 26, 2024 7:07 pm Post subject: |
|
|
ormorph wrote: | [...] Here is an example of a program in pytde [...] |
Are you sure you have used the correct link ? It gives me a "ouput.mp4" file ... ? (I have not checked if it is really a mp4). _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
|
ormorph n00b
Joined: 18 Jun 2024 Posts: 27
|
Posted: Wed Jun 26, 2024 7:16 pm Post subject: |
|
|
pietinger wrote: | Are you sure you have used the correct link ? It gives me a "ouput.mp4" file ... ? (I have not checked if it is really a mp4). |
Of course, this video shows how capture and compression works, it's just a video stitched together from two files. If you are interested in the source code, you can view it here. |
|
Back to top |
|
|
|