You are not logged in.

#1 2014-10-17 21:39:13

Rybelda
Member
Registered: 2014-10-17
Posts: 2

5.1 Surround over HDMI: Solve one problem, another rises up.

UPDATE 1:  After a good night's sleep, and after doing a bit more reading on alsa-project.org (big props to this page), I managed to get a much better ~/.asoundrc together.  It solves all my problems, and I can do everything I need.  I've preserved the post below in case anyone else runs into these issues, and I'll post my solution as a response to this post.

UPDATE 2:  Looks like I celebrated too early.  Got more strange problems.  Screw it, I'm going back to PulseAudio.  I just wrote a wrapper script to kill and restart Pulse for applications that really, really need ALSA.

* * *

Okay.  I've almost completely worn out my fingers trying to get this working.  I feel like I'm playing Whack-a-Mole.  This is a bit of a lengthy post, but I'll try my best to describe every problem I've encountered in as much detail as I can, followed by the solutions I found, followed by the problems each solution brought with it.  By going through everything this way, mole by mole, hopefully it'll be easy to follow along and help me come to a universally working solution.


Summarized Version of Problems:

  1. 5.1 surround works only on specific applications which are robust enough to allow me to manually specify audio output options, and only if ALSA isn't configured at all

  2. once I've configured ALSA, sound works on every application, but it's all downmixed to 2.0 stereo from this point on

  3. installing PulseAudio lets me choose 5.1 surround as a default, but brings with it its own problems and drawbacks, namely the lack of passthrough support for encoded streams


Long-Winded Version:

I have my computer connected over HDMI to an AVR with a 5.1 surround speaker system.  At first, I didn't have anything configured in ~/.asoundrc (or its global equivalent, /etc/asound.conf).  Neither file existed, so everything was running off defaults.  I got the name and device number of my card from aplay, ran speaker-test and played a six-channel test file in mplayer.

$ 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

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
hdmi:CARD=HDMI,DEV=0
    HDA Intel HDMI, HDMI 0
    HDMI Audio Output

$ speaker-test -Dhdmi -c6

speaker-test 1.0.28

Playback device is hdmi
Stream parameters are 48000Hz, S16_LE, 6 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 64 to 349504
Period size range from 32 to 174752
Using max buffer size 349504
Periods = 4
was set period_size = 174752
was set buffer_size = 349504
 0 - Front Left
 4 - Front Center
 1 - Front Right
 3 - Rear Right
 2 - Rear Left
 5 - LFE
Time per period = 21.868405

