Skip to content

Instantly share code, notes, and snippets.

@kriegalex
Created October 17, 2025 03:56
Show Gist options
  • Select an option

  • Save kriegalex/72381c409faa2d40c0f615ab95308de0 to your computer and use it in GitHub Desktop.

Select an option

Save kriegalex/72381c409faa2d40c0f615ab95308de0 to your computer and use it in GitHub Desktop.
Reset Sound Blaster G6 microphone on Linux after reboot via systemd
[Unit]
Description=Sound BlasterX G6 Audio Configuration
After=graphical.target sound.target alsa-restore.service pulseaudio.service pipewire.service
# Wait for everything to be fully ready
After=multi-user.target network.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 10
ExecStart=/usr/local/bin/reset_sound_blaster_g6.sh
RemainAfterExit=yes
Restart=on-failure
RestartSec=5s
User=root
# Logging configuration
StandardOutput=journal
StandardError=journal
SyslogIdentifier=audio-config
[Install]
WantedBy=multi-user.target
#!/bin/bash
set -euo pipefail
# Script configuration
readonly SCRIPT_NAME="$(basename "$0")"
readonly DEVICE_NAME="Sound BlasterX G6"
readonly USB_DEVICE_ID="041e:3256"
readonly INITIAL_SLEEP=1
readonly USB_RESET_SLEEP=2
# Logging functions
log_info() {
echo "[INFO] $*"
}
log_error() {
echo "[ERROR] $*" >&2
}
log_warn() {
echo "[WARN] $*" >&2
}
log_debug() {
echo "[DEBUG] $*"
}
# Main script
main() {
log_info "Starting audio device configuration for ${DEVICE_NAME}"
# Initial delay
log_debug "Waiting ${INITIAL_SLEEP}s for system initialization"
sleep "$INITIAL_SLEEP"
# Find sound card
log_info "Searching for sound card: ${DEVICE_NAME}"
local aplay_output
if ! aplay_output=$(aplay -l 2>&1); then
log_error "Failed to list audio devices"
log_debug "aplay output: ${aplay_output}"
return 1
fi
local card_number
card_number=$(echo "$aplay_output" | grep "$DEVICE_NAME" | cut -d' ' -f 2 | tr -d ':' || true)
if [[ -z "$card_number" ]]; then
log_error "Sound card '${DEVICE_NAME}' not found"
log_debug "Available devices:"
echo "$aplay_output" | grep -E "^card" >&2 || log_debug "No cards found"
return 1
fi
log_info "Found sound card at card${card_number}"
# Reset USB device
log_info "Resetting USB device ${USB_DEVICE_ID}"
if ! usbreset "$USB_DEVICE_ID" 2>&1; then
log_error "Failed to reset USB device ${USB_DEVICE_ID}"
log_warn "Continuing anyway..."
else
log_info "USB device reset successful"
fi
# Wait for device to reinitialize
log_debug "Waiting ${USB_RESET_SLEEP}s for device reinitialization"
sleep "$USB_RESET_SLEEP"
# Verify card still exists after reset
log_debug "Verifying card${card_number} is available after reset"
if ! aplay -l 2>&1 | grep -q "card ${card_number}"; then
log_error "Card${card_number} disappeared after USB reset"
return 1
fi
# Configure audio settings
log_info "Configuring audio settings for card${card_number}"
# Set PCM Capture Source
log_debug "Setting PCM Capture Source to 'External Mic'"
if ! amixer -c "$card_number" set 'PCM Capture Source' 'External Mic' 2>&1; then
log_error "Failed to set PCM Capture Source"
return 1
fi
# Enable and set External Mic to 100%
log_debug "Setting External Mic capture to 100%"
if ! amixer -c "$card_number" set 'External Mic' cap 100% 2>&1; then
log_error "Failed to configure External Mic"
return 1
fi
# Set Input Gain Control to 67%
log_debug "Setting Input Gain Control to 67%"
if ! amixer -c "$card_number" set 'Input Gain Control' cap 67% 2>&1; then
log_error "Failed to set Input Gain Control"
return 1
fi
log_info "Audio configuration completed successfully"
# Display final mixer state
log_debug "Current mixer state:"
amixer -c "$card_number" scontents 2>&1 | grep -A 5 -E "(External Mic|PCM Capture|Input Gain)" || true
return 0
}
# Execute main function
if main; then
log_info "${SCRIPT_NAME} completed successfully"
exit 0
else
log_error "${SCRIPT_NAME} failed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment