Cannot switch from front panel audio to back panel audio device

I have exactly the same problem on my PC (with GNOME desktop, but doesn’t change anything though) as the linked topic below.

I’ve read some related topics here: Manjaro: Unable to switch audiosource with headphones plugged in - Newbie Corner - Manjaro Linux Forum , and this solution using alsamixer seems promising to me, but I have no idea how to use the tool and detect where are my devices and how to make the same script for my case.

@Sarah have you solved the issue?
@nikgnomic Maybe you could help me?

alsamixer is operated only from Keyboard commands
You might want to try gnome-alsamixer or qasmixer if you intend to access ALSA controls frequently

The last 2 commands in the post you linked to was the basis for a BASH script
but it looks like OP did not follow through confirming if the commands worked

I skipped a step during information gathering because OP had only one audio device

Other users are likely to have more than one audio device so would need to check available playback devices to find the correct card number for onboard audio Analog output

aplay -l

(If aplay data shows a 2nd Analog or Alt Analog output the audio codec can support 2 independent audio outputs and a BASH script is not required)

HDMI outputs from GPU would usually be card 0 and Onboard audio is likely to be card 1

if that is the case, the command to show the ALSA control settings would be

amixer --card=1

That data will show the names of the controls for speaker and headphone outputs

Hey,

Thanks for the quick answer.

The aplay -l gives me the following:

