Surround 5.1 experiment

Questions about Wine on Linux
Post Reply
krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Surround 5.1 experiment

Post by krumpf » Mon Sep 20, 2021 7:53 am

After doing some researches on the web, I found that site which lists many games using surround sound and if it's working on Windows.
So I wanted to check if wine would allow 5.1 to work as well.
I'm using an alsa setup, pulseaudio is not installed.

I've done some tests using either an empty .asoundrc file, or one that expose the soundcard as 6 channels capable to the apps.

My .asoundrc file:

Code: Select all

pcm.!default {	type plug	slave.pcm "duplexIO"}
########## duplex ##############
pcm.duplexIO {
	type asym
	playback.pcm "dmixer"
	capture.pcm "D2capture"
}
########### mixer ##############
pcm.dmixer {
	type dmix
	ipc_key 1337
	ipc_key_add_uid true
	slave {
		pcm "XonarD2"
		channels 6
		period_size 1024 # fixes cracks for me, might depend on sound chip
	}
}
########### capture ############
pcm.D2capture {
	type dsnoop
	ipc_key 31416
	ipc_key_add_uid true
	slave.pcm "XonarD2"
}
####### Xonar D2 Analog  #######
pcm.XonarD2 {
	type hw
	card D2
	device 0
}
I also got a Stereo Upmix option in alsamixer, set on disabled, so the driver won't perform a stereo to 5.1 upmix.

Let's use speaker-test app, included in alsa-utils, to conduct a first test.
speaker-test -c 6 -t wave # -c 6 to use 6 channels, and -t wave to have a nice voice telling speaker name instead of a noise
- empty asoundrc: only FL and FR speakers
- with asoundrc: all speakers are working

This test leads me to believe my .asoundrc is doing its job properly.

Now, let's try with Wine.

I'm on Gentoo, so wine is compiled from sources with alsa-lib, faudio, gstreamer, mpg123, openal audio-related flags (https://wiki.winehq.org/Building_Wine) No pulseaudio flag, it's not installed on my system.

For each game tested, settings in winecfg Audio tab:
- Output device set on "Out: default"
- Speaker configuration: device "Out: default" to "5.1 Surround"

Using these settings, let's push the winecfg Test Sound button
- no asoundrc: stereo output only
- with asoundrc: all speakers produce sound

Now let's try in games:

Witcher 3:
- no asoundrc: stereo output only
- with asoundrc: stereo output only, no sound from rears/center

Crysis 2:
- no asoundrc: stereo output only
- with asoundrc: stereo output only, no sound from rears/center

Secret World Legends: (game is not in the list, but it has an option to use 5.1 surround speakers)
- no asoundrc: stereo output only
- with asoundrc: stereo output only, no sound from rears/center

Unfortunately, none of the tested games gave me the expected 5.1 sound like it would on Windows, despite the Test Sound in winecfg working.
So I'm wondering: am I doing something wrong ?
Am i missing some dlls that I should install with winetricks ? I know xact can sometimes solve issues, but neither Witcher 3 or Crysis 2 are using xAudio API.
Is pulseaudio the only audio backend that allows 5.1 surround to work properly ?
Is the 5.1 surround only supported for directsound in Wine ?


