[pulseaudio-discuss] Routing of audio to loudspeakers or headphones

Colin Guthrie gmane at colin.guthr.ie
Tue Aug 24 01:25:01 PDT 2010

'Twas brillig, and Kim Therkelsen at 24/08/10 08:33 did gyre and gimble:
> Hi,
> I have made a LADSPA plugin that I want to apply for the PC loudspeakers
> only. I do not want to pass the audio through the LADSPA plugin when
> listening through headphones.
> How do I accomplish that?
> Normally when I load the plugin for testing I just use a command like this:
> load-module module-ladspa-sink sink_name=ladspa_out
> master=alsa_output.pci-0000_00_1b.0.analog-stereo plugin=myplugin
> control=1...
> If I could just enter a "master" that only pointed to the headphones it
> would solve my problem.

Hmm, tricky problem. I'm not sure that the current setup with ladspa
sinks really allows this.

I think that to do this, the actual sink created by the ladspa module
would have to be unloaded when a certain "port" was used by the sink it
connected to. This requires more smarts than it can currently cope with.

> If it is not possible then how do I detect in my LADSPA plugin if the
> headphones are connected? I assume there is some API that I can use?

Well, I think it would require rather a lot of hacking.

In theory, this is what you need to do (I think):

 Write a PA module that is similar to the ladspa one. When it specifies
a master sink to use, you can (in the PA module code) inspect the port
currently selected for that sink and get notifications when that port
changes. Your module could sit there and wait for the "headphone" port
to be activated on the sink and only then create the actual virtual
ladpsa sink.

At present the ladspa sink is created at module initialisation.

The way I look at it there are two choices:

 1. Modify module-ladspa-sink to have a "master_port" argument and make
it only create the virtual sink when the master sink's port matches the
argument value (and to unload it when it changes).
 2. Rewrite your ladspa plugin in PA using the git master virtual sink
as a basis for the code.

Even when this is all done, you will still not get everything working
100% perfectly just yet. Jack sensing is (apparently - not looked for a
while) a mess and does not work reliably on all drivers. We need to fix
that and probably will enable automatic port switching on jack status in
due course. But until this comes in, when you plug in your headphones,
you have to manually change the port in pavucontrol (labelled connector
in gnome tools).



Colin Guthrie

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

More information about the pulseaudio-discuss mailing list