Automatically switch equalizer preset based on audio output (internal speaker or external)
The facts below come from experience with Ubuntu 13.10 on a 64-bit laptop.
Context/problem: bad speakers
As many people know, laptop speakers have "highly unequal frequency response" as audio professional would say. Normal people say: "they sound very bad".
First-step solution: equalization
Equalizing provides a valuable workaround, dramatically improving sound quality with a one-time effort. For example, I installed PulseAudio Equalizer from Web Upd8.
For good results, equalization values should be chosen based on measurements, but that's another story (I could do it with Ubuntu alone though it's tricky, ask me for details).
Remaining problem: equalization curve is output-dependent
Equalization values are attached to the whole chain, though generally only the speakers are a major source of unequal response.
This means I have two equalization profiles:
- one for laptop speakers (with wildly varying equalization curve)
- another (much flatter curve, so disabling equalization is often acceptable) when an external stereo is plugged to e.g. a 3.5mm jack.
Current situation in practice: auto un/mute, good but insufficient
- When plugging the 3.5mm jack to the external stereo, internal speakers are automatically muted and volume adjusted by the Ubuntu stack. This is good but insufficient.
- When unplugging, internal speakers are automatically activated again. This is good but insufficient.
Improvement: not only auto-mute but auto-select eq curve
It would be much better to have the correct equalizer preset applied when un/plugging the 3.5mm jack. Plug the external stereo, the flat curve is selected. Unplug the stereo, internal speaker get their correction curve.
Questions
How to make a quick-and-dirty hack ? How to detect jack plug from a script ?
Regarding detecting the plugging event. I could not find documentation on the web, plus the keyword "jack" returns results regarding the jack software suite, irrelevant here. Meager starting points: sound - How to automatically change volume level when un-/plugging headphones? - Ask Ubuntu Jack detection for audio : Blueprints : Ubuntu
Regarding changing the equalizer curve I could not find any documentation about
pulseaudio-equalizer-gtk
. A proof-of-concept script fiddling with files then callingpulseaudio-equalizer interface.applysettings
could change the settings, but the GUI wouldn't be aware.
How to make a clean setup: assign the equalization curve to internal speaker, not just plug event.
For example, say I plug a USB audio device and play audio through it. The quick-and-dirty hack would change EQ curve whenever the 3.5mm jack is un/plugged, though the audio actually continued to go to the USB audio device not the internal speaker, making eq curve change irrelevant.
In a "clean" setup, an equalization profile would be cleanly assigned to the internal speaker, making the thing more robust. Whatever the situation, it would be always (and only) applied when needed.
Is anyone working on it ? Any hint ?
Thank you for your attention.
Because I have a similar problem i have made a "quick and dirty" python script which uses pulseaudio's DBus-Events to detect when to activate which equalizer profile.
Installation
To use it you have to add the following line to /etc/pulse/default.pa:
load-module module-dbus-protocol
Then disable the equalizer via pulseaudio-equalizer-gtk and click on "Apply settings", now close the GUI.
Download apply-equalizer.py save it somewhere and make it executable.
Execute it as user (!). Maybe you need to install some additional python modules. Also you may want to automatically start it on login (i dont know what is the best way to do that).
Usage
The script creates per-port [1] equalizer-configurations under ~/.config/apply-equalizer and symlinks them if a device changes the output port (i.e. headphones plugged in or out).
[1]: many sound cards have different ports, e.g. one speaker-port and one headphone-port
So:
- Unplug headphones.
- Open pulseaudio-equalizer GUI
- Customize equalizer-settings until it sounds good
- "Apply Settings" will then assign the configuration you made (including if the equalizer is enabled at all) to the current port (speakers in this case)
- close the GUI and repeat from step 2 for every port you want to assign (headphones not plugged in)
Now the equalizer settings get automatically adjusted whenever your switch between speakers and headphones.
Here a manual solution to switch between Equalizor ON (with your favorite settings) and OFF:
if [ "$(pulseaudio-equalizer status | grep "Equalizer status" | cut -d"[" -f2 | cut -d"]" -f1)" == "enabled" ]; then
pulseaudio-equalizer disable
else
pulseaudio-equalizer enable
fi
Save as a file as a bash script, create a new panel starter to by able to start the script directly from desktop or your menu panel.