Now, if more people owning a 5.1 surround set want to test, please do and post the results (but remember to disable stereo to 5.1 upmix in your driver - or in pulseaudio if you're using it).
Thanks for reading

krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Re: Surround 5.1 experiment

Post by krumpf » Wed Sep 22, 2021 5:01 am

So, I've done some more testing, this time using MPC-BE(portable version), and a video with 5.1 sound from fraunhofer page (HE-AAC Channel ID - With H.264 Video - download the file from the page)

I've created a fresh wineprefix, no extra stuff from winetricks, winecfg audio tab set as in previous post.

After launching mpc-be through wine, I got to Options - Audio, and set the renderer to "DirectSound: Out: default"
With these settings, the fraunhofer video only uses front left/right speakers.
Now, small changes in mpc-be settings, setting the audio renderer to "MPC audio renderer" (its internal properties are set to "Primary Sound Driver").
Playing the fraunhofer video again, and... it works. All channels are played in their associated speakers.

So, using 5.1 sound works in Wine. But then, why doesn't it work with games ? Could there be an issue between the API used by games and wine audio layer ? I really don't get it :?

Also, am I the only guy using 5.1 speakers here ? It would be nice if another user could confirm or deny my experimentation results.

On a side note: Alsa provides a upmix plugin, that turns stereo to 5.1, but leaves 5.1 sources untouched. I'm using it with mpv media player, and it works nicely with fraunhofer video, and in movies, the 6 channels are played correctly.
Of course, I've tried it in games, it sure does fill the center/rear speakers, but it's not true 5.1, just upmixed stereo, the rear channels just play a copy of front ones. :?

krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Re: Surround 5.1 experiment

Post by krumpf » Wed Sep 22, 2021 3:47 pm

I think I found the culprit: the "plug" plugin in asoundrc.
I've been trying another .asoundrc where i removed it

Code: Select all

pcm.!default {
	type asym
	playback.pcm "dmixer"
	capture.pcm "D2capture"
}
########### mixer ##############
pcm.dmixer {
	type dmix
	ipc_key 1337
        ipc_key_add_uid true
	slave {
		pcm "XonarD2"
		channels 6
		period_size 1024 # fixes cracks (Talos Principle, Witcher 3)
	}
}
########### capture ############
pcm.D2capture {
    type dsnoop
    ipc_key 31416
    ipc_key_add_uid true
    slave.pcm "XonarD2"
}
####### Xonar D2 Analog  #######
pcm.XonarD2 {
	type hw
	card D2
	device 0
}
With those settings, I retested Crysis 2, Witcher 3 & Secret World, all produced sound from the rear/center speakers. Yay !
But then I figured out with the "plug", Firefox wouldn't produce any more sound :?
I feel more & more condemned to install pulseaudio :(

krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Re: Surround 5.1 experiment

Post by krumpf » Thu Sep 23, 2021 3:12 pm

Been doing some more tests. Using this asoundrc file

Code: Select all

pcm.!default {
	type asym
	playback.pcm "convert"
	capture.pcm "D2capture"
}
###### format conversion ######
pcm.convert {
	type plug
	slave.pcm "dmixer"
	rate_converter "samplerate_medium"
	slave.channels "unchanged"
#	slave.channels 6
}
########### mixer ##############
pcm.dmixer {
	type dmix
	ipc_key 1337
    ipc_key_add_uid true
	slave {
		pcm "XonarD2"
		channels 6
		period_size 1024 # fixes cracks (Talos Principle, Witcher 3)
	}
}
########### capture ############
pcm.D2capture {
    type dsnoop
    ipc_key 31416
    ipc_key_add_uid true
    slave.pcm "XonarD2"
}
####### Xonar D2 Analog  #######
pcm.XonarD2 {
	type hw
	card D2
	device 0
}
In the format conversion plugin, if I use slave.channels "unchanged" :
- Wine audio tab Test Sound button does not produce sound (why ?)
- Using MPC-BE to play the fraunhofer 5.1 video works
- In games launched with Wine, surround 5.1 is played properly (positional audio works!)

If I use slave.channels 6 (or just remove the slave.channels line):
- Wine audio tab Test Sound button make sound in all speakers
- Using MPC-BE to play the fraunhofer 5.1 video does not work, the rear channels are played in front speakers at a lower volume (but then how come the wine test sound worked ?)
- In games, I only get stereo sound, rear/center stay silent

krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Re: Surround 5.1 experiment

Post by krumpf » Sat Sep 25, 2021 2:16 pm

Even more testing has been done.

This time, I've installed pulseaudio (PA) , and recompiled wine with PA support.
Pavucontrol set to use analog 5.1 output + analog stereo input (quite the same thing I'm doing with asoundrc)
Important settings in PA ~/.config/pulse/daemon.pa

Code: Select all

enable-remixing = yes  # so when switching PA to stereo mode, 5.1 sources get downmixed to stereo
remixing-use-all-sink-channels = no # if yes, every non-5.1 sound source gets upmixed to saturate all speakers
Wine audio tab, everything set to PA, and PA speaker config on 5.1

Crysis 2 --> 5.1 positional audio works perfectly

Secret World --> 5.1 audio works BUT sound pops & crackles. Been trying quite a lot of PA tricks (tweaking PULSE_LATENCY_MSEC, changing stuff in PA daemon config, load the udev module with tsched=0, etc..), none helped.
On a side note: I also tried this game with my headphones (game audio output on 5.1, pavucontrol output on analog stereo duplex, that's where PA remixing shines), and it worked perfectly, without any pop or crack.

Cyberpunk 2077 --> 5.1 positional audio works, BUT sound pops & crackles. After failing to make Secret World work properly, I didn't even bother trying PA known tricks.

The Witcher 3 --> PA only gave me stereo sound, rear/center speakers were silent, while it works perfectly on pure alsa. On my pc, Witcher & Cyberpunk use the same wineprefix, and according to this page, both games use the same audio API, so I don't get why 5.1 works with Cyberpunk and not with Witcher.

I'm quite disappointed in PA performances. I thought it was supposed to make audio easier to config, but it just brought me more problems :? So, back to pure alsa for now, guess I'll keep an eye on Pipewire and will give it a try when it'll be a bit more mature.

krumpf
Level 2
Level 2
Posts: 13
Joined: Tue Nov 10, 2020 5:37 am

Re: Surround 5.1 experiment

Post by krumpf » Mon Sep 27, 2021 5:45 am

Code: Select all

pcm.!default {
	type asym
	playback {
		pcm {
			@func getenv
			vars [ ALSAPLUG ]
			default "convert"
		}
	}
	capture.pcm "D2capture"
}

###### format conversion ######
defaults.pcm.rate_converter "samplerate_medium"
pcm.convert {
	type plug
	slave.pcm "dmixer"
}
pcm.convertWine {
	type plug
	slave.pcm "dmixer"
	slave.channels "unchanged"
}
This will make all sounds go through the default route -here the convert plugin- but also create a new env variable ALSAPLUG which can be used in commandline/script to make an application use another alsa route. With that, I can get 5.1 sound to work perfectly in games, and keep sounds coming from other apps such as Firefox or Discord. All on pure alsa system, without need to bother with pulseaudio.

Post Reply