LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-06-2015, 05:14 PM   #1
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 814

Rep: Reputation: 265Reputation: 265Reputation: 265
Outputting to two sound cards with ALSA


Hi,
I have a Dell Inspiron 15R laptop. It has two sound cards: one for the internal speakers and headphone jack, and one for the HDMI audio. Originally, the default was the HDMI, but I fixed that with the help of this thread: https://www.linuxquestions.org/quest...er-4175506142/

The configuration that set the internal speaker card as default:
/etc/asound.conf
Code:
pcm.!default {
	type hw
	card 1
}

ctl.!default {
	type hw
	card 1
}
~/.asoundrc
Code:
pcm.!default {
  type plug
  slave.pcm "dmixer"
}

pcm.dsp0 {
  type plug
  slave.pcm "dmixer"
}

pcm.dmixer {
  type dmix
  ipc_key 1024
  slave {
    pcm hw:1
  }
}
While that worked, I'd like to be able to use HDMI audio as well, if I connect my laptop to something over HDMI.
Using this guide (http://slack4dummies.blogspot.com/20...ple-sound.html) I came up with this /etc/asound.conf, and no ~/.asoundrc
Code:
# Have output to both normal sound card and HDMI audio
# Based very heavily on this article:
# http://slack4dummies.blogspot.com/2012/02/alsa-multiple-output-multiple-sound.html

pcm.onboard {
	type hw
	card PCH
}
ctl.onboard {
	type hw
	card PCH
}

pcm.hdmi {
	type hw
	card HDMI
}
ctl.hdmi {
	type hw
	card HDMI
}

pcm.internalDmix {
	type dmix
	ipc_key 1024
	slave {
		pcm "internal"
		channels 2
	}
	bindings {
		0 0
		1 1
	}
}

pcm.hdmiDmix {
	type dmix
	ipc_key 2048
	slave {
		pcm "hdmi"
		channels 2
	}
	bindings {
		0 0
		1 1
	}
}

pcm.both {
	type route
	slave.pcm {
		slaves.a.pcm "internalDmix"
		slaves.b.pcm "hdmiDmix"
		slaves.a.channels 2
		slaves.b.channels 2

		bindings.0.slave a
		bindings.0.channel 0
		bindings.1.slave a
		bindings.1.channel 1

		bindings.0.slave b
		bindings.0.channel 0
		bindings.1.slave b
		bindings.1.channel 1
	}

	ttable.0.0 1
	ttable.1.1 1
}

pcm.!default {
	type plug
	slave {
		pcm both
	}
}

ctl.!default {
	type hw
	card PCH
}
However, that isn't working. Not only does HDMI audio not work, but the internal speakers aren't doing anything either. When I try to open alsamixer, I get this error:
Code:
[anthony@newerLaptop ~]$ alsamixer 
ALSA lib conf.c:1231:(parse_def) hdmi is not a compound
ALSA lib conf.c:1697:(snd_config_load1) _toplevel_:14:10:Invalid argument
ALSA lib conf.c:3417:(config_file_open) /etc/asound.conf may be old or corrupted: consider to remove or fix it
ALSA lib conf.c:3339:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument
ALSA lib conf.c:3788:(snd_config_update_r) hooks failed, removing configuration
cannot open mixer: Invalid argument
I had to move my asound.conf out of the way and reboot in order to get this output, but I know that you'd ask for it anyway
Code:
[anthony@newerLaptop ~]$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3223 Analog [ALC3223 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
When I open alsamixer and go to the HDMI sound card, there are no "slider" bars. Instead, there are three "S/PDIF" options that only have the option to mute/unmute. Could that have anything to do with why it failed?

I apologize if there's some ridiculously stupid mistake in there. I'm still having trouble wrapping my head around the syntax of these files.
 
Old 08-18-2015, 02:32 PM   #2
Melanie
LQ Newbie
 
Registered: Jan 2003
Location: London, UK
Distribution: CentOS, Fedora
Posts: 4

Rep: Reputation: 1
At first glance, there seem to be several things in that asound.conf that reference things not defined anywhere.

First off, there are certain difficulties with merging two sound cards. From my work on jackd I learned that, unless the two cards are sample-synchronized, there is a very good chance it will just not work reliably.

It may work well enough for the desktop pops and clicks, or for watching a movie, but may well fail after a few hours, when one of the dmix buffers underflows.

That said, when using type hw, card must be numeric, not a name. Refer to your aplay -l output for these numbers. In your case, the HDMI audio port is port 0 and the analog is port 1.

This gives you:

pcm.onboard {
type hw
card 1
}
ctl.onboard {
type hw
card 1
}

pcm.hdmi {
type hw
card 0
}
ctl.hdmi {
type hw
card 0
}

Now the names "onboard" and "hdmi" are defined.

The next bit is the DMIXers. You need them to allow different programs to set different sample rates.

Here you had "internal", which wasn't defined. Changing this to "onboard", which _is_ defined, makes it look like this:

pcm.internalDmix {
type dmix
ipc_key 1024
slave {
pcm "onboard"
channels 2
}
bindings {
0 0
1 1
}
}

pcm.hdmiDmix {
type dmix
ipc_key 2048
slave {
pcm "hdmi"
channels 2
}
bindings {
0 0
1 1
}
}

Finally, your router:

pcm.both {
type route
slave.pcm {
slaves.a.pcm "internalDmix"
slaves.b.pcm "hdmiDmix"
slaves.a.channels 2
slaves.b.channels 2

bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1

bindings.0.slave b
bindings.0.channel 0
bindings.1.slave b
bindings.1.channel 1
}

ttable.0.0 1
ttable.1.1 1
}

Nothing seems to be wrong here.

And your output defaults.

pcm.!default {
type plug
slave {
pcm both
}
}

ctl.!default {
type hw
card 1
}

Note how I changed the CTL default to be a number here again?

Now, I have no way to test this, but it should give you a nudge in the right direction.

- Melanie

Last edited by Melanie; 08-18-2015 at 05:15 PM.
 
Old 08-20-2015, 05:58 PM   #3
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 814

Original Poster
Rep: Reputation: 265Reputation: 265Reputation: 265
Thanks for the reply!

Unfortunately, your suggestion did not help. Just to double-check, here is the latest asound.conf:
Code:
[anthony@newerLaptop ~]$ cat /etc/asound.conf
# Have output to both normal sound card and hdmi audio
# Based very heavily on this article:
# http://slack4dummies.blogspot.com/2012/02/alsa-multiple-output-multiple-sound.html

pcm.internal {
	type hw
	card 1
}
ctl.internal {
	type hw
	card 1
}

pcm.hdmi {
	type hw
	card 0
	device 3
}

ctl.hdmi {
	type hw
	card 0
	device 3
}

pcm.internalDmix {
	type dmix
	ipc_key 1024
	slave {
		pcm "internal"
		channels 2
	}
	bindings {
		0 0
		1 1
	}
}

pcm.hdmiDmix {
	type dmix
	ipc_key 2048
	slave {
		pcm "hdmi"
		channels 2
	}
	bindings {
		0 0
		1 1
	}
}

pcm.both {
	type route
	slave.pcm {
		slaves.a.pcm "internalDmix"
		slaves.b.pcm "hdmiDmix"
		slaves.a.channels 2
		slaves.b.channels 2

		bindings.0.slave a
		bindings.0.channel 0
		bindings.1.slave a
		bindings.1.channel 1

		bindings.0.slave b
		bindings.0.channel 0
		bindings.1.slave b
		bindings.1.channel 1
	}

	ttable.0.0 1
	ttable.1.1 1
}

pcm.!default {
	type plug
	slave {
		pcm internalDmix
	}
}

ctl.!default {
	type hw
	card 1
}
If it helps, this /etc/asound.conf makes the internal speakers work (no HDMI):
Code:
[anthony@newerLaptop ~]$ cat /etc/asound.conf | grep -v "#"

pcm.internal {
	type hw
	card 1
}
ctl.internal {
	type hw
	card 1
}



pcm.internalDmix {
	type dmix
	ipc_key 1024
	slave {
		pcm "internal"
		channels 2
	}
	bindings {
		0 0
		1 1
	}
}



pcm.!default {
	type plug
	slave {
		pcm internalDmix
	}
}

ctl.!default {
	type hw
	card 1
}
 
Old 08-28-2015, 05:02 PM   #4
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 814

Original Poster
Rep: Reputation: 265Reputation: 265Reputation: 265
I think I'm going to leave good enough alone.

Also, I was directed to a "more correct" method on the debian-user mailing lists: https://lists.debian.org/debian-user.../msg00985.html

Quote:
To select the order of the devices for one particular device (your case):

Code:
options snd-hda-intel index=1,0
This has the added benefit of making my internal microphone work. I don't use it often so I didn't even realize that it wasn't working; but it does now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alsa not outputting sound TheStarLion Debian 1 04-03-2013 09:45 AM
alsa problem with 2 programs outputting sound librano Mandriva 3 04-18-2006 01:26 PM
sound cards and alsa? ericb Linux - Hardware 3 09-07-2005 12:48 AM
alsa + 2 sound cards atrain Linux - Hardware 2 02-13-2005 11:51 AM
ALSA + 2 Sound Cards codyman Linux - General 3 08-14-2004 09:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration