bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
680 stars 69 forks source link

Allow specifying application name in PulseAudio context creation #81

Closed flying-sheep closed 4 years ago

flying-sheep commented 4 years ago

Hi, I’m using the audio visualizer panon. Panon uses this project to grab audio data from a monitor of the current output.

My desktop, KDE Plasma, shows a little microphone symbol when something is using a microphone or monitor. Hovering it while panon is running says “audio is using the microphone”*, with the “audio” part being pretty confusing, and possibly scary for people using panon.

I grepped your source code to find out that you hardcode this string in your _PulseAudio backend class:

https://github.com/bastibe/SoundCard/blob/08cb467a6421c2cdf273fe55c4f1f5b9303d8d5b/soundcard/pulseaudio.py#L66

Could you please make it configurable so applications using this project can tell PulseAudio their name? Optimally this would mean that multiple contexts can be created, but using pa_context_set_name for the global context is probably sufficient for most applications.

*The fact that using a microphone symbol and message is wrong when using a monitor is besides the point here, but tracked in KDE bug 410637 if anyone is interested

bastibe commented 4 years ago

We hat multiple contexts for a while, but they caused problems. Apparently, pulse can get rather unstable if too many contexts are created. So we'll have to make do with a single context for now.

Would you like to create a pull request for changing the context name with a global function? I am a bit weary of including new features if they are only implemented in one platform, but you have to start somewhere.

Alternatively, it might be possible to implement this in your own code, by adding a the pa_context_set_name manually with an additional _ffi.cdef and re-opening _ffi.dlopen('pulse') before using the library.

flying-sheep commented 4 years ago

Panon directly imports and uses the pulseaudio backend, so I wasn’t aware that there’s an abstraction. Sure, I can try my hand at it!