$ mplayer -ao alsa:device=hdmi -channels 6 Nums_5dot1_24_48000.wav 
MPlayer SVN-r37224 (C) 2000-2014 MPlayer Team
210 audio & 441 video codecs
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing Nums_5dot1_24_48000.wav.
libavformat version 55.33.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 48000 Hz, 6 ch, s24le, 6912.0 kbit/100.00% (ratio: 864000->864000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
[AO_ALSA] Format s24le is not supported by hardware, trying default.
AO: [alsa] 48000Hz 6ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   8.6 (08.5) of 9.0 (09.0)  0.3% 


Exiting... (End of file)

Everything seemed well, all six channels played from the correct location on both tests, but I did realize that the device number of the card was 3, not 0.  A lot of applications that aren't as configurable expect the default card/device to be set properly, and audio won't work in those applications without specifying that in ALSA's configuration.  Knowing this, I set the following in my ~/.asoundrc:

pcm.!default {
        type hw
        card HDMI
        device 3
}

ctl.!default {
        type hw
        card HDMI
        device 3
}

This, however, ended up causing more problems.  Oh, it made sound work on everything by default after that, but only for one application at a time!  That surpised me, as I thought ALSA's big advantage over OSS is that it can multitask.  Running the speaker-test the way I did earlier turned out fine, but when I tried playing that test file in mplayer, things got weird again. Here's the output from mplayer:

$ mplayer -ao alsa -channels 6 Nums_5dot1_24_48000.wav 
MPlayer SVN-r37224 (C) 2000-2014 MPlayer Team
210 audio & 441 video codecs
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing Nums_5dot1_24_48000.wav.
libavformat version 55.33.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 48000 Hz, 6 ch, s24le, 6912.0 kbit/100.00% (ratio: 864000->864000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
[AO_ALSA] alsa-lib: pcm_hw.c:1557:(snd_pcm_hw_open) open '/dev/snd/pcmC0D0p' failed (-2): No such file or directory
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video


Exiting... (End of file)

Why the hell is it looking for pcmC0D0p?  It should be looking at pcmC0D3p.  Did it not get the memo from ~/.asoundrc?  Urgh.

I've also tried '-af channels=6' in place of '-channels 6' but the same result happened.  It does the same thing without the '-ao alsa' option, I just specified it to trim down the output, so that I wouldn't be copying and pasting all kinds of other errors about not finding OSS or JACK or other things I don't have installed.

If I symlink /dev/snd/pcmC0D0p to /dev/snd/pcmC0D3p, it'll fix the problem, but that feels like one ugly kludge.  I'd have to do it again over and over every time I reboot, too.

Not sure if this would help matters or not, but if anyone knows how to change my card's device number from 3 to 0, I'd like to try that as well, but I'm not sure how to do that sort of thing.  I'm just guessing it might be worth trying, since everything looks for card0/device0 by default, and that kludge I tried earlier did have an effect, so maybe if we can just switch those device numbers with each other, everything would work smoothly without having to force anything through ALSA's configuration at all.  I believe card0/device0 belongs to the Host Bridge... is there a way to have them trade their device numbers for one another's in a safe manner?

I can also get it to play if I specify the device like I did in my first test, using '-ao alsa:device=hdmi', but that defeats the purpose of getting good defaults set if I still have to set everything by hand before I play something.  If I try playing the test file without any options, like so:

$ mplayer Nums_5dot1_24_48000.wav

... it will play, but only in two-channel stereo, and the parts that should happen in the center, rear and LFE channels get downmixed into the left and right channels.

I can get it to work in aplay, though!  All six channels!  Not that I plan on using this as my primary multimedia software.

$ aplay -c6 Nums_5dot1_24_48000.wav

The only solution I found so far that allows me to have 5.1 audio by default is to install the PulseAudio server, which is able to find a sink/source named 'alsa_output.pci-0000_00_03.0.hdmi-surround' and lets me choose that as my default.  Only problem with this is that PulseAudio has its own problems.

Aside from the crackling sound issues in some Wine games, Pulse also has a much bigger drawback -- a complete lack of passthrough support, meaning I can't use encoded streams such as Dolby DTS and TrueHD with PulseAudio.  I have a Harman/Kardon AVR and I'd like to get my money's worth out of it, so I'd really like to figure out a solution in ALSA without using Pulse at all.

Does anyone know how I can have my cake and eat it, too?  I just need 5.1 surround, by default, in ALSA without PulseAudio.

HUGE thanks to anyone who tries to help here.  This is really making me sad and frustrated, I've been using Arch for quite a while now and this is the first real big stumper I've come across that forced me to post a thread.  Otherwise I've been having a wonderful time.

Edited because I tried something different that removed *some* issues, but the above problems still remain.

Last edited by Rybelda (2014-10-27 22:10:24)

Offline

#2 2014-10-18 20:02:01

Rybelda
Member
Registered: 2014-10-17
Posts: 2

Re: 5.1 Surround over HDMI: Solve one problem, another rises up.

Well, I thought I fixed it doing this...

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

pcm.dmixer {
	type dmix
	ipc_key 1138
	ipc_key_add_uid true
	slave {
		pcm "hw:0,3"
		format S32_LE
		channels 8
		rate 192000
		period_size 9600
		buffer_size 38400
	}
}

... but then realized it strangely makes applications that run at 640x480 have no sound at all.  No idea why the video resolution is screwing up the sound, but that's what's happening, because if I set the resolution any higher, the sound comes back.

I'm going back to PulseAudio, I feel like ALSA is mocking me.  I wrote a wrapper script for the few times where pure, Pulse-less ALSA will be necessary for me.  Here it is, in case it helps anyone else.  I've tested it with XBMC, it turns off Pulse and allows ALSA to pass through encoded streams unhindered.  It also works with some Wine applications that have scratchy audio glitches in Pulse.

#!/bin/bash

echo "autospawn = no" > $HOME/.config/pulse/client.conf
pulseaudio --kill &> /dev/null

"$*"

rm -f $HOME/.config/pulse/client.conf
pulseaudio --start &> /dev/null

I'm removing the SOLVED tag because technically I didn't resolve any of my original issues, I more or less gave up on what I wanted to do and found another way to satisfy my needs, but it still isn't as elegant as I had hoped for.  In any case, I'm done with this issue for now and the forseeable near-future, but if anyone has anything further to add, feel free. smile

Last edited by Rybelda (2014-10-27 22:32:55)

Offline

Board footer

Powered by FluxBB