How to set Alsa sound volume using sound.extraConfig?

My sound volume is too low when logging in. So, I added these commands in my .profile file:

amixer -c "PRMA" set PCM,0 100%
amixer -c "PRMA" set PCM,1 100%

This solution is resolving my issue. But, I wonder if I could instead use the sound.extraConfig NixOS option in my NixOS configuration file.

Would someone know how?

1 Like

That appears to be a shell command. extraConfig generally depends on a given program or service. There is a way with extraConfig precisely when there is a way with whatever configuration options the program or service provides.

Here’s a possible solution. It hasn’t been tested.

  systemd.services.alsaCommands = {
    enable = true;
    script = ''
      amixer -c "PRMA" set PCM,0 100%
      amixer -c "PRMA" set PCM,1 100%
    '';
    wantedBy = [ "multi-user.target" ];
  };

This creates a systemd service called alsaCommands that runs the given script for all users.

systemd.services.<name>.wantedBy
Units that want (i.e. depend on) this unit. The default method for starting a unit by default at boot time is to set this option to ["multi-user.target"] for system services. Likewise for user units (systemd.user.<name>.* ) set it to ["default.target"] to make a unit start by default when the user <name> logs on.

My sound volume is too low when logging in.

The sound levels should persists across reboots: the state is stored in /var/lib/alsa/asound.state . Do you have impermanence or something like that and forgot to keep this file?

if I could instead use the sound.extraConfig NixOS option in my NixOS configuration file.

No, you can’t use the ALSA configuration to change the sound levels. At best you can raise the minimum level, but then you wouldn’t be able to lower the volume if you ever need to.
How exactly depends on your card, but generally the default device looks something like this:

pcm.default {
	@args [ CARD ]
	@args.CARD {
		type string
	}
	type asym
	playback.pcm {
		type plug
		slave.pcm {
			type softvol
			slave.pcm {
				@func concat
				strings [ "dmix:" $CARD ]
			}
			control {
				name "PCM Playback Volume"
				card $CARD
			}
		}
	}
	capture.pcm {
		type plug
		slave.pcm {
			type softvol
			slave.pcm {
				@func concat
				strings [ "dsnoop:" $CARD ]
			}
			control {
				name "Digital Capture Volume"
				card $CARD
			}
			min_dB -30.0  # CHANGE THIS
			max_dB 30.0
			resolution 121
		}
		route_policy copy
	}
	hint.device 0
}

1 Like

I don’t think so. I haven’t done anything special.

When I log in, after a startup, my sound is too low. So, I use alsamixer to change this volume. Thereafter, the volume stays at the same level for the entire session, keeping its level even if the computer has slept.

Adding the two commands that I have shown previously in my .profile file solve the issue when I log in: I no longer have to go into alsamixer to change the volume manually. But the sound volume goes back to low after the computer has slept with this method.

I don’t understand what is written in /var/lib/alsa/asound.state and I don’t want to change it because this solution would not be portable.

Making a service was a great idea! Here is what I came with:

  systemd.services.RestoreAlsaVolume = {
      enable = true;
      description = "Setting SPDIF ALSA volume at 100% after sleep.";
      unitConfig = {
          Type = "simple";
      };
      serviceConfig.User = "pierre";
      script = lib.getExe(pkgs.writeShellApplication {
          name = "set-spdif-volume";
          runtimeInputs = with pkgs; [alsa-utils];
          text = ''
	    amixer -c "PRMA" set PCM,0 100%
            amixer -c "PRMA" set PCM,1 100%
          '';
      });
      wantedBy = [ "suspend.target" ];
  };

I still have the two same commands in .profile. I was unable to create a service setting the volume at startup. Because, I think this is conflicting with Alsa trying to do the same thing.

I had difficulties in my tests because setting the volume in alsamixer makes Alsa remember the volume when the machine is back from sleep. The command lines I used to not have this memory effect.

But the sound volume goes back to low after the computer has slept with this method.

This should not happen: the sound levels are saved before the computer goes to sleep or is powered off and restored on boot.

Can you share the output of these commands?

systemctl status alsa-store.service 
journalctl -u systemd-udevd -b -o cat --grep alsa

Can you share the output of these commands?

systemctl status alsa-store.service 
journalctl -u systemd-udevd -b -o cat --grep alsa
systemctl status alsa-store.service

â—Ź alsa-store.service - Store Sound Card State
     Loaded: loaded (/etc/systemd/system/alsa-store.service; enabled; preset: enabled)
     Active: active (exited) since Sun 2024-06-30 02:01:20 EDT; 3h 3min ago
    Process: 1592 ExecStart=/nix/store/pxf98n8dsxb6kmm0pdvc3dr3gzcqhizi-coreutils-9.3/bin/mkdir -p /var/lib/alsa (code=exited, status=0/SUCCESS)
   Main PID: 1592 (code=exited, status=0/SUCCESS)
         IP: 0B in, 0B out
        CPU: 1ms

jun 30 02:01:20 pierre-nixos systemd[1]: Starting Store Sound Card State...
jun 30 02:01:20 pierre-nixos systemd[1]: Finished Store Sound Card State.

journalctl -u systemd-udevd -b -o cat --grep alsa produces no output.

It looks like the udev rule is not firing… strange. What if you manually run sudo alsactl restore, is the volume restored? If so, you could put this in you workaround service.

What do you mean by that? What is the test you are proposing?

  1. Change the volume with alsamixer to whatever level you like
  2. reboot the system
  3. log in and run sudo alsactl restore

Is the volume properly restored now?

Yes, the volume is properly restored. :smiley:

So, what to do next?

