Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] ALSA audio routing
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Mon Jun 24, 2024 6:36 pm    Post subject: [Solved] ALSA audio routing Reply with quote

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
View user's profile Send private message
ormorph
n00b
n00b


Joined: 18 Jun 2024
Posts: 27

PostPosted: Mon Jun 24, 2024 8:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
Chiitoo
Administrator
Administrator


Joined: 28 Feb 2010
Posts: 2730
Location: Here and Away Again

PostPosted: Tue Jun 25, 2024 11:59 am    Post subject: Reply with quote

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
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Tue Jun 25, 2024 12:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
ormorph
n00b
n00b


Joined: 18 Jun 2024
Posts: 27

PostPosted: Tue Jun 25, 2024 1:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
Chiitoo
Administrator
Administrator


Joined: 28 Feb 2010
Posts: 2730
Location: Here and Away Again

PostPosted: Tue Jun 25, 2024 3:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Wed Jun 26, 2024 8:35 am    Post subject: Reply with quote

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
View user's profile Send private message
ormorph
n00b
n00b


Joined: 18 Jun 2024
Posts: 27

PostPosted: Wed Jun 26, 2024 6:49 pm    Post subject: Reply with quote

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 :D
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5118
Location: Bavaria

PostPosted: Wed Jun 26, 2024 7:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
ormorph
n00b
n00b


Joined: 18 Jun 2024
Posts: 27

PostPosted: Wed Jun 26, 2024 7:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum