Bug 68286 - Support toggling speaker and headphone port output, whilst keeping headphones plugged in
Summary: Support toggling speaker and headphone port output, whilst keeping headphones...
Status: RESOLVED NOTABUG
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-19 18:06 UTC by Raman Gupta
Modified: 2013-12-12 20:07 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Output of alsa-info.sh (38.24 KB, text/plain)
2013-08-19 18:06 UTC, Raman Gupta
Details
Output of `pactl list` (21.95 KB, text/plain)
2013-11-21 01:16 UTC, Raman Gupta
Details

Description Raman Gupta 2013-08-19 18:06:14 UTC
Created attachment 84277 [details]
Output of alsa-info.sh

I have my 5.1 speaker system plugged in two the Front and Rear Line out jacks on my Intel HDA (motherboard-based) sound card.

I also have my headphones (with mic) plugged in to another jack (successfully retasked to a Headphone jack via a module "patch" command), and a mic jack. My headphones are dedicated, and remain plugged in always.

However, I would like to switch between headphone output for activities like conference calls and the speakers for normal computer use, and listening to music.

Currently, PulseAudio seems to provide no mechanism for this. The only way to do this, as per @patrakov on IRC (thanks for the help!) currently appears to be to use the Auto-Mute control for the hardware in alsamixer (http://imagebin.org/268107). The relevant settings, with PulseAudio as it is now, seem to be:

1) Auto-Mute Enabled, Headphone Mute: Output on speakers.
2) Auto-Mute Enabled, Headphone Unmuted: Output on speakers and headphones.
3) Auto-Mute Disabled, Headphone Unmuted: Output on headphones.

Here is the startup debug log of PulseAudio: http://pastebin.com/UAMWV5x3

I have attached the output of alsa-info.sh.

It would be great if PulseAudio can be used to switch the output to my headphones, to my speakers, and optionally to both.
Comment 1 Raymond 2013-08-22 01:16:43 UTC
http://www.intel.com/support/motherboards/desktop/sb/CS-034206.htm


to enable multi streaming, you have to use hints indep_hp=true

instead of retasking line in as another headphone

need the conference application allow you to select alt analog playback device 

http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/plain/Documentation/sound/alsa/HD-Audio.txt


Hint Strings
~~~~~~~~~~~~
The codec parser have several switches and adjustment knobs for
matching better with the actual codec or device behavior.  Many of
them can be adjusted dynamically via "hints" strings as mentioned in
the section above.  For example, by passing `jack_detect = no` string
via sysfs or a patch file, you can disable the jack detection, thus
the codec parser will skip the features like auto-mute or mic
auto-switch.  As a boolean value, either `yes`, `no`, `true`, `false`,
`1` or `0` can be passed.

The generic parser supports the following hints:


- indep_hp (bool): provide the independent headphone PCM stream and
  the corresponding mixer control, if available


http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/plain/Documentation/sound/alsa/HD-Audio-Controls.txt

* Independent HP
  When this enum control is enabled, the headphone output is routed
  from an individual stream (the third PCM such as hw:0,2) instead of
  the primary stream.
Comment 2 Raymond 2013-08-22 15:31:23 UTC
: [pulseaudio] module-alsa-card.c: Found 4 jacks.

I: [pulseaudio] alsa-util.c: Successfully attached to mixer 'hw:0'

D: [pulseaudio] module-alsa-card.c: Jack 'Front Headphone Jack' is now unplugged

D: [pulseaudio] device-port.c: Setting port analog-output-headphones to status no

D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.

D: [pulseaudio] module-alsa-card.c: Jack 'Headphone Jack' is now plugged in

W: [pulseaudio] module-alsa-card.c: Availability of port 'analog-output-headphones' is inconsistent!






ode 0x1a [Pin Complex] wcaps 0x40058f: Stereo Amp-In Amp-Out
  Control: name="Headphone Playback Switch", index=1, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Headphone Jack", index=0, device=0
  Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
  Amp-In vals:  [0x00 0x00]
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x0000373c: IN OUT HP Detect
    Vref caps: HIZ 50 GRD 80 100
  Pin Default 0x0181305f: [Jack] Line In at Ext Rear
    Conn = 1/8, Color = Blue
    DefAssociation = 0x5, Sequence = 0xf
  Pin-ctls: 0xc0: OUT HP VREF_HIZ
  Unsolicited: tag=02, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 5
     0x0c 0x0d 0x0e 0x0f 0x26*
