therealmuffin / synchronator

Synchronator brings bit perfect volume control to Hi-Fi systems with Linux as source.
GNU General Public License v3.0
12 stars 3 forks source link

`pulseaudio` support #11

Closed nbrownus closed 5 years ago

nbrownus commented 5 years ago

Curious if you have any thoughts on supporting this functionality within pulseaudio.

My personal goal is to get the system level volume to control and display the correct volume for my receiver.

therealmuffin commented 5 years ago

Hello NBrownus,

No, I haven't thought about that. But it's an interesting thought.

Have you got any idea on how that could work (I'm not a pulseaudio user, so I have no knowledge besides the basic concept)? For example, how would that work with the multiple sources? Perhaps we can let Synchronator trigger on volume changes on one of those sources, wouldn't it be annoying that would also lower the volume for other sources as well?

Regards, Maarten

nbrownus commented 5 years ago

Yeah I've gone fairly far down the rabbit hole on this. There are three methods that I can see and they all have their pros and cons.

  1. A PulseAudio plugin that intercepts volume function calls to the active sink. I implemented this with two FIFOs. One for volume changes within pulse to affect the receiver and another for volume changes on the receiver to affect pulse. It's hacky and weird because it just literally slams itself in there and you need to restart pulse or your system if you want to undo it.

  2. A PulseAudio plugin that is implemented as a virtual sink in a sink chain and works more or less like option 1 but less destructively. I'm no linux audio expert and I'm not sure what this does to the audio streams in terms of latency or configurability. The one thing this has going for it is the PulseAudio mailing list offered this as a good solution to someone looking for this back in 2008.

  3. Use the control= configuration option on the module-alsa-sink PulseAudio module. This solution is basically identical to yours. Create a dummy control device on your alsa card, tell PulseAudio to control that instead of the master volume control. This seems like the least weird solution, the problem being that on my computers I actually use the module-alsa-card module that creates a sink and does not expose the control= configuration parameter. I will shoot a PR over to them this weekend though, and folks can use it in a few years on distros like Ubuntu...

I've mostly written the code for all three solutions and more or less duplicated synchronator for my use case (denon AVR over serial), I don't have the issues I ran into at the moment but I do recall some segfaulting while trying to get synchronator to work.

therealmuffin commented 5 years ago

Thanks for the overview, a couple of questions: 1) I see the cons of solution 1 and 2. However, I don't see the pros are of these first two solutions compared to 3. Option 3 seems quite clean and the least intrusive. Why even consider those first two options? 2) From what I understand, with module-alsa-sink, gives you the solution you want without changing any code. Is that correct? 3) Why do you use module-alsa-card instead of module-alsa-sink?

therealmuffin commented 5 years ago

I'm closing this issue. From what I understand there is a clean solution that doesn't require any coding (option 3). If there's a case in enhancing Synchronator to significantly improve PulseAudio support, I'm more than willing to take a look at it, but based on the above, I don't see it.