Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulseeffects doesn't apply preset when switching from speaker to headphones (headphone jack) #520

Closed
Utini2000 opened this issue May 29, 2019 · 27 comments

Comments

@Utini2000
Copy link

Hello again,

so far Pulseeffects switches it's settings/presets perfectly fine between:
Laptop Speakers
Sennheiser HD800S + DAC1 - via USB
Sennheiser HD600 + DAC2 - via USB

How ever, today I tried plugging some random VE Monk headphones in the headphone jack and pulseeffects doesn't switch automatically.
Pulseaudio is detecting that my output changed from speakers to headphones and also applies the last saved volume level. But pulseeffects doesn't?

Thanks!

@wwmm
Copy link
Owner

wwmm commented May 29, 2019

Headphones that are plugged in the sound card jack are treated in a different way by Pulseaudio. It took some time to realize how to support them. But they should work too in the latest PE versions. The procedure is the same. Plug it in the sound card so that they become the default output device and then select a preset that should be loaded the next time they are plugged in the system. If everything is fine a file for this headphone should be created in the folder ~/.config/PulseEffects/autoload/

@wwmm
Copy link
Owner

wwmm commented May 29, 2019

As an example when I plug a headphone in my sound card and do the procedure above this file is created alsa_output.pci-0000_0b_00.3.analog-stereo:analog-output-headphones.json

@Utini2000
Copy link
Author

Hmm I am on Archlinux with version 4.6.1-1.
My autoload folder only has three files (2x DAC + 1x speakers).
So it seems like it doesn't create an autoload file for my headphone via the headphone jack.

But no idea why.

Pulse audio shows me:
Speakers (Built-in Audio Analog Stereo)
Headphones (Built-in Audio Analog Stereo)

@wwmm
Copy link
Owner

wwmm commented May 29, 2019

Usually Pulseaudio creates a port in the soundcard for these kind of headphones. Plug this headphone and run the command pactl list sinks. It will show if Pulseaudio is creating this port

@Utini2000
Copy link
Author

Utini2000 commented May 29, 2019

pactl output
Sink #0
	State: SUSPENDED
	Name: alsa_output.pci-0000_00_1f.3.analog-stereo
	Description: Built-in Audio Analog Stereo
	Driver: module-alsa-card.c
	Sample Specification: s16le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 7
	Mute: no
	Volume: front-left: 48497 /  74% / -7,85 dB,   front-right: 48497 /  74% / -7,85 dB
	        balance 0,00
	Base Volume: 65536 / 100% / 0,00 dB
	Monitor Source: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
	Latency: 0 usec, configured 0 usec
	Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
	Properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "ALC285 Analog"
		alsa.id = "ALC285 Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "HDA Intel PCH"
		alsa.long_card_name = "HDA Intel PCH at 0x604b108000 irq 189"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:00:1f.3"
		sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
		device.bus = "pci"
		device.vendor.id = "8086"
		device.vendor.name = "Intel Corporation"
		device.product.id = "a348"
		device.product.name = "Cannon Lake PCH cAVS"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "384000"
		device.buffering.fragment_size = "192000"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		alsa.mixer_name = "Realtek ALC285"
		alsa.components = "HDA:10ec0285,17aa2267,00100002 HDA:8086280b,80860101,00100000"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	Ports:
		analog-output-speaker: Speakers (priority: 10000, not available)
		analog-output-headphones: Headphones (priority: 9000, available)
	Active Port: analog-output-headphones
	Formats:
		pcm

Sink #1
	State: SUSPENDED
	Name: PulseEffects_apps
	Description: PulseEffects(apps)
	Driver: module-null-sink.c
	Sample Specification: s16le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 28
	Mute: no
	Volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	        balance 0,00
	Base Volume: 65536 / 100% / 0,00 dB
	Monitor Source: PulseEffects_apps.monitor
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY 
	Properties:
		device.description = "PulseEffects(apps)"
		device.class = "sound"
		device.icon_name = "audio-card"
	Formats:
		pcm

Sink #2
	State: SUSPENDED
	Name: PulseEffects_mic
	Description: PulseEffects(mic)
	Driver: module-null-sink.c
	Sample Specification: s16le 2ch 44100Hz
	Channel Map: front-left,front-right
	Owner Module: 29
	Mute: no
	Volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	        balance 0,00
	Base Volume: 65536 / 100% / 0,00 dB
	Monitor Source: PulseEffects_mic.monitor
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY 
	Properties:
		device.description = "PulseEffects(mic)"
		device.class = "sound"
		device.icon_name = "audio-card"
	Formats:
		pcm