aplay -l                                                                                                           ✔ 
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 11: HDMI 5 [HDMI 5]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 12: HDMI 6 [HDMI 6]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 0: ALC1220 Analog [ALC1220 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 1: ALC1220 Digital [ALC1220 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

And there you are correct - onboard audio is obviously Card1.

So the amixer --card=1 gives me this (Speakers plugged in Rear, Headphones+Mic plugged in Front panel, audio working on Headset):

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 47 [54%] [-30.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Front',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [off]
  Front Right: Playback 87 [100%] [0.00dB] [off]
Simple mixer control 'Front Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Front Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.00dB]
  Front Right: 3 [100%] [30.00dB]
Simple mixer control 'Surround',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 0 [0%] [-65.25dB] [off]
  Front Right: Playback 0 [0%] [-65.25dB] [off]
Simple mixer control 'Center',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 0 [0%] [-65.25dB] [off]
Simple mixer control 'LFE',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 0 [0%] [-65.25dB] [off]
Simple mixer control 'Line',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Line Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'IEC958 Default PCM',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 63
  Front Left: Capture 63 [100%] [30.00dB] [on]
  Front Right: Capture 63 [100%] [30.00dB] [on]
Simple mixer control 'Capture',1
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 63
  Front Left: Capture 0 [0%] [-17.25dB] [off]
  Front Right: Capture 0 [0%] [-17.25dB] [off]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Enabled'
Simple mixer control 'Input Source',0
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line'
  Item0: 'Front Mic'
Simple mixer control 'Input Source',1
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line'
  Item0: 'Front Mic'
Simple mixer control 'Loopback Mixing',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Rear Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Rear Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]

What I want to achieve now, is to have a simple script to toggle or turn on/off speakers or headset, without plugging the headset off. Then I can bind this script to a Keyboard shortcut and in that way toggle if I want that my audio comes out of Speakers or Headset.

Thank you in advance!

Hey @acerinth

Can you post an output of a full inxi command:

export LANG=C; inxi --admin --verbosity=7 --filter --no-host --width

That would help others in getting a better picture of your configuration. Thanks!

Of course :slight_smile:

System:
  Kernel: 5.10.56-1-MANJARO x86_64 bits: 64 compiler: gcc v: 11.1.0 
  parameters: BOOT_IMAGE=/boot/vmlinuz-5.10-x86_64 
  root=UUID=f3821945-f020-41c8-ab0d-fa24636ea73c rw quiet splash apparmor=1 
  security=apparmor resume=UUID=e675d7c4-da3d-4c5f-a2a3-2337f677c663 
  udev.log_priority=3 
  Desktop: GNOME 40.3 tk: GTK 3.24.30 wm: gnome-shell dm: GDM 40.1 
  Distro: Manjaro Linux base: Arch Linux 
Machine:
  Type: Desktop System: ASUS product: N/A v: N/A serial: <filter> 
  Mobo: ASUSTeK model: ROG STRIX B550-F GAMING v: Rev X.0x serial: <filter> 
  UEFI: American Megatrends v: 1205 date: 11/17/2020 
Battery:
  ID-1: hidpp_battery_0 charge: N/A condition: N/A volts: 3.8 min: N/A 
  model: Logitech G502 LIGHTSPEED Wireless Gaming Mouse type: N/A 
  serial: <filter> status: Discharging 
Memory:
  RAM: total: 15.58 GiB used: 3.3 GiB (21.2%) 
  RAM Report: permissions: Unable to run dmidecode. Root privileges required. 
CPU:
  Info: 6-Core model: AMD Ryzen 5 3600 bits: 64 type: MT MCP arch: Zen 2 
  family: 17 (23) model-id: 71 (113) stepping: 0 microcode: 8701021 cache: 
  L2: 3 MiB bogomips: 86269 
  Speed: 4150 MHz min/max: 2200/3600 MHz boost: enabled Core speeds (MHz): 
  1: 4150 2: 2074 3: 3627 4: 2077 5: 2056 6: 2054 7: 3592 8: 2098 9: 3717 
  10: 2070 11: 2061 12: 2053 
  Flags: 3dnowprefetch abm adx aes aperfmperf apic arat avic avx avx2 bmi1 
  bmi2 bpext cat_l3 cdp_l3 clflush clflushopt clwb clzero cmov cmp_legacy 
  constant_tsc cpb cpuid cqm cqm_llc cqm_mbm_local cqm_mbm_total cqm_occup_llc 
  cr8_legacy cx16 cx8 de decodeassists extapic extd_apicid f16c flushbyasid 
  fma fpu fsgsbase fxsr fxsr_opt ht hw_pstate ibpb ibs irperf lahf_lm lbrv lm 
  mba mca mce misalignsse mmx mmxext monitor movbe msr mtrr mwaitx nonstop_tsc 
  nopl npt nrip_save nx osvw overflow_recov pae pat pausefilter pclmulqdq 
  pdpe1gb perfctr_core perfctr_llc perfctr_nb pfthreshold pge pni popcnt pse 
  pse36 rdpid rdpru rdrand rdseed rdt_a rdtscp rep_good sep sev sev_es sha_ni 
  skinit smap smca sme smep ssbd sse sse2 sse4_1 sse4_2 sse4a ssse3 stibp 
  succor svm svm_lock syscall tce topoext tsc tsc_scale umip v_vmsave_vmload 
  vgif vmcb_clean vme vmmcall wbnoinvd wdt xgetbv1 xsave xsavec xsaveerptr 
  xsaveopt xsaves 
  Vulnerabilities: Type: itlb_multihit status: Not affected 
  Type: l1tf status: Not affected 
  Type: mds status: Not affected 
  Type: meltdown status: Not affected 
  Type: spec_store_bypass 
  mitigation: Speculative Store Bypass disabled via prctl and seccomp 
  Type: spectre_v1 
  mitigation: usercopy/swapgs barriers and __user pointer sanitization 
  Type: spectre_v2 mitigation: Full AMD retpoline, IBPB: conditional, STIBP: 
  conditional, RSB filling 
  Type: srbds status: Not affected 
  Type: tsx_async_abort status: Not affected 
Graphics:
  Device-1: NVIDIA TU116 [GeForce GTX 1660 Ti] vendor: Gigabyte driver: nvidia 
  v: 470.57.02 alternate: nouveau,nvidia_drm bus-ID: 07:00.0 
  chip-ID: 10de:2182 class-ID: 0300 
  Device-2: Logitech C505 HD Webcam type: USB driver: snd-usb-audio,uvcvideo 
  bus-ID: 5-4:4 chip-ID: 046d:08e3 class-ID: 0102 serial: <filter> 
  Display: x11 server: X.org 1.20.13 compositor: gnome-shell driver: 
  loaded: nvidia resolution: <missing: xdpyinfo> 
  OpenGL: renderer: NVIDIA GeForce GTX 1660 Ti/PCIe/SSE2 
  v: 4.6.0 NVIDIA 470.57.02 direct render: Yes 
Audio:
  Device-1: NVIDIA TU116 High Definition Audio vendor: Gigabyte 
  driver: snd_hda_intel v: kernel bus-ID: 07:00.1 chip-ID: 10de:1aeb 
  class-ID: 0403 
  Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK 
  driver: snd_hda_intel v: kernel bus-ID: 09:00.4 chip-ID: 1022:1487 
  class-ID: 0403 
  Device-3: Logitech C505 HD Webcam type: USB driver: snd-usb-audio,uvcvideo 
  bus-ID: 5-4:4 chip-ID: 046d:08e3 class-ID: 0102 serial: <filter> 
  Sound Server-1: ALSA v: k5.10.56-1-MANJARO running: yes 
  Sound Server-2: JACK v: 1.9.19 running: no 
  Sound Server-3: PulseAudio v: 15.0 running: yes 
  Sound Server-4: PipeWire v: 0.3.33 running: yes 
Network:
  Device-1: Intel Ethernet I225-V vendor: ASUSTeK driver: igc v: kernel 
  port: N/A bus-ID: 06:00.0 chip-ID: 8086:15f3 class-ID: 0200 
  IF: enp6s0 state: up speed: 100 Mbps duplex: full mac: <filter> 
  IP v4: <filter> type: dynamic noprefixroute scope: global 
  broadcast: <filter> 
  IP v6: <filter> type: dynamic noprefixroute scope: global 
  IP v6: <filter> type: dynamic noprefixroute scope: global 
  IP v6: <filter> type: noprefixroute scope: link 
  WAN IP: <filter> 
Bluetooth:
  Message: No bluetooth data found. 
Logical:
  Message: No logical block device data found. 
RAID:
  Message: No RAID data found. 
Drives:
  Local Storage: total: 2.5 TiB used: 617.22 GiB (24.1%) 
  SMART Message: Required tool smartctl not installed. Check --recommends 
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Crucial model: CT500P2SSD8 
  size: 465.76 GiB block-size: physical: 512 B logical: 512 B speed: 31.6 Gb/s 
  lanes: 4 type: SSD serial: <filter> rev: P2CR012 temp: 34.9 C scheme: GPT 
  ID-2: /dev/sda maj-min: 8:0 vendor: Seagate model: ST1000DM010-2EP102 
  size: 931.51 GiB block-size: physical: 4096 B logical: 512 B speed: 6.0 Gb/s 
  type: HDD rpm: 7200 serial: <filter> rev: CC43 scheme: GPT 
  ID-3: /dev/sdb maj-min: 8:16 vendor: Seagate model: ST250DM000-1BC141 
  size: 232.88 GiB block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s 
  type: HDD rpm: 7200 serial: <filter> rev: JC4B scheme: MBR 
  ID-4: /dev/sdc maj-min: 8:32 vendor: Western Digital model: WD10JPCX-24UE4T0 
  size: 931.51 GiB block-size: physical: 4096 B logical: 512 B speed: 6.0 Gb/s 
  type: HDD rpm: 5400 serial: <filter> rev: 1A01 scheme: MBR 
  Message: No optical or floppy data found. 
Partition:
  ID-1: / raw-size: 449.66 GiB size: 441.53 GiB (98.19%) 
  used: 20.26 GiB (4.6%) fs: ext4 dev: /dev/nvme0n1p2 maj-min: 259:2 
  label: N/A uuid: f3821945-f020-41c8-ab0d-fa24636ea73c 
  ID-2: /boot/efi raw-size: 100.5 MiB size: 99 MiB (98.45%) 
  used: 282 KiB (0.3%) fs: vfat dev: /dev/nvme0n1p3 maj-min: 259:3 
  label: NO_LABEL uuid: 127C-637C 
  ID-3: /home raw-size: 931.51 GiB size: 915.81 GiB (98.31%) 
  used: 120.33 GiB (13.1%) fs: ext4 dev: /dev/sda1 maj-min: 8:1 label: N/A 
  uuid: b3f12122-7905-45d8-955a-663710ae6f93 
  ID-4: /mnt/Movies raw-size: 931.51 GiB size: 931.51 GiB (100.00%) 
  used: 476.63 GiB (51.2%) fs: ntfs dev: /dev/sdc1 maj-min: 8:33 label: Movies 
  uuid: 1CF28147F281265C 
Swap:
  Kernel: swappiness: 60 (default) cache-pressure: 100 (default) 
  ID-1: swap-1 type: partition size: 16 GiB used: 0 KiB (0.0%) priority: -2 
  dev: /dev/nvme0n1p1 maj-min: 259:1 label: N/A 
  uuid: e675d7c4-da3d-4c5f-a2a3-2337f677c663 
Unmounted:
  ID-1: /dev/sdb1 maj-min: 8:17 size: 64 GiB fs: ntfs label: WINXP 
  uuid: 2EECD3E1ECD3A17F 
  ID-2: /dev/sdb2 maj-min: 8:18 size: 1 KiB fs: <superuser required> 
  label: N/A uuid: N/A 
  ID-3: /dev/sdb3 maj-min: 8:19 size: 104.87 GiB fs: ntfs label: TETA 
  uuid: FCA8D8ACA8D86724 
  ID-4: /dev/sdb5 maj-min: 8:21 size: 64 GiB fs: ntfs label: KAZETE 
  uuid: C8C48D89C48D7A88 
USB:
  Hub-1: 1-0:1 info: Full speed (or root) Hub ports: 10 rev: 2.0 
  speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900 
  Device-1: 1-6:2 info: ASUSTek AURA LED Controller type: HID 
  driver: hid-generic,usbhid interfaces: 2 rev: 2.0 speed: 12 Mb/s power: 16mA 
  chip-ID: 0b05:1939 class-ID: 0300 serial: <filter> 
  Hub-2: 1-7:3 info: Genesys Logic Hub ports: 4 rev: 2.0 speed: 480 Mb/s 
  power: 100mA chip-ID: 05e3:0610 class-ID: 0900 
  Hub-3: 2-0:1 info: Full speed (or root) Hub ports: 4 rev: 3.1 speed: 10 Gb/s 
  chip-ID: 1d6b:0003 class-ID: 0900 
  Hub-4: 3-0:1 info: Full speed (or root) Hub ports: 2 rev: 2.0 
  speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900 
  Hub-5: 4-0:1 info: Full speed (or root) Hub ports: 4 rev: 3.1 speed: 10 Gb/s 
  chip-ID: 1d6b:0003 class-ID: 0900 
  Hub-6: 5-0:1 info: Full speed (or root) Hub ports: 4 rev: 2.0 
  speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900 
  Device-1: 5-1:2 info: Logitech USB Receiver type: Mouse,Keyboard,HID 
  driver: hid-generic,usbhid interfaces: 3 rev: 2.0 speed: 12 Mb/s power: 98mA 
  chip-ID: 046d:c545 class-ID: 0300 
  Device-2: 5-2:3 info: Logitech USB Receiver type: Keyboard,Mouse,HID 
  driver: logitech-djreceiver,usbhid interfaces: 3 rev: 2.0 speed: 12 Mb/s 
  power: 98mA chip-ID: 046d:c539 class-ID: 0300 
  Device-3: 5-4:4 info: Logitech C505 HD Webcam type: Video,Audio 
  driver: snd-usb-audio,uvcvideo interfaces: 4 rev: 2.0 speed: 480 Mb/s 
  power: 500mA chip-ID: 046d:08e3 class-ID: 0102 serial: <filter> 
  Hub-7: 6-0:1 info: Full speed (or root) Hub ports: 4 rev: 3.1 speed: 10 Gb/s 
  chip-ID: 1d6b:0003 class-ID: 0900 
Sensors:
  System Temperatures: cpu: 43.8 C mobo: N/A gpu: nvidia temp: 47 C 
  Fan Speeds (RPM): N/A gpu: nvidia fan: 0% 
Info:
  Processes: 328 Uptime: 1h 28m wakeups: 6 Init: systemd v: 248 
  tool: systemctl Compilers: gcc: 11.1.0 Packages: 1279 pacman: 1271 lib: 315 
  flatpak: 0 snap: 8 Shell: Zsh v: 5.8 running-in: gnome-terminal inxi: 3.3.06

data from aplay shows only one analog output device

card 1: Generic [HD-Audio Generic], device 0: ALC1220 Analog [ALC1220 Analog]

so no option for independent audio streams

ALSA control Auto-Mute Mode must be changed to disabled to allow ‘manual’ control

amixer --card=1 sset 'Auto-Mute Mode' Disabled

This command should unmute rear speaker jack and mute headphones

amixer --card=1 -q sset `Headphone` mute &&  amixer --card=1 -q sset `Front` unmute

and this to mute speaker jack and unmute headphones

amixer --card=1 -q sset `Headphone` unmute &&  amixer --card=1 -q sset `Front` mute

If the commands work as intended, they can be used in a BASH script like this

alsa_mute_toggle.sh

#!/bin/bash

## alsa_mute_toggle.sh
## mute or un-mute speakers and headphones

# check if speakers are unmuted
if (amixer -c1 sget 'Front' | grep -Fq "[on]") > /dev/null;
then
# mute speaker and unmute headphone
    amixer -qc1 sset 'Front' mute && amixer -qc1 sset 'Headphone' unmute
else
# unmute speaker and mute headphone
    amixer -qc1 sset 'Front' unmute && amixer -qc1 sset 'Headphone' mute
fi
exit
1 Like

Hey @nikgnomic ,

Thanks a lot! Instead of backticks (`) I have to use single quotes (’), like in the script :smiley:
For some strange reason, when switching to Speakers, I have to change the volume afterwards to make it output sound, but this is definitely a minor issue. Script works like a charm! :sparkles:

Thanks once again for the awesome support :pray:

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.