You are not logged in.

#1 2015-03-30 13:03:29

rabcor
Banned
Registered: 2013-02-09
Posts: 500

[Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

Here is my complete solution.

I've been looking for a way to use HDMI sound through an Nvidia GPU for a wihle now. I will be switching between nouveau and the proprietary drivers a bit (so I need it working on both drivers) but so far haven't gotten it working on either one of the drivers.

In short, this is what it looks like right now:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC1150 Analog [ALC1150 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC1150 Digital [ALC1150 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

(I set the index for the snd_intel_hda module to 1 so that the nvidia hdmi card is the default device, I can easily undo this)

And here is a screenshot of what alsamixer looks like.

Sq2aY6H.png


I am not using any asound.conf/asoundrc configuration file as is, and the HDMI input is the only sound option for my computer which I am using primarily as a media center. What do I need to do to make this work?

Last edited by rabcor (2015-03-30 17:16:14)

Offline

#2 2015-03-30 13:31:47

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

A bit of an update, I found that the hdmi sound is working on device hw:0,7 (This is a bit odd, normally it should be hw:0,3 according to documentation)

Haven't tested on nouveau but I assume it would be the same. However my problem now is that I don't know how to control the volume seeing as alsamixer looks the way it does and I can't configure the volume in there.

Last edited by rabcor (2015-03-30 13:33:42)

Offline

#3 2015-03-30 15:04:10

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

I have figured this out as well now. I simply create a volume control in asoundrc or asound.conf

(With the nvidia hdmi as card 1, not card 0 like it was in the OP)

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

pcm.hdmi-playback{
	type hw
	card 1
	device 7
}

pcm.hdmivol{
	type softvol
	slave.pcm "hdmi-playback"
	control {
    	name "Master"
    	card 1
  	}

Now everything works fine, except that the new master control cannot be muted (so I need to mute hw:1,7 to mute)

Note: If you mess up somewhere and have controls you're not using left over from testing, here's how to reset alsa to default:

rm /var/lib/alsa/asound.state # remove the state file
chmod -x /usr/sbin/alsactl # make alsactl non-executable to prevent settings being written on shutdown
<REBOOT>
chmod +x /usr/sbin/alsactl

After this you just need to edit the asoundrc/asound.conf again to set it back to what you wanted to do, and remember to unmute in alsamixer again.

Offline

#4 2015-03-30 15:54:12

firekage
Member
From: Eastern Europe, Poland
Registered: 2013-06-30
Posts: 623

Re: [Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

Out of curiosity, does this hdmi sound card from nvidia graphic card is being visible in K > system settings > multimedia in KDE? I have something similar, but with XFI. My primary card is XFI (/etc/modprobe.d/alsa-base.conf) with

options snd_ctxfi index=0

and

options snd_hda_intel index=1

but the nvidia sound card from my GTX660 is not being visible by K > system settngs > multimedia in kde, but kmix sees it. Also, in my case, i can only use sound from nvidia with apps that have the ability to change sound outputs - for an exmaple, when i want to watch something using my flat tv screen i change sound from ALSA to  alsa (1.9 HDA - nvidia) in smplayer menu options and i have sound using hdmi on tv, but other apps that does not allow to change it, does not have sound (for an example, firefox does not have sound when i use hdmi and TV because primary sound card is xfi, and nvidia sound card is not being seen in kde mentioned above, so i can't even change it). I don't use asoundrc or asound.conf because i don't understand it.

Last edited by firekage (2015-03-30 15:55:48)

Offline

#5 2015-03-30 16:14:20

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

Hmm, I don't happen to be using kde at the moment so I can't check, but I can confirm that we have very similar cards (I'm on GTX 670, if I remember correctly yours is a bit newer based on mine)

However I did run into a comparable issue, I installed a volume manager called volti (available in AUR) and while it's internal mixer detected my Nvidia card, in the volume I con settings the only selectable card was my intergrated intel card (named PCH in that specific program) this might be related to why you can't see it in kde's multimedia menu.

As for your second issue, I use bomi for video playback, it's a bit better than smplayer2 (it's based on mpv which is a fork of mplayer2, you should try it). But by the sound of it, I think your issue is really simple, notice my .asoundrc where I set the pcm.!default to the HDMI sound output, this makes it the default playback card for all applications that don't specify another card (since most applications just run the default pcm if they don't have an option to specify another pcm or a specific card). If you set it up like I did you should be able to play the sounds from everything (including firefox) on your tv.

You could also try to see what happens if you allow your HDMI card to be card 0 (e.g. assuming your hdmi card is card 2 right now, move the ctxfi index to 1 and hda_intel index to 2; this will make whatever is now card 2 be card 0, as in the next card in line takes that spot) this will ensure that your hdmi card is 100% the default card of Alsa, it might make some difference (That's basically how I did it in the OP)

Edit: I tested this with Volti just for lulz, and I had success. Although volti still doesn't see the nvidia card, it defaults to it and shows me the master channel that I created by default as the volume option. I quite like this since it has a nice internal mixer, I think I'm gonna stick with it since it fits well with my LXDE. I think that the problem we might be having with Volti and KDE's multimedia thing is that they are probably designed with pulseaudio in mind, alsa as an afterthought.(at least in their current versions) and since we are not using pulse, we might be running into these basic problems. But I just really don't wanna use pulse personally.

I'm happy about making volti work, because I really liked it and I was thinking if I wanted a proper mixer I'd have to end up writing it myself (really not in the mood, but it would be good for me, I'm gonna do it one of these days anyways) the last piece of the puzzle is dmixing.

I think we should be manually adding dmixing in the asoundrc, at least according to this we should.

Edit: Oh you said you have an x-fi card, I have one on my other system, I've never run into the problem you've got, although I constantly run into a problem where the card isn't properly initialized on boot.

And yeah; I did some testing and it is really necessary (without dmixing we can only play sound from one source at a time, I'm working on this.)

Last edited by rabcor (2015-03-31 09:23:33)

Offline

#6 2015-03-30 17:15:15

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved] How do I use HDMI sound on Nvidia (Kepler) card with alsa?

I've got it set up now exactly the way I want it I will walk through it again for anyone who stumbles upon this and needs it.

The process requires the alsautils package.

First to make the HDMI card the default soundcard (skip this step if you don't want hdmi sound to be your default device) for alsa you want the HDMI card to be on index 0. Assuming you only have an intel intergrated soundcard and an nvidia card with hdmi audio in your system, add the following to /etc/modprobe.d/alsa.conf

options snd_hda_intel index=1

This leaves the only other card in the system at index 0 which is the default card for alsa. (If you have other soundcards you will have to add them to their own indexes as well after 1, i.e. index 2 and 3 and 4 leaving only 0 for the hdmi card, the reason I'm not just setting the hdmi card to index 0 is because I honestly don't know what the option name for it is, i'm not entirely sure if it actually has one as is.)

To finish setting the card as default, restart your system.

Next to figure out what index your hdmi card is on run aplay -l

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC1150 Analog [ALC1150 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC1150 Digital [ALC1150 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

As you can see my nvidia card is card 0 (after setting it to index 0 correctly) you want to make sure your nvidia card is card 0 if you want it to be your default card, otherwise it doesn't really matter what index it is on.

Now you will want to unmute all the s/pdif channels of your hdmi card via alsamixer to make sure you can get sound.

Next run a series of speaker-tests to find out what the device number of your card is, if you look at the aplay -l list above you can see that there are many entries for card 0, and the device numbers are 3, 7, 8 and 9.

So we run:
(Note: You can replace the number of channels (-c2) with whatever you want, like 6 for a 5.1 speaker system.

speaker-test -D hw:0,3 -c2 -t wav
speaker-test -D hw:0,7 -c2 -t wav
speaker-test -D hw:0,8 -c2 -t wav
speaker-test -D hw:0,9 -c2 -t wav

And whichever of the above commands gives us sound is the correct device.

After establishing what the correct card number and device numbers are, we can create an asound.conf or asoundrc.
(The dmixed pcm is based on this file)

'pcm.dmixed-hdmi {
	type asym
	playback.pcm {
		type dmix

		ipc_key_add_uid true

		ipc_key 5678293
		ipc_perm 0660
		ipc_gid audio

		slave {
                        # 2 for stereo, 6 for surround51, 8 for surround71
			channels 2
			pcm {
				format S32_LE
				#format S16_LE

				#rate 44100
				rate 48000

				nonblock true

				type hw
				card 0
				device 7
				subdevice 0
			}

			# mplayer2 chooses 1024
			# period_size 512 with buffer_size 16384 stops crackling in xmame
			# 320 breaks flash - https://bbs.archlinux.org/viewtopic.php?id=129458
			#period_size 512
			period_size 1024
			#period_size 512

			# 4096 might make sound crackle
			# mplayer2 chooses 8192. Half-Life 2 chooses 16384.
			# If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=2048
			buffer_size 8192
		}
	}
	# apulse (a cut-down replacement for pulseaudio) needs dsnoop
	# https://bbs.archlinux.org/viewtopic.php?id=187258
	capture.pcm "dsnoop"
}

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

pcm.hdmivol{
	type softvol
	slave.pcm "dmixed-hdmi"
	control {
    	name "Master"
    	card 0
  	}
}

Make sure you look at the configurations for the dmixed pcm (i.e. set the correct channel number, and the desired rate and format) most importantly make sure that the card and device numbers in the dmixed pcm match those of your setup, and also make sure that the card number in the hdmivol pcm is the same as the index of your card.

And that's it, now you should have an alsamixer Master (volume) channel for your hdmi card entry in it which you can use for volume control (sadly it can't be muted so you will have to mute the device specifically unless you have a good volume manager like volti) and working dmixed sound. The dmixing is essential, for normal soundcards dmixing is enabled by default in alsa but for digital sources dmixing needs to be manually added or you can only play sound from one source at a time.

Enjoy your hdmi sound. Also if you don't want the HDMI sound to be your default card, just use the hdmivol pcm to use it in programs and set your default pcm to something else (or if you skipped the first step where we made the HDMI card the default alsa card, you can even just not declare default at all instead. You should though if you want to upmix stereo sound to surround sound (refer to the file I linked to above my asoundrc code for more info on that))

Last edited by rabcor (2015-04-01 10:02:15)

Offline

Board footer

Powered by FluxBB