@wwmm
Copy link
Owner

wwmm commented May 30, 2019

I don't see a reason for this to be failing. In your soundcard we have Active Port: analog-output-headphones as expected. Kill the current PE instance pulseeffects -q and restart it in debug mode G_MESSAGES_DEBUG=pulseeffects pulseeffects. Now plug your headphone and try to associate a preset with it. On my computer something like this is printed in the terminal

presets_manager: added autoload preset file: /home/wallace/.config/PulseEffects/autoload/alsa_output.pci-0000_0b_00.3.analog-stereo:analog-output-headphones.json

Try to see if it prints nothing or a file with another name.

When you tried to do this was your soundcard(not the one in the usb) set as default device? Right now this feature only works for default devices. It is a limitation I am not sure how to overcome.

@Utini2000
Copy link
Author

Utini2000 commented May 30, 2019

Headphones plugged in + setting a preset:
(pulseeffects:11258): pulseeffects-DEBUG: 08:54:25.220: presets_manager: added autoload preset file: /home/sneida/.config/PulseEffects/autoload/alsa_output.pci-0000_00_1f.3.analog-stereo.json

Removed the headphones (speakers active) and set a preset:
(pulseeffects:11258): pulseeffects-DEBUG: 08:54:49.168: presets_manager: added autoload preset file: /home/sneida/.config/PulseEffects/autoload/alsa_output.pci-0000_00_1f.3.analog-stereo.json

So in both cases it will write it to the same .json file. In reality it should make two different .json files. One for my speakers, one for my headphone jack? :/
It is only one soundcard active (my laptops built in soundcard). I don't have any of the external DACs connected.

@wwmm
Copy link
Owner

wwmm commented May 30, 2019

Yes. In your case I would expect something like this alsa_output.pci-0000_00_1f.3.analog-stereo:analog-output-headphones. In other words the headphone active port would be appended after the sound card name.

I have only one explanation for this. For some bizarre reason Pulseaudio seems to be giving me a null active port. It is strange because pactl is not printing a null port. I think I will have to take a look at pactl source code and see how Pulseaudio devs are parsing this port value. But as far as I could see in Pulseaudio programming api it should be a simple string =/

@wwmm
Copy link
Owner

wwmm commented May 30, 2019

@Utini2000
Copy link
Author

Utini2000 commented May 31, 2019

Hmm weird. Well it doesn't bother me too much because I rarely use the headphone jack but it would still be nice to see it fixed and might also resolve the same problem for others :)

