You are not logged in.

#1 2021-06-11 00:59:49

Nhanderu
Member
From: São Paulo, Brazil
Registered: 2021-04-25
Posts: 6
Website

[SOLVED] ALSA doesn't work without PulseAudio

Hello.

I'm pretty newbie with sound configuration, basically because I was spoiled by my last Arch installation, where I just installed ALSA and everything worked out of the box with amixer. Now, I have a working setup with ALSA + PulseAudio, but, even after configuring it to work, I still can't understand my current situation here.

In this PC, I discovered that had to set the card no. 1 as the default, since that ALSA couldn't find Master in card 0, so I set the following to /etc/asound.conf:

pcm.!default {
        type hw
	card 1
}

ctl.!default {
        type hw           
        card 1
}

After all that, the sound still didn't work. I gave up, installed pulseaudio, and bam! It works! But with a minor inconvenience: amixer sset Master mute mutes PulseAudio's sink 1, too, but amixer sset Master unmute doesn't undo it, so I always have to run pacmd set-sink-mute 1 0 after toggling mute.

Yes, I know I already have the solution for the problem, but it feels like it's not the correct one (actually, writing this, it sounds like a pretty dumb one). Why amixer seems to mess with PulseAudio so arbitrarily? Why did I need to install PulseAudio (not that I have a problem with it) and couldn't run ALSA by itself?

Some things that are worth mentioning:

  • speaker-test -Dpulse works perfectly, while speaker-test doesn't

  • I've tried this solution (plus some others) and nothing different happened

Are there any logs that could help or any reference that could lead me to a solution?
Thank you in advance.

Last edited by Nhanderu (2021-06-11 21:56:46)

Offline

#2 2021-06-11 07:08:32

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 12,994

Re: [SOLVED] ALSA doesn't work without PulseAudio

The ALSA <-> pulse compat bridge shouldn't be used as the synchronisation of volumes via the fake ALSA master doesn't really happen. Don't use ALSA tools, rely on pulse tools if you use pulse, it is the correct choice here (you can also change volumes with pacmd/pactl there, an easy to use "trick" is doing

pactl set-sink-mute @DEFAULT_SINK@ toggle
pactl set-sink-volume @DEFAULT_SINK@ +5%

which will automatically refer to your set default sink ), as it completely changes the way volume control works to provide the features it does synchronising back from an  ALSA view is very cumbersome.

The problem here is that the "Master" channel refers to one single possibility of manipulating the audio. pulseaudio might internally actually change the "Headphone" or the "Speaker" or whatever control, and the amixer invocation will provide too little information to pulse in the background.

As for why you had to install pulseaudio and couldn't just use ALSA: That's impossible. Pulse ultimately relies on the drivers of ALSA, so you must have configured something incorrectly - which is easy to do by accident - and one of the reasons why pulse exists because there are a  lot of hidden gotchas and complexities that aren't immediately obvious, but you didn't provide enough information here that could help for why ALSA doesn't work.

As an example, the config you tried to use up here is the "worst" way to set the default card out of all the options listed on the ALSA wiki page. That will change the underlying ALSA node to exclusive direct access to the card, which would mean you could only have one active audio application at any given time (the speaker-test might as well have failed precisely because "pulse" was already using the device) and the formats of whatever you are trying to play have to be compatible to the card. You usually only use something like this if you know exactly what you are doing and have very specific usecases.

What was the error message when using speaker-test without going over the pulse pcm? As mention in my post you referenced you will always want to use -c2 as direct HW access can have issues with a plain mono channel. Pulse will internally mix that up to stereo so it's fine again, if you use direct HW access with ALSA this can lead to problems e,g,

speaker-test -Dplughw:1

should provide a simple format conversion even on ALSA.

To identify what we can do to try and get audio out of plain ALSA, you might want to post

aplay -lL
amixer -c1
#pulse state for reference
pacmd list-cards
pacmd list-sinks

Last edited by V1del (2021-06-11 08:34:37)

Offline

#3 2021-06-11 21:55:22

Nhanderu
Member
From: São Paulo, Brazil
Registered: 2021-04-25
Posts: 6
Website

Re: [SOLVED] ALSA doesn't work without PulseAudio

Hey. First of all, thank you for your incredible answer. I really appreciate that.

V1del wrote:

Don't use ALSA tools, rely on pulse tools if you use pulse

It makes total sense. I was stubbornly insisting on using amixer. Your pactl commands ran perfectly.

