You are not logged in.

#1 2017-08-20 17:04:31

nexx1
Member
Registered: 2017-08-20
Posts: 62

[SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Hi!

I just migrated from debian to arch, so far everything is running smooth, except one thing: audio from more than 1 source.

My very basic ~/.asound.conf looks like this (as described in the wiki):

pcm.!default {
	type hw
	card Generic
}

ctl.!default {
	type hw
	card Generic
}

Using just one playback (usually MPD/GMPC), its fine. Pausing the title and trying to open e.g. a youtube video fails with no sound.
Pausing MPD and running "alsaplayer some.mp3" returns no playback. Console output:

snd_pcm_open: Das Gerät oder die Ressource ist belegt (default)
Failed to initialize plugin!
Failed to register plugin: /usr/lib/alsaplayer/output/libalsa_out.so
Failed to load output plugin "alsa". Trying defaults.
snd_pcm_open: Das Gerät oder die Ressource ist belegt (default)
Failed to initialize plugin!
/usr/lib/alsaplayer/output/libalsa_out.so failed to load
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=Datei oder Verzeichnis nicht gefunden)
attempt to connect to server failed
jack: server not running?
/usr/lib/alsaplayer/output/libjack_out.so failed to load
error opening /dev/dsp
Failed to initialize plugin!
/usr/lib/alsaplayer/output/liboss_out.so failed to load
NOTE: THIS IS THE NULL PLUGIN.      YOU WILL NOT HEAR SOUND!!
libmikmod.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
CBSetcurrent: 1
CBSetcurrent: 1

alsaplayer -o alsa -d plug:dmix some.mp3 fails with the same messages.

I tried using other .asoundrcs, e.g. this one mentioned here: https://bbs.archlinux.org/viewtopic.php?id=226909
With this, every output fails. MPD cannot find the "default" device. (I changed the card appropriately, my guess is the definition pcm "hw:2,0". I dont know how to modify it correctly).

I do not have any other .asoundrc-files.

