You are not logged in.

#1 2021-08-10 15:51:29

stolichniaskitnik
Member
Registered: 2017-09-29
Posts: 34

[SOLVED] How to use ALSA without pulseaudio

Hello all,

I've recently bought a new laptop and have setup arch on it. In the past on all my desktop installations I install alsa-utils + pulseaudio and I have sound out of the box with everything.

I think it's finally time to learn how to configure sound without installing pulseaudio.

According to the ALSA archwiki local users can use sound without being added to the audio group. Additionally it states that alsa has been built into the linux kernel as a module (I'm using linux-hardened release but I believe that statement should also apply here) so it should technically work out of the box.
However it doesn't.

I also installed the alsa-ucm-conf and alsa-firmware packages to ensure this isn't due to my sound card being a new or weird model, but still no joy.

I used alsamixer to unmute all channels on all cards as well. Trying to use amixer to do the same however it is complaining I don't have a control for 'Master'

elina% amixer sset Master unmute
amixer: Unable to find simple control 'Master',0

elina%

It seems also that the sound modules have indeed been loaded.

elina% lsmod | grep '^snd' | column -t
snd_hda_codec_realtek  155648  1
snd_hda_codec_generic  98304   1  snd_hda_codec_realtek
snd_hda_codec_hdmi     73728   1
snd_hda_intel          57344   0
snd_intel_dspcfg       28672   1  snd_hda_intel
snd_intel_sdw_acpi     20480   1  snd_intel_dspcfg
snd_hda_codec          176128  4  snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_core           110592  5  snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek
snd_hwdep              16384   1  snd_hda_codec
snd_pcm                147456  4  snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core
snd_timer              45056   1  snd_pcm
snd                    114688  8  snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_pcm
snd_rn_pci_acp3x       20480   0
snd_pci_acp3x          20480   0
elina% ls -l /dev/snd
total 0
drwxr-xr-x  2 root root       80 Aug 10 17:26 by-path
crw-rw----+ 1 root audio 116,  4 Aug 10 17:26 controlC0
crw-rw----+ 1 root audio 116,  8 Aug 10 17:26 controlC1
crw-rw----+ 1 root audio 116,  3 Aug 10 17:26 hwC0D0
crw-rw----+ 1 root audio 116,  7 Aug 10 17:26 hwC1D0
crw-rw----+ 1 root audio 116,  2 Aug 10 17:26 pcmC0D3p
crw-rw----+ 1 root audio 116,  6 Aug 10 17:26 pcmC1D0c
crw-rw----+ 1 root audio 116,  5 Aug 10 17:26 pcmC1D0p
crw-rw----+ 1 root audio 116,  1 Aug 10 17:26 seq
crw-rw----+ 1 root audio 116, 33 Aug 10 17:26 timer
elina%

Here is also the output of amixer -di

elina% amixer -di
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
elina%

Can anybody suggest do I need further configuration to get my sound working without installing pulseaudio? Is it something with hardware that makes it mandatory I install pulseaudio to get sound working?
Let me know if I should provide further info.

Thanks!


=======================================================================================

EDIT: So the issue in this case was due to the way my hardware cards were ordered by the system I believe. Following 4.10 from this wiki I had to:

1) Get the list of my sound cards and devices:

elina% aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic_1 [HD-Audio Generic], device 0: ALC256 Analog [ALC256 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
elina%

2) Test out each card and device to confirm which one produces sound:
- not working as nothing connected to HDMI:

elina% aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav;
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
elina%

- working and producing sound:

elina% aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Center.wav;
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
elina%

3) Then creating ~/.asoundrc with the following contents, sounds is now working. I did reboot my box as well to get chromium working too.

elina% cat ~/.asoundrc
pcm.!default {
    type hw
    card 1
    device 0
}
elina%

That being said I believe the above 1) - 3) answer my initial question hence this will now be marked as solved.

Last edited by stolichniaskitnik (2021-08-11 14:52:31)

Offline

#2 2021-08-10 15:54:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] How to use ALSA without pulseaudio

Does speaker-test work:

speaker-test -c 2

If not, please post the output of the following:

aplay -l

Also post the content of any existing /etc/asoundrc and/or ~/.asoundrc.

Unfortunately, I don't think our wiki page on alsa is very well done.  The order it is laid out makes it appear as though sound generally works "out of the box" and that is not at all the case.  In most (if not all) cases, you need to at least set the default sound card.

Last edited by Trilby (2021-08-10 15:58:09)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2021-08-10 16:04:38

