93

Hello I have tryed out the programm "EarCandy", now I had/have a lot of problems. At first I did not get any sound and now it is very low volume. PS Earcandy is now deleted from my harddisk.

When Im opening the Alsamixer with:

alsamixer

I see that the volume for the speakers is zero. Now I push it to the max volume. But after every restart, I have to open alsamixer again and have to set the volume to max again. Can I save the settings for alsamixer or is there any other way to fix the problem ? enter image description here

1
  • I did a solution to listen alsamixer monitor and restore automatically if any application tried to change. You can take a look here – Kafels Jun 1 at 17:24

11 Answers 11

101

Execute:

sudo alsactl store

This should save alsamixer configurations to /etc/asound.state which gets loaded every startup.

5
  • 15
    My laptop continues to reset my configuration, even after running the above command. It claims to be storing it to /var/lib/alsa/asound.state. Is there any other reason for it not working? – Azmisov Aug 31 '13 at 3:35
  • 1
    I have exactly the same problem, and exactly the same behaviour when I try sudo alsactl store. – JeanSibelius Oct 18 '14 at 19:15
  • 1
    @Azmisov: You can further experiment with the system like following: (1) store the configuration (2) start alsamixer and change master level (2) restore the configuration (3) check that master level was restored. If above is as expected, check that restore is actually triggered at system boot (chkconfig alsa-utils should display alsa-utils on). – dma_k Mar 12 '15 at 10:54
  • This answer solved my SPDIF problem: askubuntu.com/questions/541847/… – neves Dec 5 '15 at 17:04
  • 1
    When I run sudo alsactl store it gives me the following error alsactl: get_controls:567: snd_ctl_open error: Invalid argument. – user2513149 Nov 8 '16 at 20:36
30

You 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
2
  • 2
    The top answer didn't work for me but this did! I created a config file and placed it at /etc/asound.state and added the reload line to my /etc/rc.local. – John Aug 31 '15 at 13:21
  • This was the right solution for me... but I had to specify the absolute path to .config file inside the rc.local (although it should work even with relative because it's the same user.. but it didn't). thank you and I hope my hint also helps someone – davidhq Nov 29 '18 at 9:45
16

Seppo Erviälä's answer is right but not complete. As dma_k already noted, man alsactl clearly states at the end that,

/var/lib/alsa/asound.state (or whatever file you specify with the -f flag) is used to store current settings for your soundcards.

palacsinit appropriately noted that you can store config into your file with

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

and reload with

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

This can be further improved with placing the second line, the restore command into a .desktop file.

You will need to run nano ~/.config/autostart/alsarestore.desktop, which will open nano text editor and create ~/.config/autostart/alsarestore.desktop file. Entries in ~/.config/autostart/ directory are used to autostart programs and services for specific user on startup/graphical login.

The contents of the .desktop file should be the following:

[Desktop Entry]
Type=Application
Terminal=false
Name=alsarestore
Exec=alsactl --file ~/.config/asound.state restore

Among other things, you could store your config in /etc/asound.state and symlink it to /var/lib/alsa/asound.state, but this one is more of a suggestion rather than tested solution

5
  • This was the only way I worked for me on Ubuntu Xenial 16.04 – Francisco Costa Mar 18 '16 at 19:23
  • 1
    The "store" and "restore" command work fine for manual control. However, when I set up the autostart file with the "restore" command, I see the mic setting in alsamixer is being rewritten to mute and the result is static. If i manually do the restore command, all is fine. Why is the mic setting changing and not being corrected by an appropriately stored configuration file by autostart??? – Brad Horn Oct 8 '16 at 11:40
  • @BradHorn it's possible you have something else overwriting your command. It runs, but then something else undoes its changes – Sergiy Kolodyazhnyy Oct 8 '16 at 11:43
  • any ideas what that could be? – Brad Horn Oct 8 '16 at 11:44
  • 1
    @BradHorn not of the top of my head, no. Try changing the Exec line in the .desktop file to be Exec=bash -c "sleep 5 && alsactl --file ~/.config/asound.state restore" . That will introduce a 5 second delay, so whatever is overwriting your settings will run first, and then your restore command will run after that. Try playing with the sleep values if that still overrides your settings. – Sergiy Kolodyazhnyy Oct 8 '16 at 11:49