sudo fuser -v /dev/snd/*:

BEN.        PID ZUGR.  BEFEHL
/dev/snd/pcmC1D0p:   user     19171 F...m mpd

aplay -L

null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
hdmi:CARD=HDMI,DEV=0
    HDA ATI HDMI, HDMI 0
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=1
    HDA ATI HDMI, HDMI 1
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=2
    HDA ATI HDMI, HDMI 2
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=3
    HDA ATI HDMI, HDMI 3
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=4
    HDA ATI HDMI, HDMI 4
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=5
    HDA ATI HDMI, HDMI 5
    HDMI Audio Output
sysdefault:CARD=Generic
    HD-Audio Generic, ALC1220 Analog
    Default Audio Device
front:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    Front speakers
surround21:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Generic,DEV=0
    HD-Audio Generic, ALC1220 Digital
    IEC958 (S/PDIF) Digital Audio Output

If there is anything I can provide more to help you helping me, please let me know!

Last edited by nexx1 (2017-08-30 15:53:00)

Offline

#2 2017-08-21 03:53:56

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

The numbers after hw: stand for the soundcard number and device number. So those would have to match your setup too.

Here's my .asoundrc with what works for me:

pcm.!default {
        type plug
        slave.pcm "dmixer"
}

pcm.dmixer {
        type dmix               # http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
        ipc_key 17              # must be unique for each dmix definition
        ipc_key_add_uid true    # add current uid to unique IPC key, users can use this simultaneously
        slave {
                channels 2              # 2 for stereo, 6 for surround51, 8 for surround71
                pcm {
                        nonblock true           # nonblocking open mode, read/write access unchanged

                        #format S16_LE
                        format S32_LE
                        rate 44100
                        #rate 48000

                        type hw
                        card 0
                        device 0
                        #subdevice 0
                }
                period_time 0           # OSS?
                period_size 1024        # OSS needs powers of 2
                buffer_size 8192
                #period_size: 11024     # mpd defaults
                #buffer_size: 22048
        }
}

which I put together from http://www.alsa-project.org/alsa-doc/al … ugins_dmix Edit: mostly copied from here, actually

I've also found http://www.alsa-project.org/main/index.php/Asoundrc to be helpfull for understanding things.

I think maybe this section of the wiki is incorrect.

Edit: commented out subdevice - should be unneeded and might cause issues on some cards, I think.

Last edited by Ziusudra (2017-08-21 05:49:17)

Offline

#3 2017-08-21 18:19:35

nexx1
Member
Registered: 2017-08-20
Posts: 62

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Ziusudra wrote:

Here's my .asoundrc with what works for me:

Wonderful, it works! Thanks you!

Well, almost smile This .asoundrc causes my keybinds to not be working anymore. I am using the command 'amixer set Master 1-' (and 1+ and toggle).
'amixer set Master 1-' returns now:

amixer: Unable to find simple control 'Master',0

Well, what now?!

Last edited by nexx1 (2017-08-21 18:46:33)

Offline

#4 2017-08-22 03:38:01

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Well, that's weird - that command works for me. What're the output of 'amixer info' and 'amixer scontrols'?

Last edited by Ziusudra (2017-08-22 04:26:35)

Offline

#5 2017-08-22 13:50:49

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Any reason you guys are messing around with .asoundrc in the first place? Remove it and simply let ALSA do its thing, it hasn't needed configuring for dmix since ages now. Well, unless maybe you're doing something very specialized, but that doesn't appear to be the case here.

Offline

#6 2017-08-22 16:15:48

nexx1
Member
Registered: 2017-08-20
Posts: 62

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Gusar wrote:

Any reason you guys are messing around with .asoundrc in the first place? Remove it and simply let ALSA do its thing, it hasn't needed configuring for dmix since ages now. Well, unless maybe you're doing something very specialized, but that doesn't appear to be the case here.

Well, thats easy. Because it doesnt work without .asoundrc.

aplay /some.mp3

ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
aplay: main:807: Fehler beim Öffnen des Gerätes: Datei oder Verzeichnis nicht gefunden
Ziusudra wrote:

Well, that's weird - that command works for me. What're the output of 'amixer info' and 'amixer scontrols'?

amixer info

Card default 'HDMI'/'HDA ATI HDMI at 0xfe860000 irq 79'
  Mixer name	: 'ATI R6xx HDMI'
  Components	: 'HDA:1002aa01,00aa0100,00100300'
  Controls      : 42
  Simple ctrls  : 6

amixer scontrols

Simple mixer control 'IEC958',0
Simple mixer control 'IEC958',1
Simple mixer control 'IEC958',2
Simple mixer control 'IEC958',3
Simple mixer control 'IEC958',4
Simple mixer control 'IEC958',5

Well, the HDMI output seems to be the default now. No clue why... (aplay -L in the 1st post)

Weird indeed!

Offline

#7 2017-08-23 03:30:05

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

nexx1 wrote:

Well, thats easy. Because it doesnt work without .asoundrc.

Either you still have some ALSA config somewhere or your Pulseaudio is misconfigured. No other way ALSA would try a non-existent device by default. Also, aplay doesn't play mp3, it only plays wav.

nexx1 wrote:

Well, the HDMI output seems to be the default now. No clue why... (aplay -L in the 1st post)

That's very normal. It's the case in a lot of modern machines. The solution is very simple, though documentation everywhere instead prefers complex and/or not working solutions (it's one of the great mysteries of the internet, not unlike how people still think glxgears is a benchmark, but I digresss). Create an /etc/modprobe.d/alsa.conf with:

options snd_hda_intel index=1

Offline

#8 2017-08-23 05:15:09

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Gusar wrote:
nexx1 wrote:

Well, thats easy. Because it doesnt work without .asoundrc.

Either you still have some ALSA config somewhere or your Pulseaudio is misconfigured. No other way ALSA would try a non-existent device by default.

Pulseaudio =/= dmix. I'm trying to run as lean a system as I can. After a fresh install in 2015 dmix did not work -  thus the .asoundrc. With it ALSA does everything I want without PA even installed.

Gusar wrote:

Create an /etc/modprobe.d/alsa.conf with:

options snd_hda_intel index=1

Needs to be index=0 to make it the default as ALSA uses zero-based numbering.

Edit: I'm seeing some discussion (like https://raspberrypi.stackexchange.com/a/21989) that you may need to specify the index of both "cards".

There is also a "new" slots option described in the kernel docs. (The docs say new, it's been there for very nearly a decade now.)

Use 'cat /proc/asound/modules' to see what driver modules to use in either option. If they use the same module see: http://alsa.opensrc.org/MultipleCards#O … _same_type (you have to scroll down to that section).

Last edited by Ziusudra (2017-08-23 06:42:50)

Offline

#9 2017-08-23 17:24:08

nexx1
Member
Registered: 2017-08-20
Posts: 62

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Gusar wrote:
nexx1 wrote:

Well, thats easy. Because it doesnt work without .asoundrc.

Either you still have some ALSA config somewhere or your Pulseaudio is misconfigured. No other way ALSA would try a non-existent device by default. Also, aplay doesn't play mp3, it only plays wav.

Well, since its a fresh system and I did not install pulse, there is no misconfigured pulseaudio.

pacman -Qi pulseaudio
Fehler: Paket 'pulseaudio' wurde nicht gefunden
Gusar wrote:
nexx1 wrote:

Well, the HDMI output seems to be the default now. No clue why... (aplay -L in the 1st post)

That's very normal. It's the case in a lot of modern machines. The solution is very simple, though documentation everywhere instead prefers complex and/or not working solutions (it's one of the great mysteries of the internet, not unlike how people still think glxgears is a benchmark, but I digresss). Create an /etc/modprobe.d/alsa.conf with:

options snd_hda_intel index=1

I did create the /etc/modprobe.d/alsa.conf, but with not success. It just didnt change a thing. Just for testing, i replaced snd_hda_intel with the more likely modules snd_hda_codec_realtek and snd_hda_codec_generic and changed to index=0, all with no change. (Tested with amixer info after each change). --> removed the file

Ziusudra wrote:

cat /proc/asound/modules

0 snd_hda_intel
1 snd_hda_intel

Currently looking into the other link... But this soundthing does get bigger as i wanted it to get.

Last edited by nexx1 (2017-08-23 17:34:18)

Offline

#10 2017-08-23 18:58:04

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Yeah, I thought they'd be the same module. You'll have to do something like this. First get the vendor and device id of the cards:

$ lspci -nn
05:00.0 Multimedia video controller [0400]: Conexant Systems, Inc. CX23885 PCI Video and Audio Decoder [14f1:8852] (rev 03)
80:01.0 Audio device [0403]: VIA Technologies, Inc. VT8237A/VT8251 HDA Controller [1106:3288] (rev 10)

So [1106:3288] is the card needing to be default and [14f1:8852] is the other. And then in the modprobe.d/alsa.conf file

options snd_hda_intel index=0,1 vid=0x1106,0x14f1 pid=0x3288,0x8852

Or another possibility:

options snd_hda_intel index=0,1 id=Generic,HDMI

Last edited by Ziusudra (2017-08-23 19:20:15)

Offline

#11 2017-08-24 03:36:18

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Ziusudra wrote:

Pulseaudio =/= dmix. I'm trying to run as lean a system as I can. After a fresh install in 2015 dmix did not work -  thus the .asoundrc. With it ALSA does everything I want without PA even installed.

I know they're not the same. But I'm specifically taking about dmix not needing configuration. What you have in your .asoundrc is pretty much the same as ALSA *already* does and has been doing for years. Without an .asoundrc present. And I found it's better to just let ALSA do it's thing because manual configuration like yours can screw things up, but having no config would just work.

Ziusudra wrote:
Gusar wrote:

Create an /etc/modprobe.d/alsa.conf with:

options snd_hda_intel index=1

Needs to be index=0 to make it the default as ALSA uses zero-based numbering.

The point is *explicitly* to set index=1, so that the first device will get that, while the second device will get 0. It's a trick to change the device ordering from HDMI,Analog to Analog,HDMI.


Ziusudra wrote:

So [1106:3288] is the card needing to be default and [14f1:8852] is the other. And then in the modprobe.d/alsa.conf file

options snd_hda_intel index=0,1 vid=0x1106,0x14f1 pid=0x3288,0x8852

The sna_hda_intel module does not take vid and pid parameters (only the alsa us b module does). So that code will do nothing.


Ziusudra wrote:

Or another possibility:

options snd_hda_intel index=0,1 id=Generic,HDMI

The id parameter does not select, it assigns. All that code does is assign the first device an id of "Generic" and the second device an id of "HDMI". But if your first device is a HDMI one, all you've done is give it a wrong id now, but you didn't do what you wanted which is to change device ordering. Just a simple index=1 or, if you want to be explicit, index=1,0 will change device ordering.


@nexx1:
Your aplay -L output does show a pulse device in there, that's why I mentioned the possibility of a misconfigured pulse.

Last edited by Gusar (2017-08-24 03:37:50)

Offline

#12 2017-08-24 04:37:17

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Except we've both said that dmix didn't just work without a config on a fresh install. That said my 'aplay -L' output does not mention PA anywhere.

Won't using 'options snd_hda_intel index=1' to swap the order only work until udev decides to swap the initial order? Which it's already done once.

So if there is no reliable way using modprobe, what about instead of using 'card 0' in the .asoundrc using 'card Generic'? Using the name instead of the number as documented here

And/or adding these to .asoundrc:

defaults.pcm.!card Generic
defaults.pcm.!ctl Generic

Last edited by Ziusudra (2017-08-24 04:45:55)

Offline

#13 2017-08-29 16:32:50

nexx1
Member
Registered: 2017-08-20
Posts: 62

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Ziusudra wrote:

Except we've both said that dmix didn't just work without a config on a fresh install. That said my 'aplay -L' output does not mention PA anywhere.

Won't using 'options snd_hda_intel index=1' to swap the order only work until udev decides to swap the initial order? Which it's already done once.

So if there is no reliable way using modprobe, what about instead of using 'card 0' in the .asoundrc using 'card Generic'? Using the name instead of the number as documented here

And/or adding these to .asoundrc:

defaults.pcm.!card Generic
defaults.pcm.!ctl Generic

Adding the two lines doesnt change a thing. Mixing doesnt work. Changing to "card 0" disables sound output, "card 1" works as "card Generic".

PS: Sorry for my late answers, i am struggling to find time for my private PC.

Edit: Blo***y hell, this is a pain in the arse. Either mixing works OR the amixer-volumechange-commands work. It seems impossible to get them working together. I just dont get it...

Last edited by nexx1 (2017-08-29 17:29:34)

Offline

#14 2017-08-30 03:07:25

Ziusudra
Member
Registered: 2014-04-19
Posts: 120

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Oh right. So amixer tries to control card 0 by default. You can try 'amixer -c Generic set Master 1+'. (That works for me for setting controls on either of my cards.)

With that '-c Generic' option in the amixer commands and and 'card Generic' in the .asoundrc, it should not matter what order udev/ALSA puts the cards in.

(Though, clearly, I could be wrong.)

Edit: So, looking again at your 'aplay -L' output it look like your cards have always been in the HDMI, Generic order. The reason the amixer commands stopped working is the lack of a ctl.!default block in the .asoundrc I posted. You did have that block in originally.

So the proper .asoundrc would be:

pcm.!default {
	type plug
	slave.pcm "dmixer"
}

ctl.!default {
	type hw
	card Generic
}

# mostly from https://web.archive.org/web/20160415075838/https://dl.dropboxusercontent.com/u/18371907/asoundrc
pcm.dmixer {
	type dmix		# http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
	ipc_key 17		# must be unique for each dmix definition
	ipc_key_add_uid true	# add current uid to unique IPC key, users can use this simultaneously
	slave {
		channels 2		# 2 for stereo, 6 for surround51, 8 for surround71
		pcm {
			nonblock true		# nonblocking open mode, read/write access unchanged

			#format S16_LE
			format S32_LE
			rate 44100
			#rate 48000

			type hw
			#card 0
			card Generic
			device 0
			#subdevice 0
		}
		period_time 0		# OSS? http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_dmix
		period_size 1024	# OSS needs powers of 2
		buffer_size 8192
		#period_size: 11024	# mpd defaults
		#buffer_size: 22048
	}
}

That should have both dmix and normal amixer commands working.

Last edited by Ziusudra (2017-08-30 03:38:35)

Offline

#15 2017-08-30 07:25:04

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,742

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

@Zisundra

Regarding the modprobe options, in this case, HDMI always gets enumerated first which is why a simple index=1 should be sufficient. I don't know the exact logic why that seems to be the case, but observation has shown that it is.And as mentioned vid/pid have never done anything on snd_hda_intel, that's an alarmingly widespread misconception, presumably carried over from the fact that another widespread module - snd_usb_audio - does take these parameters

Also general info into the room, the ALSA pulse device will be present as soon as alsa-plugins is installed, unless it's directly referenced by config it is harmless and will not cause any interference.

But yeah, that last config should theoretically work.

Offline

#16 2017-08-30 15:52:27

nexx1
Member
Registered: 2017-08-20
Posts: 62

Re: [SOLVED] Alsa - problem with mixing (dmix) multiple audio sources

Ziusudra wrote:

Oh right. So amixer tries to control card 0 by default. You can try 'amixer -c Generic set Master 1+'. (That works for me for setting controls on either of my cards.)

With that '-c Generic' option in the amixer commands and and 'card Generic' in the .asoundrc, it should not matter what order udev/ALSA puts the cards in.

(Though, clearly, I could be wrong.)

Edit: So, looking again at your 'aplay -L' output it look like your cards have always been in the HDMI, Generic order. The reason the amixer commands stopped working is the lack of a ctl.!default block in the .asoundrc I posted. You did have that block in originally.

So the proper .asoundrc would be:

That should have both dmix and normal amixer commands working.


Well, what can I say... This config works! Woohoo, thank you Ziusudra, thank you very much! You just saved my day smile

PS: Yes, my soundcard order has always been HDMI at 0 and the onboard Generic at 1.

Offline

Board footer

Powered by FluxBB