ALSA: Difference between revisions
No edit summary |
m Cleaned up tone somewhat, however this page likely could do with a cleanup and reformating Tags: Mobile edit Mobile web edit Advanced mobile edit Visual edit |
||
| Line 7: | Line 7: | ||
In order to save the sound card state on shutdown sound must be enabled in <code>configuration.nix</code> | In order to save the sound card state on shutdown sound must be enabled in <code>configuration.nix</code> | ||
< | <syntaxhighlight lang="nix"> | ||
hardware.alsa.enablePersistence = true; | |||
</ | </syntaxhighlight> | ||
==Troubleshooting ALSA== | ==Troubleshooting ALSA== | ||
* on a console | * on a console launch [[wikipedia:Alsamixer|alsamixer]]. | ||
alsamixer | alsamixer | ||
* you see plenty of vertical bars | * If you see plenty of vertical bars: | ||
** | ** You should be okay | ||
* you see very few vertical bars and the sound card (top-left) is | * If you see very few vertical bars and the sound card (top-left) is "PC Speaker" or similar: | ||
** | ** Hit the 'S' key, you should be able to switch to the "real" audio card (if not your audio card is likely to not being supported yet). | ||
** | ** When the real audio card is selected you should be viewing the "plenty vertical bars" thing. | ||
*** | *** First thing to do is to disable PC speaker (kernel module "snd-pcsp", see below. | ||
=== Make your audio card the default ALSA card === | === Make your audio card the default ALSA card === | ||
Occasionally the PC-speaker is the default audio card for ALSA. You can make your real sound card default instead. For example, if your sound card is "hda-intel" then you would add the following to your configuration. | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
boot.extraModprobeConfig = '' | boot.extraModprobeConfig = '' | ||
options snd slots=snd-hda-intel | options snd slots=snd-hda-intel | ||
''; | ''; | ||
</syntaxHighlight> | </syntaxHighlight>At times, you may wish to disable one of multiple Intel cards. Here is how to disable the first card, but enable a second one. | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
boot.extraModprobeConfig = '' | boot.extraModprobeConfig = '' | ||
| Line 42: | Line 38: | ||
''; | ''; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Disable PC Speaker "audio card" === | === Disable PC Speaker "audio card" === | ||
Add "snd_pcsp" to the <code>boot.blacklistedKernelModules</code> option: | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 57: | Line 51: | ||
=== Other hardware specific problems === | === Other hardware specific problems === | ||
Some hardware specific problems can be resolved by adjusting the options for the sound module. For example, the microphone may be stuck on | Some hardware specific problems can be resolved by adjusting the options for the sound module. For example, the microphone may be stuck on a very low volume. First you should be sure that you have already checked the settings in alsamixer to make sure nothing is muted, and also any physical buttons on your computer. | ||
You should be able to look up the available options for | You should be able to look up the available options for model in [https://www.kernel.org/doc/Documentation/sound/hd-audio/models.rst models.rst]. You can try them out interactively as follows: | ||
# Close any applications using the sound card | # Close any applications using the sound card | ||
## See if any applications are using the sound card | ## See if any applications are using the sound card | ||
##: $ lsof /dev/snd/* | ##: {{Code|$ lsof /dev/snd/* | ||
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME | |||
pulseaudi 14080 goibhniu 30u CHR 116,7 0t0 5169 /dev/snd/controlC0 | |||
## Kill | pulseaudi 14080 goibhniu 37u CHR 116,7 0t0 5169 /dev/snd/controlC0|lang=console|line=no}} | ||
## Kill any processes | |||
##: for any process apart from pulseaudio you could just do: | ##: for any process apart from pulseaudio you could just do: | ||
##: $ kill -9 14080 | ##: $ kill -9 14080 | ||
| Line 92: | Line 87: | ||
''; | ''; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
[[Category:Audio]] | [[Category:Audio]] | ||
Latest revision as of 17:32, 27 March 2026
ALSA is the kernel-level sound API for Linux. On modern systems, it is usually used via a sound server like PulseAudio.
Save volume state on shutdown
In order to save the sound card state on shutdown sound must be enabled in configuration.nix
hardware.alsa.enablePersistence = true;
Troubleshooting ALSA
- on a console launch alsamixer.
alsamixer
- If you see plenty of vertical bars:
- You should be okay
- If you see very few vertical bars and the sound card (top-left) is "PC Speaker" or similar:
- Hit the 'S' key, you should be able to switch to the "real" audio card (if not your audio card is likely to not being supported yet).
- When the real audio card is selected you should be viewing the "plenty vertical bars" thing.
- First thing to do is to disable PC speaker (kernel module "snd-pcsp", see below.
Make your audio card the default ALSA card
Occasionally the PC-speaker is the default audio card for ALSA. You can make your real sound card default instead. For example, if your sound card is "hda-intel" then you would add the following to your configuration.
boot.extraModprobeConfig = ''
options snd slots=snd-hda-intel
'';
At times, you may wish to disable one of multiple Intel cards. Here is how to disable the first card, but enable a second one.
boot.extraModprobeConfig = ''
options snd_hda_intel enable=0,1
'';
Disable PC Speaker "audio card"
Add "snd_pcsp" to the boot.blacklistedKernelModules option:
boot.blacklistedKernelModules = [ "snd_pcsp" ];
Now reboot and retry from the beginning (i.e. check that your real card is shown by alsamixer without using the 'S' key).
Other hardware specific problems
Some hardware specific problems can be resolved by adjusting the options for the sound module. For example, the microphone may be stuck on a very low volume. First you should be sure that you have already checked the settings in alsamixer to make sure nothing is muted, and also any physical buttons on your computer.
You should be able to look up the available options for model in models.rst. You can try them out interactively as follows:
- Close any applications using the sound card
- See if any applications are using the sound card
$ lsof /dev/snd/* COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME pulseaudi 14080 goibhniu 30u CHR 116,7 0t0 5169 /dev/snd/controlC0 pulseaudi 14080 goibhniu 37u CHR 116,7 0t0 5169 /dev/snd/controlC0
- Kill any processes
- for any process apart from pulseaudio you could just do:
- $ kill -9 14080
- but in the case of pulseaudio you have to prevent it from respawning itself automatically
- $ systemctl --user mask pulseaudio.socket && systemctl --user stop pulseaudio
- you can then stop pulseaudio with:
- $ pulseaudio -k # or kill it by process id
- See if any applications are using the sound card
- Unload the snd-hda-intel module
- rmmod snd-hda-intel
- Find your model
- grep Codec /proc/asound/card0/codec*
- Look up the model options for your card
- Try each one
- modprobe snd-hda-intel model=3stack-6ch
- Test if this has fixed your problem (tip: aplay and arecord are alsa based command line tools you can use to quickly check)
- Repeat until you have exhausted all the options or have fixed your problem
- TIDY UP!
- Don't forget to re-enable pulse autospawning: systemctl --user unmask pulseaudio.socket
Once you have found a setting that works, you can add it to your configuration file:
boot.extraModprobeConfig = ''
options snd-hda-intel model=YOUR_MODEL
'';