2

After 2 months of trying to make "sudo alsactl store" to work, I finally managed to do it. Firstly type in terminal "alsamixer" to enter the alsamixer UI. Then make the configurations you need(e.g increase speakers/headphones level or unmute something pressing "m" on keyboard). Now the most important part. Before you exit alsamixer, open a new terminal and do : "sudo su" to get high privileges (Be very careful with commands you use in "sudo su" mode because you may destroy your system) and then do "alsactl store" to save alsa settings. Then close both terminals and restart your computer. This will do the job.

2
1

The solution of Sergiy Kolodyazhnyy worked for me. Although I had to add the modification of Exec=bash -c "sleep 5 .... Indeed this happens because PulseAudio is modifying ALSA.
Another solution is to disable PulseAudio during boot (see here):

sudo cp /etc/pulse/client.conf /etc/pulse/client.confbackup
sudo nano /etc/pulse/client.conf

Find ; autospawn = yes, remove the ; and change it to:

autospawn = no

This solution also worked for me, although Ubuntu gave me a system program error at start. As I hate this kind of messages, I used the first solution.

1

Open alsamixer with sudo privilege:

sudo alsamixer

Then adjust the volume and exit.

sudo alsactl store
1

ALSA has a mechanism to save and restore settings:

# alsactl store
# alsactl restore

It will use a default file (usually /var/lib/alsa/asound.state) to save settings, and restore them from. The restore operation is usually done automatically at system bootup, usually from a systemd service.

However, it may happen that PulseAudio (the audio server that is often used by default on "recent" distributions), will override the ALSA settings by its own, sometimes messing up things. It may not so easy to teach PulseAudio to behave as you'd like, so a workaround of this kind might be used:

You may want to launch the following script (~/alsarestore.sh) from the root user crontab.

#!/bin/sh
restore_alsa() {
    while [ -z "$(pidof pulseaudio)" ]; do
        sleep 1
    done
    alsactl restore 
}
restore_alsa &

It will wait for PulseAudio to launch before calling alsactl restore (considering the stored configuration is the one you want).

Finally, as root, you may want to add this to crontab -e:

@reboot ~/alsarestore.sh 2>/dev/null

This work around is inspired from this ArchLinux wiki article.

2
  • I've seen that in my system pulseaudio never terminates, so that the while loop runs forever. I've solved the problem by simply using this code as alsarestore.sh : #!/bin/sh sleep 5 && alsactl -L restore (no need to use sudo) you may need to increase or decrease the 5 seconds delay. – Maurizio Ferreira Nov 5 '20 at 20:40
  • The while loop waits for pulseaudio to start, not to terminate. As soon as a pulseaudio process is running, the while loop finishes and the alsactl restore is executed. It only runs forever if pulseaudio never starts. Also, I removed the useless sudo from my answer, thanks for pointing it out. – Totor Nov 9 '20 at 1:00
0

After running sudo alsamixer the mixer should should retain the changes you make.

See Sound does not work once my profile loads on which answers you can find a clue also.

Good luck!

0

Alsa-Json-Gateway https://github.com/fulup-bzh/AlsaJsonGateway supports store/restore of sound card sessions from JSON/REST API

  • list sessions /jsonapi?request=session-list&cardid=hw:0
  • store session /jsonapi?request=session-store&cardid=hw:0&args=MySoundConfig
  • restore /jsonapi?request=session-load&cardid=hw:0&args=MySoundConfig
0

For those whom @Sergiy Kolodyazhnyy 's answer didn't work, try replacing alsactl by its complete path (whatever the which alsactl returned to you).

0

Alsa resets the volume for mic, headphones and speaker for my system. So I executed following commands to store and restore alsa setting.

  1. Following commands restores the default state

    sudo alsactl restore

  2. Then run following command and adjust the volume as per your need.

    sudo alsamixer

Make sure you select correct soundcard for which you want to modify the setting.

  1. After setting up sound level, exit the alsamixer and store the setting using following command

    sudo alsactl store

To verify the setting is saved you can check the file 'asound.state' which is stored at location /var/lib/alsa/asound.state (use locate command if you want to know the location of the file in your system)

  1. To restore the setting after system reboots, use following command

    sudo alsactl restore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.