4

As PulseAudio (amazingly) doesn't provide any simple query commands, I'm parsing the output from pacmd list-sinks to get the index of the active sink. However, I'm not sure what lines actually indicate which sink is active. I know that the index line has an asterisk in front of it if it's the default sink. That doesn't appear to be the same as the active sink, though. When I connect a bluetooth speaker, that's what all audio goes through, nevertheless, sink 0 is still marked as default. When audio is playing, the sink that is outputting it displays 'state: RUNNING'. But once playback stops, that goes back to SUSPENDED.

Is there any reliable way to find out what sink PulseAudio will use for audio?

3
  • Have you previously configured the bluetooth speaker as the sink for certain applications, using a tool such as pavucontrol? PulseAudio uses a module called stream-restore to "remember" some source-sink mappings, and this information isn't included in the output of pacmd list-sinks or ... dump.
    – JigglyNaga
    Oct 21, 2019 at 12:16
  • 1
    There's nothing that keeps multiple application from streaming to multiple sinks at the same time. So how do you define "the" active sink? You can use the associated .monitor sources of each sink to find the current level, just like pavucontrol, if that's what you want.
    – dirkt
    Oct 21, 2019 at 13:11
  • Thanks for the help! @dirkt I guess in that case my question would be how can I find out what sink or sinks PulseAudio is streaming to or will be streaming to once I start playback. However, I managed to find the solution for now by using list-sources instead of list-sinks. Oct 22, 2019 at 8:53

2 Answers 2

1

It seems I need to gain a greater understanding of the PulseAudio nomenclature. Listing sources marks the bluetooth speaker correctly as default. And since sources and sinks apparently share the same index, I can pass the index number extracted from pacmd list-sources to pactl set-sink-volume to change volume. Because pactl set-source-volume does nothing. I can't really make sense of it but it does work.

3
  • Not sure if I understand you correctly, but: "Sources" are audio sources you can record from, "sinks" are audio sinks you can play sound to. I wouldn't be surprised if Bluetooth always has a source, even if you only have connected speakers, if the underlying protocol works this way. The "default" marking just means that when you start a new application without stream-restore info, the application will use this source (for recording) or sink (for playing) by default, unless it decides otherwise. So what you are doing seems to work by accident, but very likely isn't correct.
    – dirkt
    Oct 22, 2019 at 9:44
  • Yeah, you are, of course, right. Guess, I really need to gain a greater understanding of the PulseAudio nomenclature. As it turned out, I had created a sink mapping or something similar earlier that I was unaware of. After clearing ~/.config/pulse, the Bluetooth speaker is correctly marked as default after connecting. So actually @JigglyNaga's initial comment was already pointing me in the right direction. Thank you both once more for your help. Oct 23, 2019 at 11:12
  • To repeat: I advise very strongly against drawing any conclusion about current use of sinks from the information which sink is "default". You keep saying "the Bluetooth speaker is correctly marked as the default sink". Thinking about it this way is a mistake. There is no "correct" or "incorrect" marking of the default sink - it's just the sink that gets used by default for a new application that doesn't have information about sinks preferred in the past.
    – dirkt
    Oct 24, 2019 at 8:02
0

For me the default sink seems to be the same as the active sink (at least it works for my toggle if I just switch defaults). I know it's not a direct answer, but I did have a snippet for getting the default sink which was useful for me:

pacmd list-sinks | awk '/\*/ {getline; print $2}' gets the default sink name. (with <> around it)

'/\*/ {getline; print $2}': This part is the awk command, the goal of this part is to get the active sink and get the name aswell.

/\*/ : This means awk will find lines that contain an asterisk (*). In the pacmd list-sinks output, the asterisk denotes the default sink (the currently active sound device).

{getline; print $2}: This is the operation awk performs once it finds a line containing an asterisk. getline fetches the next line after the match, and print $2 prints the second field (column) of this new line, separated by a whitespace, which is the active sink.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .