nulleuro / apply-equalizer Goto Github PK
View Code? Open in Web Editor NEWpython programm that activates or deactivates pulseaudio-equalizer based on output port (headphones or speakers)
License: MIT License
python programm that activates or deactivates pulseaudio-equalizer based on output port (headphones or speakers)
License: MIT License
Context: plug a jack into a sound output.
Expected: equalizer changes once
Observed: equalizer changes back and forth many times between setup for "nothing plugged in" and "something plugged in". Can be tens of times for a duration of possibly one minute.
Reproducible: sometimes, hardware-dependent. Happens on my main working machine, a laptop less than two years old.
Comments:
A perfect jack sensor would only send one and only one event on jack plug/unplug.
A real sensor sometimes "bounces". This indeed is a hardware issue.
When the programs reacting to it act quickly, it's not really an issue. For example, xfce4-volumed automatically adjusts volume level depending on active output. When problem occurs one just sees volume slide back and forth quickly and that's all.
But apply-equalizer is much longer to appy settings. Events get queued. When bounces trigger tens of events, queue can take a long time to drain and appear like an endless loop.
Some times, the script fails at start and outputs this:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 175, in activate_name_owner
return self.get_name_owner(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 361, in get_name_owner
's', (bus_name,), **keywords)
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.PulseAudio1': no such name
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./apply-equalizer.py", line 70, in <module>
'org.PulseAudio1', '/org/pulseaudio/server_lookup1')\
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 241, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 248, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 180, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 278, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.PulseAudio1 was not provided by any .service files
Running the script again doesn't change anything.
Logging out and in, it then succeeds.
Perhaps a bug in pulseaudio's module-dbus-protocol
?
Symptom:
./apply-equalizer.py
load dbus-module into PA
27
cannot look up address!
cannot look up address!
cannot look up address!
cannot look up address!
cannot look up address!
cannot look up address!
Goes on forever, about one line per second.
Ctrl-C does not kill process.
Manual kill with PID quits.
Running process again -> same failure.
pulseaudio -k
then running again -> works
./apply-equalizer.py
load dbus-module into PA
17
Got pa-server address from dbus: unix:path=/run/user/1000/pulse/dbus-socket
Disabling persistence...
Current operation: saving configuration (disable-config)
-------------------------------------
Equalizer setting saved (disable-config).
-------------------------------------
Disabling...
PulseAudio Equalizer/LADSPA Processor 2.7 (05/02/2010)
-------------------------------------
Current operation: disabling equalizer
-------------------------------------
Unloading & reloading stream-restore module...
Unloading module-ladspa-sink...
Moving active PulseAudio clients to ALSA sink (alsa_output.pci-0000_00_1b.0.analog-stereo)...
Transferring current mute (0) & volume (45%) to ALSA sink (alsa_output.pci-0000_00_1b.0.analog-stereo)...
-------------------------------------
Equalizer status: [disabled]
Equalizer configuration status: [disabled]
-------------------------------------
connected to pulseaudio
After disconnect bluetooth headset - system set defaul output (not LADSPA).
For various reasons it is desirable to be able to run software as non-root. Example reasons: having several variants available for different users (e.g. developer using unstable version vs regular users wanting something less powerful that just works, or even the same user depending on time), systems where administrator cannot not approve that change quickly enough (security, policy, whatever).
Currently, this could mean that when
dbus.connection.Connection(srv_addr)
fails with
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /run/user/1000/pulse/dbus-socket: No such file or directory
The script automatically adds
load-module module-dbus-protocol
to the user's ~/.config/pulse/default.pa
after checking that it's not already there ?
pa_config_path = os.path.join(xdg_config_home, 'pulse', 'default.pa')
with open(pa_config_path, "a") as pa_config_fh:
pa_config_fh.write("load-module module-dbus-protocol\n")
Checking to avoid duplicates is important else we break pulseaudio for the user...
Currently the user has to manually run the script.
Let's figure out how to have it run at login time.
This may be more or less desktop-environment dependent (I'm using XFCE on Ubuntu.) but thanks to freedesktop.org there's probably a common way.
My first guess: look in /etc/xdg/autostart/
and add something there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.