stolichniaskitnik
Member
Registered: 2017-09-29
Posts: 34

Re: [SOLVED] How to use ALSA without pulseaudio

Hi Trilby

When running the speaker command I get a playback error.

elina% speaker-test -c 2

speaker-test 1.2.5.1

Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
Playback open error: -2,No such file or directory
elina%

Here is the output of the second command you referenced.

elina% aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic_1 [HD-Audio Generic], device 0: ALC256 Analog [ALC256 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
elina%

Offline

#4 2021-08-10 16:11:04

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,160

Re: [SOLVED] How to use ALSA without pulseaudio

Your card 1 is what you actually want to play from so test

speaker-test -Dhw:1 -c2

and if that worked follow the linked section for setting the default card properly.

Offline

#5 2021-08-10 16:28:47

stolichniaskitnik
Member
Registered: 2017-09-29
Posts: 34

Re: [SOLVED] How to use ALSA without pulseaudio

Thank you V1del. Interesting, I am actually getting a 'cannot allocate memory' error here. Am not sure if that's something to do with linux-hardened or perhaps apparmor.

elina% speaker-test -Dhw:1 -c2

speaker-test 1.2.5.1

Playback device is hw:1
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 64 to 8544000
Period size range from 32 to 4272000
Using max buffer size 8544000
Periods = 4
Unable to set hw params for playback: Cannot allocate memory
Setting of hwparams failed: Cannot allocate memory
elina%

Offline

#6 2021-08-10 18:13:45

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,160

Re: [SOLVED] How to use ALSA without pulseaudio

could also just be a format incompat, try with -Dplughw:1 and/or -r 44100

Offline

#7 2021-08-11 14:45:15

stolichniaskitnik
Member
Registered: 2017-09-29
Posts: 34

Re: [SOLVED] How to use ALSA without pulseaudio

Sorry for replying late but it wasn't until this morning I got back to my laptop.

So I'm not sure if my current implementation is correct but it does seem as minimal as it gets. Also I'm not sure if that was the reason for it not working out of the box but I assume it is that it tries the cards in order, 0, then 1 and so on. As on my system card 0 is actually the HDMI one and I had nothing connected in the HDMI port it isn't working.

Additionally I only had looked into the main ALSA wiki. I found out there is this one --> https://wiki.archlinux.org/title/Advanc … leshooting

Going through it, what worked for me was 4.10 section, hardware and cards HDMI. I had to test out my cards and devices and create an ~/.asoundrc file with the relevant info.

Thanks for your help. I shall be editing my initial post shortly and marking this as solved.

Offline

#8 2021-08-11 14:58:22

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,160

Re: [SOLVED] How to use ALSA without pulseaudio

You should use one of the other approaches mentioned in the previously linked default section first. As this config as posted there will break aplay -L listings which certain applications rely on and should break dmix as well, so you won't be able to use multiple applications at the same time.

E.g. a minimal .asoundrc would look like: if you want to use the HDMI card

defaults.pcm.card 0;
defaults.pcm.device 3;

or if you want the analog card

defaults.pcm.card 1;
defaults.pcm.device 0;
defaults.ctl.card 1;

would be a minimal config that shouldn't break any usual expectations tools might have.

FWIW I agree with trilby that the current organisation could be improved, but haven't received any comments on my discussion proosal: https://wiki.archlinux.org/title/Talk:A … rd_section

Edit: Ah wait I'm a moron, the defaults method is included in that section. So I hope you did opt for the second approach in that section.

Last edited by V1del (2021-08-11 15:01:56)

Offline

#9 2021-08-11 15:13:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] How to use ALSA without pulseaudio

V1del wrote:

Edit: Ah wait I'm a moron, the defaults method is included in that section. So I hope you did opt for the second approach in that section.

It's there, but only as a fallback if the other method doesn't work.  That seems backwards: here's a bad but sometimes necessary config, if that fails, you can try this other config that is much better and should be the default.  That doesn't make a whole lot of sense.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2021-08-20 12:09:59

stolichniaskitnik
Member
Registered: 2017-09-29
Posts: 34

Re: [SOLVED] How to use ALSA without pulseaudio

Apologies for the late reply.
You were right with my config I couldn't get sound playing from multiple sources. Implementing the bit you referenced for the analog card did the trick.
I also had to enable the Auto-Mute mode inside of alsamixer to ensure speakers are muted when headphones are connected and vice versa.
Thank you guys!

Offline

Board footer

Powered by FluxBB