0

Using sudo alsamixer (a GUI interface) followed by sudo alsactl, I have been able to adjust an external USB microphone gain (volume). Whenever the USB microphone is removed, the whole procedure must be repeated. amixer is a text shell based command that has the same results as alsamixer so that I could write a shell script to execute each time the external USB microphone is plugged-in. I have read man amixer; amixer -c 1 sset Line,0 80%,40% unmute cap from man is the closest to what I need but the syntax is not that clear. I have read https://www.geeksforgeeks.org/amixer-command-in-linux-with-examples/ but that too is not that clear. I assume there is no alsamixer setting to produce the equivalent amixer command. Any assistance would be appreciated. Take care. Stay safe.

  • you can supply default attributes with udev ... start by monitor your device udevadm monitor environment --udev next you can list attributes with udevadm info -a --path= –  Oct 21 '20 at 08:31
  • I found https://askubuntu.com/questions/50067/howto-save-alsamixer-settings alsactl --file ~/.config/asound.state store Reloading: alsactl --file ~/.config/asound.state restore Will these commands save and restore the microphone state after alsamixer is used for the configuration? Will these work in 18.04.x LTS and 20.04.x LTS? Take care. Stay safe. – Yasha Karant Oct 21 '20 at 16:24
  • I think udev is your best bet. Take the first line and put it in the file. /etc/udev/rules.d/99-amixer-usb-mic.rules and run, udevadm trigger connect your microphone again. You may need to adjust the rule to match your hardware. –  Oct 22 '20 at 04:26
  • the original rule is /lib/udev/rules.d/90-alsa-restore.rules, you can test it on the command line sudo /usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore 0 where 0 is the card number. –  Oct 22 '20 at 04:52
  • The next thing you can do is creating an empty file /etc/alsa/state-daemon.conf and restart this will change alsa's state management schemas to alsa state daemon, which pulls and saves the state periodically. (...but i have had alot of problem with this daemon) –  Oct 22 '20 at 05:54

1 Answers1

0

From:

Howto save AlsaMixer settings?

ou could also save the mixer settings into a custom file with alsactl:

alsactl --file ~/.config/asound.state store

Reloading:

alsactl --file ~/.config/asound.state restore

Note that until some posts a how-to or I can track it down, the above alsactl ... restore needs to be done each time the USB microphone is plugged into the computer. Presumably, there is some USB mounting/opening/attaching initiation configuration file to the USB function that actually identifies the USB microphone as what alsamixer claims to be a "sound card"; modifying that file should make the restore unnecessary as the fix would be permanent to the system and used for every instance of the USB microphone.