Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Gentoo Chat
  • Search

pure ALSA, send audio to TV through HDMI in one command

Opinions, ideas and thoughts about Gentoo. Anything and everything about Gentoo except support questions.
Post Reply
  • Print view
Advanced search
4 posts • Page 1 of 1
Author
Message
towel1
n00b
n00b
Posts: 12
Joined: Thu Dec 25, 2025 3:45 pm
Location: Brazil

pure ALSA, send audio to TV through HDMI in one command

  • Quote

Post by towel1 » Sat Jan 10, 2026 3:13 pm

hey guys

yesterday I finally got audio working everywhere, by using ALSA exclusively (no PulseAudio, no PipeWire).
I recompiled Firefox with USE pulseaudio, using apulse[sdk] as dependency, and it is working alright so far

this is my current .asoundrc:

Code: Select all

$ cat .asoundrc
defaults.pcm.!card Generic
defaults.pcm.!device 0
defaults.ctl.!card Generic
it works with earbuds and without on my laptop.

then I connected to TV through HDMI, and audio would play at my laptop rather than my TV!! terrible

so I did some digging, and if I changed my .asoundrc to this, it would work:

Code: Select all

$ cat .asoundrc
defaults.pcm.!card Generic_1
defaults.pcm.!device 7
defaults.ctl.!card Generic_1
however. editing .asoundrc is a PITA, so I wrote the following two files in my $HOME directory:

Code: Select all

$ cat .asoundrc.m4
defaults.pcm.!card CARD
defaults.pcm.!device DEVICE
defaults.ctl.!card CARD
$ cat Makefile
here:
	m4 -DCARD=Generic -DDEVICE=0 .asoundrc.m4 > .asoundrc

tv:
	m4 -DCARD=Generic_1 -DDEVICE=7 .asoundrc.m4 > .asoundrc
so when I want audio to be on TV, I simply run "make tv" and audio goes to TV. when I want audio back to my laptop, I run "make here"

what do you think? is there a saner, more automatic way to handle this? perhaps using a GUI with buttons?
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Sat Jan 10, 2026 8:21 pm

That's one of the reasons sound servers exist. The other and more important is their ability to route audio from one software to another.

If the thing you built woks, and you're happy with the result, there's little reason to change it though. I guess you could hotkey your scripts to make them more convenient to use. Or maybe link them with acpid or something to swap the configs when HDMI connection comes up or goes down.
Make Pipewire a system service
Top
Navar
Guru
Guru
Posts: 422
Joined: Mon Aug 20, 2012 4:10 am
Location: usa

Re: pure ALSA, send audio to TV through HDMI in one command

  • Quote

Post by Navar » Sun Jan 11, 2026 3:49 am

towel1 wrote:what do you think? is there a saner, more automatic way to handle this? perhaps using a GUI with buttons?
Sanity is subjective. :)

What you've done is fine, if it's fine for you. If you want automatic without involving dbus event message passing and linux sound server bloat with associated caveats, then the very simple way to do it is to write a udev rule for when your HDMI was added or removed, accordingly, to trigger your respective scripts. All that functionality should already be installed there on your end.

A "GUI with buttons" is not an automatic way of doing anything, short of a control button assignment "launcher" to have you call one script to toggle the condition A/B. But yes, easily done. Kept my sanity vs trackpad interference except when I expressly wanted it active, vs any fancy attempts to assist on delayed enable when typing or palm rest triggering. Those QOL items never worked so great, so the manual valve to quickly enable/disable the firehose switch so to speak, is an example I had done. And now that I've suddenly got a sensitive trackpad twice as wide as before... (yes I use tmux,(n)vim, and Vimium browser plugin, what made you ask? :lol: )

Anyway, this is very lightweight and desktop/window manager agnostic, especially if you use neither (e.g., headless). The beauty of ALSA is/was that it just generally works, in a direct manner, once you've got it lightly configured for your needs with very little overhead.

I suppose you could also utilize inotify on sysfs to check for changes as well as an alternative.

If you do just want the turnkey solution as others may assume, latency issues and other confusion a real possibility, then you can just allow the defaults to roll with almost any standard modern media supported desktop and they will likely pull in pulseaudio/pipewire unless you -use fight to exclude. If you go this route, try to stay within their interesting constraints, rather than doing your own thing, or you'll likely run into more headaches.

If you're planning to use Steam and same to stream the A/V feed, then you'll definitely want to fight with a sound server, as my limited attempts have not found a way around getting it to effectively use ALSA feeds to 'sink' towards that other target across the network. It obviously counts on utilizing those with their closed code. I haven't tried real hard either, but semi-noticable latency sound skips can sometimes be irritating when they occur. You'll also want to consider how much control you give these things vs their authors suggested demands, such as real time priority vs your other processes.

If you use Steam locally and nothing more, you won't need those sound servers either, no matter what the outside voices tell you. It will still work fine, as will most of your other audio ALSA backend programs.
(I don't speak for/represent my current/past employers)
Top
Chiitoo
Ninja Apprentice
Ninja Apprentice
User avatar
Posts: 3059
Joined: Sun Feb 28, 2010 5:36 pm
Location: Sore wa sore, kore wa kore... nanoda.

  • Quote

Post by Chiitoo » Sun Jan 11, 2026 12:11 pm

I suppose one could use an environment variable to choose the default.

A snippet of what I have:

Code: Select all

pcm.!default
{
        type asym
        playback.pcm
        {
                type asym
                @func getenv
                vars [ DEFAULT_DEVICE ]
                default loopAndReal
        }
}
With this, can run an application like so to change the 'playback.pcm' without edits:

Code: Select all

DEFAULT_DEVICE="hw:1" speakertest -t wav -c 2
Not really much different in this case, but perhaps one advantage could be, that the configuration file maybe doesn't need to be re-read by applications if they are already running.
Kindest of regardses.
Top
Post Reply
  • Print view

4 posts • Page 1 of 1

Return to “Gentoo Chat”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic