Table of Contents
Audio recording with the Acer TravelMate TMB113-E
How to record audio using a wireless microphone connected to the audio jack of an Acer TravelMate TMB113-E, running Debian GNU/Linux 10 Buster.
The microphone is a lavalier one, with an UHF (630 MHz) belt transmitter and a receiver mounted on a 1/4“ TS jack. I am mainly interested in recording using command line tools.
Electrical connection
I used an headset/microphone split cable to connect to the 3.5 mm CTIA audio jack of the Acer TravelMante and a self-made cable to adapt the TRS 3.5 mm mic jack to the 1/4” TS jack. The overall pinout is as follow:
1/4“ TS female jack | Signal | 3.5 mm TRRS male jack (CTIA) |
---|---|---|
Not connected | Tip | |
Not connected | Ring | |
Sleeve | Ground | Ring |
Tip | Microphone | Sleeve |
Problem detecting the external microphone
At first try it seems that the use of the headphone/microphone split cable does not abilitate the use of the microphone. In fac, if you run the acpi_listen tool (from the acpid Debian package), when you plug and unplug the split cable you can see this output:
jack/headphone HEADPHONE plug jack/headphone HEADPHONE unplug
As you can see, nothing is reported about the microphone. Beside that the bias current does not appear on the microphone jack. A workaround is to run the hdajackretask tool (from the alsa-tools-gui Debian package). That (experimental) program is capable to force the connection of Pin 0x19:
- Enable the Show unconnected pins option.
- Click Pin ID: 0x19 ⇒ Override ⇒ Microphone.
- Apply now (it asks for the root password, as it has to run a script with superuser privileges).
the running acpi_listen will print:
jack/microphone MICROPHONE plug
Now you can also measure a bias current of 2.85 V between the ground (sleeve) and the ring or the tip.
In some cases the hdajackretask is unable to perform the Apply now function because the audio device is in use, so you get the following error message:
/sys/class/sound/hwC0D0/reconfig: Device or resource busy
The culprit can be some PulseAudio or ALSA process, or something else which is using the snd-hda-intel kernel module. I tried several commands to free the audio device, stopping user and system services:
systemctl --user stop pulseaudio.socket systemctl --user stop pulseaudio.service sudo systemctl stop alsa-state.service
I was unable to free the module on a Debian 10 with XFCE, so I tried the Install boot override button of hdajackretask. This option will add a modprobe configuration file /etc/modprobe.d/hda-jack-retask.conf containing the following line:
options snd-hda-intel patch=hda-jack-retask.fw,hda-jack-retask.fw,hda-jack-retask.fw,hda-jack-retask.fw
This will pass the patch option on module loading, using the content of the file /lib/firmware/hda-jack-retask.fw which is created by hdajackretask too. The file contains the hex values for the retask of each pin, something like this:
[codec] 0x10ec0269 0x10250748 0 [pincfg] 0x12 0x411111f0 0x14 0x90170110 0x17 0x411111f0 0x18 0x411111f0 0x19 0x03a19020 0x1a 0x411111f0 0x1b 0x90a70920 0x1d 0x40189b2d 0x1e 0x411111f0 0x21 0x0321101f
The pincfg hex values are shown on stdout by hdajackretask when you press the Apply now button, so you can take note and build different files for different scenarios to use during bootstrap. For the TBM113-E the normal status of pin 0x19 corresponds to the value 0x411111f0, whereas the override status (plugged microphone) is 0x03a19020.
When you apply the pin override in hdajackretask, it is not clear how to disable the external microphone: re-setting Pin 0x19 to Not connected does not generate the ACPI microphone unplug event, and the bias current is not cleared. The bias power disappears from the jack after a poweroff or an hybernation, so the external microphone seems to be “unplugged” after these events.
If instead the override is made at bootstrap via the modules patch option, the settings survive after the hibernation: you can see the jack/microphone MICROPHONE plug ACPI event after the resume.
Setting the recording volume with PulseAudio
I used the PulseAudio mixer pavucontrol to set the recording volume level: it turned out that a value of 16463 (corresponding to 25% of the slider, or -36.00 dB) is the best setting for normal speach. At the ALSA level (lower level interface used by PulseAudio) it means a Capture level of 100 and a Mic Boost of 0. This is a table of value correspondence between PulseAudio and ALSA (notice that it is specific to this PCI sound card):
ALSA | PulseAudio |
---|---|
Capture 100, Mic Boost 0 | Volume: 16463 / 25% / -36.00 dB |
Capture 100, Mic Boost 20 | Volume: 26092 / 40% / -24.00 dB |
Capture 100, Mic Boost 51 | Volume: 41353 / 63% / -12.00 dB |
You can check the correspondence between PulseAudio and ALSA levels by executing alsamixer, pavucontrol and pacmd list-sources commands. The settings you make in PulseAudio will be reflected in ALSA, and vice-versa.
Recording with PulseAudio parecord
I want to use the PulseAudio subsystem to record the audio; I don't want to use the ALSA kernel-level interface, which needs direct and exclusive access to the device.
Using the command pacmd list-sources you can discover the name of the device.class of type sound, the current volume level, the base volume and the ports (microphones) availables.
The recording volume should be a vaule between the base volume and 65536 (corresponding to 100%, or 0.00 dB). Every different hardware should be tested to find the best settings to get a clear and loud sound, but to avoid clipping (out of scale samples).
pacmd list-sources 2 source(s) available. index: 0 name: <alsa_output.pci-0000_00_1b.0.analog-stereo.monitor> ... properties: device.description = "Monitor of Built-in Audio Analog Stereo" device.class = "monitor" ... * index: 1 name: <alsa_input.pci-0000_00_1b.0.analog-stereo> volume: front-left: 26092 / 40% / -24.00 dB, front-right: 26092 / 40% / -24.00 dB base volume: 5206 / 8% / -66.00 dB ... properties: device.class = "sound" ... ports: analog-input-internal-mic: Internal Microphone (priority 8900, available: no) ... analog-input-mic: Microphone (priority 8700, available: yes) active port: <analog-input-mic>
Beware that with the audio card of the TMB113-E, the port analog-input-mic refers to the external microphone when that one is connected (or forcibly connected by hdajackretask), but the same name refers to the internal microphone when the audio jack is disconnected. In fact the analog-input-internal-mic only exists if there are two microphone ports.
Once you understand the output of pacmd list-sources, it is very simple to activate the recording using a command line script:
#!/bin/sh SOURCE='alsa_input.pci-0000_00_1b.0.analog-stereo' PORT='analog-input-mic' VOLUME=16463 pacmd set-default-source "$SOURCE" pacmd set-source-port "$SOURCE" "$PORT" pacmd set-source-volume "$SOURCE" "$VOLUME" pacmd set-source-mute "$SOURCE" 0 parecord --verbose --device="$SOURCE" --channels=1 --fix-rate foobar.wav
The result is a 44100 Hz, 16 bit little-endian, mono audio file, quite satisfactory for quality and low background noise.
Microphone plug/unplug events
Having set the pin 19 forcibly to microphone, I often noticed that microphone plug/unplug events are reported continously (about every 3 seconds) by the ACPI subsystem:
acpi_listen jack/microphone MICROPHONE unplug jack/microphone MICROPHONE plug jack/microphone MICROPHONE unplug jack/microphone MICROPHONE plug jack/microphone MICROPHONE unplug jack/microphone MICROPHONE plug ...
Fortunately enough, when I start recording audio with parecord, the plug event occurs and the microphone stay stably plugged throughout the recording time.