About the configuration, thank you (again) for the explanation. I'll sure take a look into that. I admit I became satisfied with it because, well, it worked, but I understand it's not the way it should be.

V1del wrote:

What was the error message when using speaker-test without going over the pulse pcm?

$ speaker-test -c2

speaker-test 1.2.5

Playback device is default
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
V1del wrote:

To identify what we can do to try and get audio out of plain ALSA, you might want to post

$ aplay -lL

null
    Discard all samples (playback) or generate zero samples (capture)
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
hdmi:CARD=Generic,DEV=0
    HD-Audio Generic, Generic Digital
    HDMI Audio Output
usbstream:CARD=Generic
    HD-Audio Generic
    USB Stream Output
sysdefault:CARD=Generic_1
    HD-Audio Generic, ALC255 Analog
    Default Audio Device
front:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    Front output / input
surround21:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
usbstream:CARD=Generic_1
    HD-Audio Generic
    USB Stream Output
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: Generic Digital [Generic Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic_1 [HD-Audio Generic], device 0: ALC255 Analog [ALC255 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
$ amixer -c1

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 0 [0%] [-65.25dB] [off]
  Front Right: Playback 0 [0%] [-65.25dB] [off]
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Mic Mute-LED Mode',0
  Capabilities: enum
  Items: 'On' 'Off' 'Follow Capture' 'Follow Mute'
  Item0: 'Off'
Simple mixer control 'Beep',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [12.00dB] [on]
  Front Right: Playback 31 [100%] [12.00dB] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 63
  Front Left: Capture 63 [100%] [30.00dB] [on]
  Front Right: Capture 63 [100%] [30.00dB] [on]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Headset Mic',0
  Capabilities: pvolume pswitch cswitch cswitch-joined cswitch-exclusive
  Capture exclusive group: 0
  Playback channels: Front Left - Front Right
  Capture channels: Mono
  Limits: Playback 0 - 31
  Mono: Capture [off]
  Front Left: Playback 31 [100%] [12.00dB] [off]
  Front Right: Playback 31 [100%] [12.00dB] [off]
Simple mixer control 'Headset Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.00dB]
  Front Right: 3 [100%] [30.00dB]
Simple mixer control 'Internal Mic',0
  Capabilities: cswitch cswitch-joined cswitch-exclusive
  Capture exclusive group: 0
  Capture channels: Mono
  Mono: Capture [on]
Simple mixer control 'Internal Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.00dB]
  Front Right: 3 [100%] [30.00dB]
Simple mixer control 'Loopback Mixing',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
$ pacmd list-cards

2 card(s) available.
    index: 0
	name: <alsa_card.pci-0000_05_00.1>
	driver: <module-alsa-card.c>
	owner module: 6
	properties:
		alsa.card = "0"
		alsa.card_name = "HD-Audio Generic"
		alsa.long_card_name = "HD-Audio Generic at 0xc07c8000 irq 77"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:05:00.1"
		sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:05:00.1/sound/card0"
		device.bus = "pci"
		device.vendor.id = "1002"
		device.vendor.name = "Advanced Micro Devices, Inc. [AMD/ATI]"
		device.product.id = "15de"
		device.product.name = "Raven/Raven2/Fenghuang HDMI/DP Audio Controller"
		device.string = "0"
		device.description = "Raven/Raven2/Fenghuang HDMI/DP Audio Controller"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	profiles:
		output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5900, available: unknown)
		off: Off (priority 0, available: unknown)
	active profile: <output:hdmi-stereo>
	sinks:
		alsa_output.pci-0000_05_00.1.hdmi-stereo/#0: Raven/Raven2/Fenghuang HDMI/DP Audio Controller Digital Stereo (HDMI)
	sources:
		alsa_output.pci-0000_05_00.1.hdmi-stereo.monitor/#0: Monitor of Raven/Raven2/Fenghuang HDMI/DP Audio Controller Digital Stereo (HDMI)
	ports:
		hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "video-display"
    index: 1
	name: <alsa_card.pci-0000_05_00.6>
	driver: <module-alsa-card.c>
	owner module: 7
	properties:
		alsa.card = "1"
		alsa.card_name = "HD-Audio Generic"
		alsa.long_card_name = "HD-Audio Generic at 0xc07c0000 irq 78"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:05:00.6"
		sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:05:00.6/sound/card1"
		device.bus = "pci"
		device.vendor.id = "1022"
		device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
		device.product.id = "15e3"
		device.product.name = "Family 17h (Models 10h-1fh) HD Audio Controller"
		device.string = "1"
		device.description = "Family 17h (Models 10h-1fh) HD Audio Controller"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	profiles:
		input:analog-stereo: Analog Stereo Input (priority 65, available: unknown)
		output:analog-stereo: Analog Stereo Output (priority 6500, available: unknown)
		output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6565, available: unknown)
		off: Off (priority 0, available: unknown)
	active profile: <output:analog-stereo+input:analog-stereo>
	sinks:
		alsa_output.pci-0000_05_00.6.analog-stereo/#1: Family 17h (Models 10h-1fh) HD Audio Controller Analog Stereo
	sources:
		alsa_output.pci-0000_05_00.6.analog-stereo.monitor/#1: Monitor of Family 17h (Models 10h-1fh) HD Audio Controller Analog Stereo
		alsa_input.pci-0000_05_00.6.analog-stereo/#2: Family 17h (Models 10h-1fh) HD Audio Controller Analog Stereo
	ports:
		analog-input-internal-mic: Internal Microphone (priority 8900, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-input-microphone"
		analog-input-headset-mic: Headset Microphone (priority 8800, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "audio-input-microphone"
		analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-speakers"
		analog-output-headphones: Headphones (priority 9900, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "audio-headphones"
$ pacmd list-sinks

2 sink(s) available.
    index: 0
	name: <alsa_output.pci-0000_05_00.1.hdmi-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: SUSPENDED
	suspend cause: IDLE
	priority: 9030
	volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 0.00 ms
	max request: 0 KiB
	max rewind: 0 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 0
	linked by: 0
	configured latency: 0.00 ms; range is 0.50 .. 1999.82 ms
	card: 0 <alsa_card.pci-0000_05_00.1>
	module: 6
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "Generic Digital"
		alsa.id = "Generic Digital"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "3"
		alsa.card = "0"
		alsa.card_name = "HD-Audio Generic"
		alsa.long_card_name = "HD-Audio Generic at 0xc07c8000 irq 77"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:05:00.1"
		sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:05:00.1/sound/card0"
		device.bus = "pci"
		device.vendor.id = "1002"
		device.vendor.name = "Advanced Micro Devices, Inc. [AMD/ATI]"
		device.product.id = "15de"
		device.product.name = "Raven/Raven2/Fenghuang HDMI/DP Audio Controller"
		device.string = "hdmi:0"
		device.buffering.buffer_size = "352768"
		device.buffering.fragment_size = "176384"
		device.access_mode = "mmap+timer"
		device.profile.name = "hdmi-stereo"
		device.profile.description = "Digital Stereo (HDMI)"
		device.description = "Raven/Raven2/Fenghuang HDMI/DP Audio Controller Digital Stereo (HDMI)"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "video-display"
	active port: <hdmi-output-0>
  * index: 1
	name: <alsa_output.pci-0000_05_00.6.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: SUSPENDED
	suspend cause: IDLE
	priority: 9039
	volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 0.00 ms
	max request: 0 KiB
	max rewind: 0 KiB
	monitor source: 1
	sample spec: s16le 2ch 48000Hz
	channel map: front-left,front-right
	             Stereo
	used by: 0
	linked by: 1
	configured latency: 0.00 ms; range is 0.50 .. 1837.33 ms
	card: 1 <alsa_card.pci-0000_05_00.6>
	module: 7
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "ALC255 Analog"
		alsa.id = "ALC255 Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "1"
		alsa.card_name = "HD-Audio Generic"
		alsa.long_card_name = "HD-Audio Generic at 0xc07c0000 irq 78"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:05:00.6"
		sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:05:00.6/sound/card1"
		device.bus = "pci"
		device.vendor.id = "1022"
		device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
		device.product.id = "15e3"
		device.product.name = "Family 17h (Models 10h-1fh) HD Audio Controller"
		device.string = "front:1"
		device.buffering.buffer_size = "352768"
		device.buffering.fragment_size = "176384"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Family 17h (Models 10h-1fh) HD Audio Controller Analog Stereo"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-speakers"
		analog-output-headphones: Headphones (priority 9900, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-speaker>

I'll set the topic as solved, since "using Pulse tools" seems like a great and simple answer. Again, thank you, sincerely. smile

Offline

Board footer

Powered by FluxBB