Audio output error if I reboot with speaker plugged into headphone jack - (solved)

Moderators: 666philb, Forum moderators

Post Reply
mow9902
Posts: 178
Joined: Fri Jul 24, 2020 11:57 pm
Has thanked: 13 times
Been thanked: 51 times

Audio output error if I reboot with speaker plugged into headphone jack - (solved)

Post by mow9902 »

I am using Fossapup64 F96 on a Dell Latitude. All is working perfectly including sound with pulseaudio.

In the pulseaudio volume control window it lists 3 output options:

  • Speakers

  • Headphones

  • Line Out

Context:
I often use an external audio conference speaker which plugs into the Headphone jack.

  • If I boot the machine without this speaker connected, the system rightly assigns the audio output to "Speakers" and sound works fine.

  • If I then plug the speaker into the headphone jack, the system rightly updates, and assigns the audio output to "Headphones" and sound works fine.

However - if I reboot the machine leaving the speaker plugged in, the system assigns the audio ouput to "Speakers" and before the sound can be heard I have to either:

  • manually open pulseadio volume control and select "Headphones" -or

  • manually unplug the speaker, and then replug it.

I would like to create a small script which will test for the presence of the Headphones and set the audio output accordingly.
What file can I interrogate to find this information?

I'm thinking my script would look something like this:

Code: Select all

audiodevice=<test some condition>

if [ $audiodevice == "Headphones" ]; then
	pactl set-sink-port 0 analog-output-headphones
else
	pactl set-sink-port 0 analog-output-speaker
fi

Can anyone help please?

Never mind - managed to work it out for myself. This works for me:

Code: Select all

headphones=`amixer contents | grep -A 2 numid=4 | grep values=on | tail -c 3`
echo "headphones=$headphones"

if [ $headphones == "on" ]; then
	echo "headphone is connected"
	pactl set-sink-port 0 analog-output-headphones
else
	echo "headphone not connected"
	pactl set-sink-port 0 analog-output-speaker
fi

# turn on volume button
pactl set-sink-mute  @DEFAULT_SINK@ 0
# set volume to 50%
pactl set-sink-volume @DEFAULT_SINK@ 50%
User avatar
MochiMoppel
Posts: 1117
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: Audio output error if I reboot with speaker plugged into headphone jack - (solved)

Post by MochiMoppel »

mow9902 wrote: Thu Mar 07, 2024 2:52 am

Never mind - managed to work it out for myself. This works for me:

Congratulations! Unfortunately doesn't work for me and I suspect that this is HW dependent.
In FP96 I can see in the volume control that the headphones are plugged, and the display changes when they are plugged out

volume_control.png
volume_control.png (28.11 KiB) Viewed 140 times

However I see no reference of this action in amixer:

Code: Select all

# amixer contents
numid=4,iface=MIXER,name='Master Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
numid=3,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
  : values=29274,29274
numid=2,iface=MIXER,name='Capture Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
numid=1,iface=MIXER,name='Capture Volume'
  ; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
  : values=65536,65536

The output is the same, regardless if headphones are plugged or not. I wonder if there is a way to include the headphone status in the amixer contents

[EDIT] Never mind - I too figured it out myself. Apparently I have to specify the card :oops: :

Code: Select all

# amixer -c 0 contents
numid=40,iface=CARD,name='Front Headphone Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off
numid=36,iface=CARD,name='Front Mic Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off
numid=38,iface=CARD,name='Line Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off
numid=39,iface=CARD,name='Line Out Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off
numid=37,iface=CARD,name='Rear Mic Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off
numid=41,iface=CARD,name='SPDIF Phantom Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=on
numid=35,iface=MIXER,name='Master Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
  ...
  <snip>
  
mow9902
Posts: 178
Joined: Fri Jul 24, 2020 11:57 pm
Has thanked: 13 times
Been thanked: 51 times

Re: Audio output error if I reboot with speaker plugged into headphone jack - (solved)

Post by mow9902 »

:thumbup: Yep - you got it.

Post Reply

Return to “Fossapup64”