Next step would be figuring out if the udev rules are really not firing and, if so, why.
To debug udev add udev.log-priority=debug to the kernel command line arguments from the bootloader. Then after you log in check the logs again: journalctl -u systemd-udevd -b -o cat --grep alsa.

This time you should see much more information, including which commands udev has run and what the result was.

I don’t understand how to do that. Could you explain?

For a one-off, you should manually edit the command line from your bootloader.
I believe in both systemd-boot and grub that’s done by pressing e on the selected boot entry.

Here is the output of journalctl -u systemd-udevd -b -o cat --grep alsa after logging.

Reading rules file: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-pipewire-alsa.rules
controlC1: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:11 Importing properties from results of builtin command 'path_id'
controlC1: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:12 Added SYMLINK 'snd/by-path/pci-0000:30:00.1'
controlC1: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules:5 RUN '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore $attr{device/number}'
controlC1: Running command "/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 1"
controlC1: Starting '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 1'
event12: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=3:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rv>
event12: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=3:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Ltd>
event14: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=8:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rv>
event14: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=8:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Ltd>
event13: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=7:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rv>
event15: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=9:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rv>
event13: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=7:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Ltd>
event15: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=9:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Ltd>
event16: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=10:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:r>
event16: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=10:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Lt>
event17: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Importing properties from results of builtin command 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=11:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:r>
event17: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-evdev.rules:25 Failed to run builtin 'hwdb 'evdev:name:HD-Audio Generic HDMI/DP,pcm=11:phys:ALSA:ev:21:dmi:bvnAmericanMegatrendsInternational,LLC.:bvr1.C2:bd05/13/2022:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7C94:pvr1.0:rvnMicro-StarInternationalCo.,Lt>
controlC1: Process '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 1' succeeded.
event15: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input24/event15'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
event17: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input26/event17'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
event14: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input23/event14'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
event12: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input21/event12'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
event13: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input22/event13'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
event16: '/nix/store/cghsv7bd73x4l2f0lkmmlk6cmzjs8w5y-libinput-1.25.0/lib/udev/libinput-device-group /sys/devices/pci0000:00/0000:00:08.1/0000:30:00.1/sound/card1/input25/event16'(out) 'LIBINPUT_DEVICE_GROUP=0/0/0:ALSA'
controlC0: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:7 Importing properties from results of builtin command 'usb_id'
controlC0: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:8 Added SYMLINK 'snd/by-id/usb-Kingston_HyperX_Virtual_Surround_Sound_00000000-00'
controlC0: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:11 Importing properties from results of builtin command 'path_id'
controlC2: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:7 Importing properties from results of builtin command 'usb_id'
controlC3: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:7 Importing properties from results of builtin command 'usb_id'
controlC0: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:12 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usb-0:1.1.1:1.0'
controlC0: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:13 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usbv2-0:1.1.1:1.0'
controlC2: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:8 Added SYMLINK 'snd/by-id/usb-046d_081b_65801AE0-02'
controlC2: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:11 Importing properties from results of builtin command 'path_id'
controlC0: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules:5 RUN '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore $attr{device/number}'
controlC3: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:8 Added SYMLINK 'snd/by-id/usb-SXW_Tech_SXW_CTUAD192_PRM-A_SXW_CTUAD-00'
controlC3: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:11 Importing properties from results of builtin command 'path_id'
controlC2: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:12 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usb-0:1.1.4.3:1.2'
controlC2: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:13 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usbv2-0:1.1.4.3:1.2'
controlC0: Running command "/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 0"
controlC0: Starting '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 0'
controlC3: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:12 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usb-0:1.1.4.4:1.0'
controlC3: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules:13 Added SYMLINK 'snd/by-path/pci-0000:30:00.4-usbv2-0:1.1.4.4:1.0'
controlC2: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules:5 RUN '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore $attr{device/number}'
controlC2: Running command "/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 2"
controlC2: Starting '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 2'
controlC3: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules:5 RUN '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore $attr{device/number}'
controlC3: Running command "/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 3"
controlC3: Starting '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 3'
controlC2: Process '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 2' succeeded.
controlC0: Process '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 0' succeeded.
controlC3: Process '/nix/store/1g4skp69k0k3av0qrykz4dv22bl4jxzx-alsa-utils-1.2.10/sbin/alsactl restore 3' succeeded.
Reading rules file: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-pipewire-alsa.rules
Reading rules file: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-pipewire-alsa.rules
Reading rules file: /nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-alsa-restore.rules
Reading rules file: /nix/store/77f0hgb1wsnkd2gbv1xqc8x99ghb4v4b-udev-rules/90-pipewire-alsa.rules

Note that I added these two lines to ~/.profile to set my volume:

amixer -c "PRMA" set PCM,0 100%
amixer -c "PRMA" set PCM,1 100%
controlC0: Process '/alsa-utils-1.2.10/sbin/alsactl restore 0' succeeded.
controlC1: Process '/alsa-utils-1.2.10/sbin/alsactl restore 1' succeeded.
controlC2: Process '/alsa-utils-1.2.10/sbin/alsactl restore 2' succeeded.
controlC3: Process '/alsa-utils-1.2.10/sbin/alsactl restore 3' succeeded.

The rules are definitely firing and these seem to indicated the settings have been restored. I’m not sure what’s going on here…

Maybe the restore procedure is working but not the store procedure?

I guess It could be. You can try to run alsactl store 0, etc. before shutting down.
The state is saved in /var/lib/alsa/asound.state, so you can try to delete it and check if it’s being correctly written. The content is plaintext and mostly readable.