Author Topic: Mono headphone output?  (Read 3735 times)

defunked

  • Newbie
  • *
  • Posts: 24
    • View Profile
Mono headphone output?
« on: July 23, 2018, 12:06:27 pm »
I have come across two audio related problems with Sailfish CE on the Gemini.  First, when headphones are plugged in to the device, the speakers continue to produce audio along with the headphone.  It is my understanding that the Gemini has a single stereo audio DAC, but I expected the OS/driver to switch the output path from the speakers/amplifier to the headphones, when the headphones are inserted.  In addition, the headphone are mono, along with the speakers..  That is certainly not right.  I know the speakers are mono (and apparently phase inverted), but my understanding was that this hardware bug did not apply to the headphone jack.  Has any one else noticed this behavior?

Bluetooth audio sending works fine.

vader

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
Mono headphone output?
« Reply #1 on: July 23, 2018, 05:28:50 pm »
Quote from: defunked
I have come across two audio related problems with Sailfish CE on the Gemini.  First, when headphones are plugged in to the device, the speakers continue to produce audio along with the headphone.  It is my understanding that the Gemini has a single stereo audio DAC, but I expected the OS/driver to switch the output path from the speakers/amplifier to the headphones, when the headphones are inserted.  In addition, the headphone are mono, along with the speakers..  That is certainly not right.  I know the speakers are mono (and apparently phase inverted), but my understanding was that this hardware bug did not apply to the headphone jack.  Has any one else noticed this behavior?

Bluetooth audio sending works fine.

I thought I was the only one who had this - due to my tinkering with trying to get SDL audio to work. The sound should automatically switch to headphones when they are inserted, but on mine (and apparently yours) they don't. Most fixes I found online involve using alsamixer to set the automute, although I can only see the master volume. On a positive, I have a command that will fix this, and I am writing an app (learning QML) which will do it in a friendly way. To get headphone output only (in stereo), you change the pulseaudio output port with (type in thumbterm or whatever terminal you use):

pactl set-sink-port output-wired_headphone

This routes the audio to the headphones. To set it back to the speakers, type:

pactl set-sink-port output-speaker

I'm sure there is a setting somewhere to control the automute, but I can't find it. I am still learning about Sailfish, but I do love that you *can* actually change things when they aren't right. For example, I added my SD card to /etc/fstab so it automounts when I reboot. I am still playing with the sound, and maybe I will find a proper fix, but until then, at least you can listen via headphones


NOTE: If you don't set the port back after listening, then all sound will go to the headphones - alerts, ringtones etc! You won't hear the phone ringtone from the speakers, even when you unplug them.
« Last Edit: July 23, 2018, 05:33:14 pm by vader »

vader

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
Mono headphone output?
« Reply #2 on: July 23, 2018, 10:59:52 pm »
I've been reading the mer porters pages and can confirm that the headphones do have a sense switch (/sys/devices/virtual/switch/h2w) which you can set up with dbus. I'm also looking for the silver button i/o so we can use it for things. I'll try to set them up tonight and if it is successful, I'll post the fix.

defunked

  • Newbie
  • *
  • Posts: 24
    • View Profile
Mono headphone output?
« Reply #3 on: July 24, 2018, 11:47:21 am »
Good to know it isn't a hardware problem with my particular unit.

I am still getting to know my way around Sailfish.  I tried to build the simple QML Hello World example, and can't seem to get it to run on the simulator.  I prefer to program in straight C, with a text editor and simple compiling scripts.  As such, build tools make my head spin.  I am used to writing GUI stuff in GTK+ so I don't have to mess around with C++, but I guess I am being pushed to into C++ land with sailfish.  Is it possible to skip QML and build a UI directly from C++ with QT?

I have been reluctant to mess around in /etc/ out of concern that changes will get over-written during an OS update.  Any idea what an OS update would over-write from that perspective?

Thanks for the information on pulse audio control.

vader

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
Mono headphone output?
« Reply #4 on: July 24, 2018, 06:05:32 pm »
Quote from: defunked
Good to know it isn't a hardware problem with my particular unit.

I am still getting to know my way around Sailfish.  I tried to build the simple QML Hello World example, and can't seem to get it to run on the simulator.  I prefer to program in straight C, with a text editor and simple compiling scripts.  As such, build tools make my head spin.  I am used to writing GUI stuff in GTK+ so I don't have to mess around with C++, but I guess I am being pushed to into C++ land with sailfish.  Is it possible to skip QML and build a UI directly from C++ with QT?

I develop on the gemini using vi (or if I feel lazy, tIDE). Have you installed openrepos? The app is called storeman and gives you access to third party apps/libs etc. You need to enable third party installs in the settings somewhere  I am a C programmer (linux embedded devices) who dabbles in lots of things. I am going to teach myself QML only so I can be a good citizen on sailfish


Quote from: defunked
I have been reluctant to mess around in /etc/ out of concern that changes will get over-written during an OS update.  Any idea what an OS update would over-write from that perspective?

If it is an incremental update (ie. pkcon refresh; pkcon update) then you should be ok. Burning new firmware will of course blot everything.

As far as headphones go, I added an accessories.ini to /etc/ohm/plugins.d which monitored the headphone socket. It works brilliantly when inserting the headphones, but doesn't seem to detect/do anything when they are removed. I will probably just write a shell inotify script which directly calls pactl.

andrewl

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Mono headphone output?
« Reply #5 on: July 25, 2018, 03:24:31 am »
Quote from: defunked
d.  In addition, the headphone are mono, along with the speakers..  That is certainly not right.  I know the speakers are mono (and apparently phase inverted), but my understanding was that this hardware bug did not apply to the headphone jack.  Has any one else noticed this behavior?

I don't think that problem is a Sailfish one, it's been reported with the shipped Android too.

vader

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
Mono headphone output?
« Reply #6 on: July 25, 2018, 06:26:57 pm »
Quote from: andrewl
I don't think that problem is a Sailfish one, it's been reported with the shipped Android too.

It could still be software, because if you set the pulseaudio port to output-speaker+wired_headphone, then you get mono from the headphones. This is how the system (at least mine) was set up. The speakers and headphones played at the same time. When you set the port to output-wired_headphones, you get stereo - and quite nice at that.

I tried to fix it the standard way by sending a uevent upon headphone insertion, which is picked up by pulse, but it didn't work properly. The insertion would stop the speakers and only play in the headphones, but removing the headphones didn't enable the speakers again. I'm not a pulseaudio guru, so after a bit of playing/searching, I gave up.

I wrote my own simple headphone switcher which does work - I will try to package it up for others to use. I compiled inotifywait and wrote a simple script which waits on /sys/class/switch/h2w/, then reads the state file when something changes. A value of 2 means headphones inserted (pactl set-sink-port output-wired_headphone), and 0 means not inserted (pactl set-sink-port output-speaker). Seems to work well, and doesn't use CPU (the wait sleeps until something changes in that directory). I'm sure a pulseaudio guru could get the proper behaviour working, but this works for now  I added the startup to droid-hal-startup.sh, as systemd doesn't do the usual (better) rc/rc.local thing.

I am a debian guy, and have to work out how to package the utility - but when I do, I'll post it here.