Let me know if I should provide any further debug/logs/testings... thats all I can do to help :(

@zetaPRIME
Copy link

I'm having a similar issue; I'm trying to use this to fix my GPD Win 2's speakers being out of phase, and while PE correctly detects whether the speakers or headphones are in use when opening the presets pane, it only actually switches when unplugging the headphones and not when plugging them in.

@wwmm
Copy link
Owner

wwmm commented Jun 5, 2019

It would be good to see what PE prints when this happens. Run pulseeffects -q and then G_MESSAGES_DEBUG=pulseeffects pulseeffects

@zetaPRIME
Copy link

No messages when plugging headphones in; removing headphones prints:

(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.167: new default sink: alsa_output.pci-0000_00_1f.3.analog-stereo
(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.167: sie: using output device: alsa_output.pci-0000_00_1f.3.analog-stereo
(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.167: presets_manager: autoloading preset Speakers for device alsa_output.pci-0000_00_1f.3.analog-stereo:analog-output-speaker
(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.218: presets_manager: loaded preset: /home/zetaprime/.config/PulseEffects/output/Speakers.json
(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.222: new default source: alsa_input.pci-0000_00_1f.3.analog-stereo
(pulseeffects:29177): pulseeffects-DEBUG: 14:15:53.222: soe: using input device: alsa_input.pci-0000_00_1f.3.analog-stereo

@wwmm
Copy link
Owner

wwmm commented Jun 6, 2019

It feels like Pulseaudio is not sending us notifications when the headphones are plugged. Only when they are removed. This may be a hardware dependent Pulseaudio bug. In my computer it emits the sink changed signal when the headphones are plugged =/

@zetaPRIME
Copy link

well, since the application gets the correct info when it actually checks, perhaps add an option to recheck every so often, with a configurable period?

@roospeteristvan
Copy link

I can confirm what zetaPRIME is experiencing on a Dell Latitude 5490 notebook, that is, PE only actually switches when unplugging the headphones and not when plugging them in.
Let me know how can I help with testing and debugging.

@wwmm
Copy link
Owner

wwmm commented Jun 10, 2019

I could do what @zetaPRIME suggested but I have to think if continually polling Pulseaudio like this could degrade performance. And it somehow feels like a last resort. I would like to be sure there is nothing else I can do before trying this.

@zetaPRIME and @roospeteristvan there is another test you can do. Open Pavucontrol with the headphones unplugged and go to the output devices tab. Pay attention to the port field. Now plug the headphones. Does Pavucontrol update the sound card port value to the headphone or you have to close and reopen it for this info to be shown? If Pavucontrol automatically updates the port value then the problem can be fixed in PE without polling Pulseaudio. Maybe by delaying the moment we ask about the port value. If it doesn't then there is definitely a Pulseaudio bug that should be reported to its developers.

@neekt
Copy link

neekt commented Jun 23, 2019

I've been having the same issue. PulseEffects recognises the switch from headphones to speakers, but not speakers to headphones.

@wwmm, I just tried as you suggested in pavucontrol, and the port field immediately changes from Speakers to Headphones (plugged in) when I plug the headphones in (i.e., no reopening required).

I use headphones a lot, so I'm happy to help to debug this in any way I can, just let me know!

@wwmm
Copy link
Owner

wwmm commented Jun 23, 2019

Interesting. When you plugged the headphone the output device was moved to the end of Pavucontrol list or did it stay in the same position? In my computer it is moved to the end. What suggests that Pulseaudio destroyed the sink and recreated it with another port. Maybe this is the reason why this feature is working on my hardware and not on others. Recreating the sink would cause a similar effect to change from one output device to another.

In any case I will delay the moment we ask about the headphone port state. Maybe Pulseaudio or the sound card need sometime to make the headphone port active.

@wwmm
Copy link
Owner

wwmm commented Jun 23, 2019

I have made some changes and now we wait for 3 seconds before auto loading presets. People on Arch Linux can use the aur package pulseeffects-git to test. Considering that somehow there is no issue on my hardware feedback will be important to fix this.

@wwmm
Copy link
Owner

wwmm commented Jun 23, 2019

Something is definitely odd in Pulseaudio. Sometimes it emits a signal telling that the speakers are the new default device when I plug the headphones and right after that it emits a signal telling the the headphone is the new default device. In the end things work but it makes no sense to do what Pulseaudio is doing. And it is totally random. Most of the time it emits only the headphone signal... In any case a delay should help to workaround this weird behavior...

@neekt
Copy link

neekt commented Jun 26, 2019

If I understand your question correctly, I only have the two output devices listed under port; speakers and headphones. Headphones are listed last in either case. I've attached screenshots of before and after plugging in the headphones, although I'm guessing it probably doesn't help much in this case.

Screenshot from 2019-06-26 12-08-40
Screenshot from 2019-06-26 12-09-18

I'm just using Linux Mint Cinnamon 19.1, so can't help you test with pulseeffects-git, sorry. Hopefully the 3 second delay fixes whatever PulseAudio oddities are causing the issue. Thanks for your efforts with this.

@wwmm
Copy link
Owner

wwmm commented Jul 6, 2019

After talking about this with Pulseaudio devs they suggested to open a new issue there about this https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/700. They would also like to see some advanced Pulseaudio logs when the headphone is plugged/unplugged. You can get these advanced logs as explained here https://github.com/wwmm/pulseeffects/wiki/Reporting-Bugs

@wwmm
Copy link
Owner

wwmm commented Jul 7, 2019

After some guidance from Pulseaudio developers I think I was able to rework this feature in a way that should work in every sound card. It would be good to have some feedback before the next release.

@wwmm
Copy link
Owner

wwmm commented Aug 4, 2019

I will assume 4.6.6 fixed this. If this is not the case reopen this issue.

@wwmm wwmm closed this as completed Aug 4, 2019
@roospeteristvan
Copy link

Hi @wwmm,
I've just tested version 4.6.6 and it works beautifully. Cheers!

@wwmm
Copy link
Owner

wwmm commented Aug 18, 2019

Good to know! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants