39

I'm running audio over HDMI to my receiver, which has a full 7.1 setup connected to it. However, most of the stuff that I listen to has far fewer channels—some is mono, most is stereo, a bit is 5.1. When the receiver is fed with the right number of channels, it has various DSP effects which work fairly well (e.g. in splitting out a center channel, in sending base to the subwoofer, auto-detecting Dolby matrix surround, etc.). This ceases working if you send it a full 7.1 signal with a bunch of silent channels.

The number of output channels in PulseAudio is configured, per-card/sink, by the profile assigned to the card. You can change the assigned profile with pacmd, pactl, and various GUI programs.

How can I set it up to automatically change the profile based on the channel usage in the input stream(s)? E.g., if the input streams are only using front-left and front-right, switch to the stereo profile. If they're using back-left and back-right as well, switch to quadrophonic, etc.

  • 3
    Maybe I'm wrong, but I don't think it is feasible at all. Pulseaudio manages multiple streams at once: which profile would be correct if different streams with different channel numbers are playing together? – Alessio Gaeta Aug 26 '15 at 10:14
  • @meden The one with the highest number of channels, I guess. – derobert Aug 26 '15 at 15:14
  • Yes, of course, but still there will be cases in which you could not achieve your goal. BTW, I do not think there is a way in Pulseaudio to conditionally switch a profile. Maybe the Kodi guide to Pulseaudio [kodi.wiki/view/PulseAudio] could be useful to have some hint (i.e. using passthrough and let your receiver do all the work, provided it supports all formats you use). – Alessio Gaeta Aug 27 '15 at 9:25
  • This is an interesting question. I don't have the audio setup available to test this, but as a work around, if you were to create profiles for each instance you envision, setup a script to analyze the streams in advance (perhaps by grepping the output of mediainfo or ffmpeg or avconv) and then use pacmd to select the appropriate profile prior to launching your player, From a logical standpoint I would expect it to work provided you were playing one audio at a time. – Elder Geek Dec 15 '16 at 22:42
  • 4
    It might be worth submitting this question as a feature request at launchpad.net/bugs/bugtrackers/pulseaudio-bugs if it has not already been submitted there. It would be an interesting feature and pulse audio could probably solve this better internally than by using an external script. – Alexander Jan 13 '17 at 14:07
1

This is just a concept and no complete solution:

You may be able to do your own handling of events with patcl subscribe if you can assign configurations to pulsaudio clients (e.g., if the movie player connects, you switch to 7.1 configuration, otherwise you use the stereo configuratioin). You will get a constant stream of events from patcl subscribe, which you can handle by observing client connections. Then you can just call pactl/pacmd to change the profile.

Example output of pactl subscribe:

$ pactl subscribe 
Event 'change' on sink #0
Event 'remove' on sink-input #93
Event 'change' on sink #0
Event 'change' on source #0
Event 'change' on sink #0
Event 'change' on source #0
Event 'new' on sink-input #98
Event 'change' on sink-input #98

Please note, that you still have the problem to handle cases in which you have multiple clients with a different number of channels.

Furthermore, the above approach is rather limited. The per application settings are not sufficient to detect the real number of used channels of the application (e.g. vlc might play a 5.1 or 7.1 video). I have not found a way to get the number actually used channels of an pulseaudio client over pactl, but I might have missed some options here. Alternatively, you might be also able to hook into the video player application itself and get the missing bits form there.

  • With pactl list | grep format.channels you should be able to find out the max. # of channels used (and more information as well). Using that information in a script triggered by subscribed events could lead to a solution. – ridgy Jan 7 '18 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.