Node 0x1b [Pin Complex] wcaps 0x40058f: Stereo Amp-In Amp-Out
  Control: name="Headphone Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Front Headphone Jack", index=0, device=0
  Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
  Amp-In vals:  [0x00 0x00]
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x0001373c: IN OUT HP EAPD Detect
    Vref caps: HIZ 50 GRD 80 100
  EAPD 0x2: EAPD
  Pin Default 0x02214c20: [Jack] HP Out at Ext Front
    Conn = 1/8, Color = Green
    DefAssociation = 0x2, Sequence = 0x0
  Pin-ctls: 0xc0: OUT HP VREF_HIZ
  Unsolicited: tag=01, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 5
     0x0c 0x0d 0x0e 0x0f 0x26*
Comment 3 Raman Gupta 2013-08-22 17:12:43 UTC
(In reply to comment #1)
> http://www.intel.com/support/motherboards/desktop/sb/CS-034206.htm
> 
> to enable multi streaming, you have to use hints indep_hp=true

Ah interesting. Raymond, do you want me to try this and see if PA behaves differently?

> instead of retasking line in as another headphone
> 
> need the conference application allow you to select alt analog playback
> device 

Can you provide a link to this? I googled but could not find anything relevant. Is this a PA utility?
Comment 4 Raymond 2013-08-23 06:06:44 UTC
in addition to disable automute , you need is change pulseaudio do not mute front, surround, center and lfe in


http://cgit.freedesktop.org/pulseaudio/pulseaudio/plain/src/modules/alsa/mixer/paths/analog-output-headphones.conf
Comment 5 Raymond 2013-08-23 12:50:25 UTC
if webrtc, audacity and aplay -L use snd_device_name_hint to get list of playback and capture devices

just add device 2 for alt analog playback and capture device of desktop using hda intel


HDA-Intel.pcm.frontpanel.0 {
	@args [ CARD ]
	@args.CARD {
		type string
	}
	slave.pcm {
		type hw
		card $CARD
          device 2
	}
}
Comment 6 Raman Gupta 2013-10-16 00:02:46 UTC
I added indep_hp=true. I don't see any difference.

I don't see any device 2 control, but to be honest I don't really understand what to do.

Here is the output of aplay -l and aplay -L with the indep_hp=true.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC898 Analog [ALC898 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC898 Digital [ALC898 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
default
    Default ALSA Output (currently PulseAudio Sound Server)
sysdefault:CARD=PCH
    HDA Intel PCH, ALC898 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    Front speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Digital
    IEC958 (S/PDIF) Digital Audio Output
Comment 7 Raymond 2013-10-16 01:13:52 UTC
how did you add the hint ?

use early patching 

or

hda_generic.c


int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
				  struct auto_pin_cfg *cfg)
{
	struct hda_gen_spec *spec = codec->spec;
	int err;
+
+       /* for HDA codecs support 7.1+2  */
+       if ((cfg->line_outs == 4) && (cfg->hp_outs == 1))
+             spec->indep_hp = 1;

	parse_user_hints(codec);




http://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/plain/Documentation/sound/alsa/HD-Audio.txt



Early Patching
~~~~~~~~~~~~~~
When CONFIG_SND_HDA_PATCH_LOADER=y is set, you can pass a "patch" as a
firmware file for modifying the HD-audio setup before initializing the
codec.  This can work basically like the reconfiguration via sysfs in
the above, but it does it before the first codec configuration.

A patch file is a plain text file which looks like below:

------------------------------------------------------------------------
  [codec]
  0x12345678 0xabcd1234 2

  [model]
  auto

  [hint]
  indep_hp = true
------------------------------------------------------------------------

The file needs to have a line `[codec]`.  The next line should contain
three numbers indicating the codec vendor-id (0x12345678 in the
example), the codec subsystem-id (0xabcd1234) and the address (2) of
the codec.  The rest patch entries are applied to this specified codec
until another codec entry is given.  Passing 0 or a negative number to
the first or the second value will make the check of the corresponding
field be skipped.  It'll be useful for really broken devices that don't
initialize SSID properly.

The `[model]` line allows to change the model name of the each codec.
In the example above, it will be changed to model=auto.
Note that this overrides the module option.


The hd-audio driver reads the file via request_firmware().  Thus,
a patch file has to be located on the appropriate firmware path,
typically, /lib/firmware.  For example, when you pass the option
`patch=hda-init.fw`, the file /lib/firmware/hda-init.fw must be
present.

The patch module option is specific to each card instance, and you
need to give one file name for each instance, separated by commas.
For example, if you have two cards, one for an on-board analog and one 
for an HDMI video board, you may pass patch option like below:
------------------------------------------------------------------------
    options snd-hda-intel patch=on-board-patch,hdmi-patch
------------------------------------------------------------------------
Comment 8 Raman Gupta 2013-10-17 00:05:28 UTC
Thanks Raymond, I added indep_hp via early patching and now I do have a second "alt analog" device 2:

$  aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC898 Analog [ALC898 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC898 Digital [ALC898 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 2: ALC898 Alt Analog [ALC898 Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I am confused about comment #5 however. Where is this configuration supposed to go? It looks like alsa configuration and I added it to /etc/asound.conf but as far as I can tell it didn't change anything.
Comment 9 Raymond 2013-10-17 04:53:26 UTC
if the application use  snd_device_name_hint and snd_device_name_get_hint to obtain the device name

http://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html

it is possible to add for the alt analog device 2 for hda-intel

as you also have alt analog capture device and alt analog playback device for the front audio panel

http://git.alsa-project.org/?p=alsa-lib.git;a=tree;f=src/conf/pcm;hb=HEAD






you can get all hint when you turn on defaults.namehin.showall or show extended hint when you turn on defaults.namehint.extended 


http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=src/conf/alsa.conf;hb=HEAD
Comment 10 Raman Gupta 2013-10-18 03:19:30 UTC
Raymond, I'm sorry I don't understand comment #9. All the applications I use, such as KDE, Chrome and Skype simply send audio to PulseAudio. There are no "device selections" in any of these applications as far as I can tell.

With the indep_hp setting, I am able to switch between speakers and headphones by using alsamixer to change the card hardware controls:

amixer -c 1 sset 'Speaker' 100                                                                                                                                                                                                                                                               
amixer -c 1 sset 'Headphone',1 0    

But is there a way to tell PulseAudio to do the above?
Comment 11 Tanu Kaskinen 2013-10-28 15:58:54 UTC
Toggling between speakers and headphones should be trivial (in theory) by just changing the sink port. But before going into more detail, could you attach the output of "pactl list"?
Comment 12 Raymond 2013-10-28 23:41:00 UTC
[    4.077762] ALSA sound/pci/hda/hda_intel.c:3742 0000:00:1b.0: Applying patch firmware 'hda-jack-retask.fw'
[    4.077773] snd_hda_intel: probe of 0000:01:00.1 failed with error -2
[    4.077776] snd_hda_intel: probe of 0000:02:00.1 failed with error -2


seem bug of hda-jack-retask which modify hda codec of two hda controllers
Comment 13 Raman Gupta 2013-11-21 01:16:49 UTC
Created attachment 89550 [details]
Output of `pactl list`

I have attached the output of `pactl list` as requested.
Comment 14 Tanu Kaskinen 2013-11-22 17:22:03 UTC
If I have understood correctly, there are two problems:

1. The headphone jack detection isn't working properly (it's showing up as "unavailable" even when the headphones are plugged in).

2. Pulseaudio doesn't really support using the headphones and speakers at the same time.

In the ideal work the alsa driver or pulseaudio (whichever is to blame) would be fixed to make the jack detection work, and a feature would be added to pulseaudio to make simultaneous output work out-of-the-box. I don't have time to work on either.

If I understood correctly, you primarily would like to have an easy way to switch between the headphones and the speakers, and secondarily you would like to have an easy way to enable output to both at the same time. I may have a workaround for the first goal:

Switching to headphones (two commands):

    pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo+input:analog-stereo

    pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo analog-output-headphones


Switching to speakers (two commands):

    pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-surround-40+input:analog-stereo

    pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-surround-40 analog-output

(In the last command the right port might also be "analog-output-speaker" instead of "analog-output", but I'm not sure if it really makes a difference anyway.)

Does that work?
Comment 15 Raman Gupta 2013-11-22 22:50:32 UTC
(In reply to comment #14)
> If I have understood correctly, there are two problems:
> 
> 1. The headphone jack detection isn't working properly (it's showing up as
> "unavailable" even when the headphones are plugged in).

Yes, that seems to be the case.

> 2. Pulseaudio doesn't really support using the headphones and speakers at
> the same time.

Switching rather than using both simultaneously is more important to me, but yes.

> In the ideal work the alsa driver or pulseaudio (whichever is to blame)
> would be fixed to make the jack detection work, and a feature would be added
> to pulseaudio to make simultaneous output work out-of-the-box. I don't have
> time to work on either.

Yes, that would be ideal.

> If I understood correctly, you primarily would like to have an easy way to
> switch between the headphones and the speakers, and secondarily you would
> like to have an easy way to enable output to both at the same time. I may
> have a workaround for the first goal:

The first goal is what I am primarily interested in.

> Switching to headphones (two commands):
> 
>     pactl set-card-profile alsa_card.pci-0000_00_1b.0
> output:analog-stereo+input:analog-stereo
> 
>     pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo
> analog-output-headphones

Running the above two commands results in no output at all. Either to my headphones or to my speakers (sound stops after the first command, and the second does not restore it).

> Switching to speakers (two commands):
> 
>     pactl set-card-profile alsa_card.pci-0000_00_1b.0
> output:analog-surround-40+input:analog-stereo
> 
>     pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-surround-40
> analog-output

This restores sound as it was before.

> (In the last command the right port might also be "analog-output-speaker"
> instead of "analog-output", but I'm not sure if it really makes a difference
> anyway.)
> 
> Does that work?

No. See above.
Comment 16 Raman Gupta 2013-12-12 19:34:55 UTC
(In reply to comment #14)
> If I understood correctly, you primarily would like to have an easy way to
> switch between the headphones and the speakers, and secondarily you would
> like to have an easy way to enable output to both at the same time. I may
> have a workaround for the first goal:
> 
> Switching to headphones (two commands):
> 
>     pactl set-card-profile alsa_card.pci-0000_00_1b.0
> output:analog-stereo+input:analog-stereo
> 
>     pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo
> analog-output-headphones
> 
> 
> Switching to speakers (two commands):
> 
>     pactl set-card-profile alsa_card.pci-0000_00_1b.0
> output:analog-surround-40+input:analog-stereo
> 
>     pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-surround-40
> analog-output
> 
> (In the last command the right port might also be "analog-output-speaker"
> instead of "analog-output", but I'm not sure if it really makes a difference
> anyway.)
> 
> Does that work?

Yes, it does work with analog-output-speaker in the second command!

I think I simply had the headphones and rear speakers plugged into the wrong ports.

Thank you very much!
Comment 17 Raman Gupta 2013-12-12 20:07:33 UTC
Specifically, this is what seems to work perfectly with my setup in order to have audio on either the speakers or the headphones, but not both:

Switch to speakers:

#!/bin/sh
amixer -c 1 sset "Auto-Mute Mode" Disabled
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-surround-40+input:analog-stereo
pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-surround-40 analog-output-speaker
amixer -c 1 sset 'Speaker' 100
amixer -c 1 sset 'Headphone',1 0

Switch to headphones:

#!/bin/sh
# Leave Auto-Mute Mode on Disabled for output headphones + speakers
amixer -c 1 sset "Auto-Mute Mode" 'Line Out+Speaker'
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo+input:analog-stereo
pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo analog-output
amixer -c 1 sset 'Speaker' 0
amixer -c 1 sset 'Headphone',1 100


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.