Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Thinkpad X230 Tablet: use headset microphone

I investigated using my combined headset (headphones and microphone) jack on my Lneovo Thinkpad X230 Tablet. The headphones would work but not the microphone input. Ultimately, what I got to work was rather simple!

File /usr/local/bin/mutemic sends a little graphical popup to indicate the microphone status.

#!/bin/sh
# File: /usr/local/bin/mutemic
# Location: LTB-019
# Author: bender, bgstack15
# Startdate: 2022-08-07
# Title: Mutemic script
# Purpose: Handle mute-mic button on Thinkpad X230 Tablet
# Project: X230T-headset
# History:
# Usage:
#    Called from /etc/acpi/events/mutemic
#    Learn device name with `amixer scontrols`
# Related:
#    /etc/acpi/events/mutemic
# Reference:
#    https://forums.linuxmint.com/viewtopic.php?t=299427
#    https://forums.linuxmint.com/viewtopic.php?t=293804
#    https://www.kernel.org/doc/html/latest/sound/hd-audio/models.html
#    https://askubuntu.com/questions/125367
# Alternatives:
#    /etc/modprobe.d/alsa-base.conf: options_snd_hda_intel model=dual-codecs
# Improve:
# Dependencies:
#    apt-get install acpid notification-daemon libnotify-bin
#    ~/.fluxbox/startup has notification-daemon &
INPUT_DEVICE="Capture"
YOUR_USERNAME="$( loginctl list-sessions | awk '/seat/{print $3}' )"
date "+%F $0 $@" >> ~"${YOUR_USERNAME}"/mutemic.log
if amixer sget $INPUT_DEVICE,0 | grep '\[on\]' ; then
    amixer sset $INPUT_DEVICE,0 toggle
    #echo "0 blink" > /proc/acpi/ibm/led
    su $YOUR_USERNAME -c 'DISPLAY=":0.0" notify-send -t 1000 \
            -i microphone-sensitivity-muted-symbolic "Mic MUTED"'
else
    amixer sset $INPUT_DEVICE,0 toggle                       
    #echo "0 on" > /proc/acpi/ibm/led
    su $YOUR_USERNAME -c 'DISPLAY=":0.0" notify-send -t 1000 \
            -i microphone-sensitivity-high-symbolic "Mic ON"'
fi

The Thinkpad automatically recognizes that the correct input was muted/unmuted (although it's not exactly a mute; it's a type of input-selection or availability?) and enables the orange lamp on the mute-mic button. The /proc/acpi/ibm/led special device does not have an integer available for the mute-mic LED lamp (unless you compile a kernel module yourself?) anyways.

The above script depends on an acpi event definition, which I placed in /etc/acpi/events/mutemic:

# File: /etc/acpi/events/mutemic
# Location: LTB-019
# Author: bgstack15
# Startdate: 2022-08-07
# Title: Mic-mute operation
# Purpose: React to acpi event for mute-mic button
# History:
# Usage:
#    determine events by running acpi_listen and pressing buttons
# Related:
#    /usr/local/bin/mutemic
# Reference:
# Improve:
#    get more specific with event?
# Project: X230T-headset
# Dependencies:
#    apt-get install acpid
# Documentation:
#    In file /usr/local/bin/mutemic
event=button/micmute
action=/usr/local/bin/mutemic

After modifying this file, restart acpid service.

Extra research

I had investigated if I needed to change the driver (settings, or which driver was used?), by modifying /etc/modprobe.d/mic-input.conf:

options snd_hda_intel model=dual-codecs

There is a whole list of audio "codecs" to use in that model value. Ultimately though, I learned the original (unspecified, so "auto") settings worked, and I just needed to unmute the mic input.

References

Weblinks

  1. Microphone from headset not working - Linux Mint Forums
  2. <SOLVED> Line Out Built-in Audio & Headphones combined - Linux Mint Forums
  3. HD-Audio Codec-Specific Models — The Linux Kernel documentation
  4. shortcut keys - Enabling Mic Mute button and light on Lenovo Thinkpads - Ask Ubuntu

Comments