4

I was hoping someone could possibly help me out with my sound card. I have a Soundblaster G6 running in 18.10. Everything seems to work except the microphone input. I realize Creative Labs doesn't officially support Linux, but since everything else is working. I was wondering if perhaps there was something I could do so that I could use my headset microphone while using it.

Can anyone point me in the right direction?

Cerebrix
  • 71
  • 2
  • 5

2 Answers2

3

I found a simple solution. Tested on Ubuntu 20.04.1 (and Fedora 31).

1. Open alsamixer

alsamixer

2. Choose your soundcard

F6

Sound BlasterX G6 Hit Enter to select the card

3. Activate 'Capture' for 'Line In' and 'External Mic'

F4
Use left-right arrows to navigate to the 'Line In'.
Use Space to activate the 'Capture'
Use left-right arrows to navigate to 'External Mic'
Use Space to activate the 'Capture'

4. Configure PCM Capture Source

F3
Use left-right arrows to navigate to 'PCM Capture Source'
Use up-down arrows to select 'External Mic'
Press ESC to save

5. Record a WAV to test the microphone

arecord -f dat -d 2 /tmp/test-mic.wav -vvv

6. Playback the WAV

aplay /tmp/test-mic.wav

7. Make the change persistent (fail)

After a reboot, The 'PCM Capture Source' keept going back to 'Line In'. I tried a systemd unit file (After=sound.target dbus.service) or a startup script in .zprofile... nothing worked. I think this is because the card takes some time to startup. So I came up with this workaround :

vim ~/bin/setmic

And add this:

#!/usr/bin/env bash

cardNumber=$(aplay -l|grep 'Sound BlasterX G6'|cut -d' ' -f 2 |tr -d ':') amixer -c "$cardNumber" -q set "PCM Capture Source" "External Mic"

if [ $? -eq 0 ]; then echo "PCM Capture Source successfully changed to 'External Mic'" else echo "Failed to configure PCM Capture source for Sound BlasterX G6" fi

amixer -c "$cardNumber" -q sset 'Input Gain Control' 3

if [ $? -eq 0 ]; then echo "Input Gain Control set to 3" else echo "Failed to activate mic Boost for Sound BlasterX G6" fi

~/bin beeing in my PATH:

chmod u+x ~/bin/setmic    
setmic

> PCM Capture Source successfully changed to 'External Mic' > Input Gain Control set to 3

Honiix
  • 131
0

This is my stupid and extremely hacky way to do it. Open for improvements.

It consists of two main parts:

  • A script that correcly configures the microphone in amixer, that is triggered on udev start
  • An autostarted script + program that resets the USB card, so that the udev-rule will actually be triggered on logon.

Create script to configure microphone

sudo nano /usr/local/bin/setmic.sh
#!/usr/bin/env bash

exec >> /tmp/setmic.log 2>&1 echo "Script started at $(date)"

cardNumber=$(aplay -l|grep 'Sound BlasterX G6'|cut -d' ' -f 2 |tr -d ':') amixer -c "$cardNumber" -q set "PCM Capture Source" "External Mic"

if [ $? -eq 0 ]; then echo "PCM Capture Source successfully changed to 'External Mic'" else echo "Failed to configure PCM Capture source for Sound BlasterX G6" fi

amixer -c "$cardNumber" -q sset 'Input Gain Control' 3

if [ $? -eq 0 ]; then echo "Input Gain Control set to 3" else echo "Failed to activate mic Boost for Sound BlasterX G6" fi

Make it executable

sudo chmod +x /usr/local/bin/setmic.sh

Add udev rule to auto execute on usb connect

sudo nano /etc/udev/rules.d/99-sound-blaster.rules
SUBSYSTEM=="sound", ACTION=="add", ATTRS{idVendor}=="041e", ATTRS{idProduct}=="3256", RUN+="/bin/bash -c 'sleep 5; /usr/bin/setmic.sh", OPTIONS+="watch"
sudo udevadm control --reload
sudo udevadm trigger

Create program to reset USB-device

nano ~/usbreset.c

Add the following content:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>

int main(int argc, char *argv) { const char filename; int fd; int rc;

if (argc != 2) {
    fprintf(stderr, &quot;Usage: usbreset device-filename\n&quot;);
    return 1;
}
filename = argv[1];

fd = open(filename, O_WRONLY);
if (fd &lt; 0) {
    perror(&quot;Error opening output file&quot;);
    return 1;
}

printf(&quot;Resetting USB device %s\n&quot;, filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc &lt; 0) {
    perror(&quot;Error in ioctl&quot;);
    return 1;
}
printf(&quot;Reset successful\n&quot;);

close(fd);
return 0;

}

Compile the script and move it to the correct location

cc usbreset.c -o usbreset
mv usbreset /usr/local/bin

Secure the file to avoid exploits

sudo chown root:root /usr/local/bin/usbreset sudo chmod 755 /usr/local/bin/usbreset

Add the script to sudoers

This is to avoid password prompts behind the scenes on autostart

sudo nano /etc/sudoers
# /etc/sudoers
your_username_here ALL=(root) NOPASSWD: /usr/local/bin/usbreset /dev/bus/usb/*/*

Create the reset script

This script will reset the USB device to make udev rules trigger (e.g. on logon)

sudo nano ~/bin/reset_soundcard.sh
#!/bin/bash

echo "$(date): Starting reset of Sound BlasterX G6" >> /tmp/reset_soundcard.log

DEVICE=$(lsusb | grep 'Sound BlasterX G6' | awk '{print "/dev/bus/usb/" $2 "/" substr($4, 1, length($4)-1)}')

if [ -n "$DEVICE" ]; then echo "Found device: $DEVICE" >> /tmp/reset_soundcard.log /usr/local/bin/usbreset "$DEVICE" >> /tmp/reset_soundcard.log 2>&1 else echo "Sound BlasterX G6 not found" >> /tmp/reset_soundcard.log fi

Make it executable

chmod +x ~/bin/reset_soundcard.sh

Create autostart for the reset script

So that you don't have to replug the device after boot

nano ~/.config/autostart/reset_soundcard.desktop

I assume you will have to modify this if you're not using Gnome.

[Desktop Entry]
Type=Application
Exec=~/bin/reset_soundcard.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Reset Sound BlasterX G6
Comment=Reseter lydkortet ved innlogging

Reboot to verify that it's working

reboot

Troubleshooting

You can use the logs generated to troubleshoot where it went wrong You can also manually run the scripts where necessary.

Jørgen V
  • 111
  • 4