Playing 5.1 surround audio

I have looked around and found some old questions related to this but nothing concretely answered and nothing for unity 5.

I am working on a project where we need control over a specific speaker output. To play sounds out of specific speakers we made a 6 channel wav file. The problem is no matter what I do, unity will consolidate the audio down to 2 channels.

alt text
This is the wav file, it just plays snippets on each channel independently. I have changed the format to PCM so that it doesnt mess with the format too much (you can see 100% ratio in the above image)

The audio source’s Spatial Blend is set to 2D.

Edit > Project Settings > Audio, Default Speaker Mode is set to Surround 5.1

If I output the audio source to a mixer I can see that it correctly has 6 levels, however, the 4 on the right never show activity. In the image below you can see that the channels are separate since only 1 channel has activity at a time (except center and sub channels, which activate both)
alt text

Debug.Log (AudioSettings.GetConfiguration ().speakerMode);

Both of these methods return “Mode5point1”

The only thing that I have found as a lead is that Debug.Log(AudioSettings.driverCapabilities);returns “stereo”. This confuses me since the system is obviously willing and able to play surround sound. I have tested the wav file in other applications and it plays each channel out of a separate speaker.

I have also tried reseting the speaker mode during runtime:

AudioConfiguration config = AudioSettings.GetConfiguration ();
AudioSettings.Reset (config);

If I do this I get no sound output.

Any help or discussion on this would be very appreciated. Thank you so much.

Side note: This project is intended to be published to a select few PCs so I dont need to worry about making it compatible with different sound systems or setups. We will be in control of the computers it will be installed on.

Turns out this is not really a unity issue but an XAudio2 issue.

XAudio2 is an audio engine used in xbox 360 and some windows installs. There seems to be an incompatibility with xaudio and AC3/Dolby Digital audio output where it will erroneously report stereo configuration, so when Unity asks XAudio what the system is capable of it returns “stereo”. This issue affects game engines and many games; anything that would tie into the XAudio API. I was able to find some hacky workaround that involves replacing DLL files in your system directory. For example this was intended to help with the witcher 3 but it works for my purposes.

This is obviously not ideal and I can’t guarantee the safety of downloading these DLLs but it does fix the issue. A better option would be if microsoft provided an update. If anyone has more info on this issue or a better option that would be great.

I have the same issues here with a Realtek sound card.

Try to set new speaker mode at runtime

In the audio settings, I’ve set the default speaker mode to Quad. Also set the speaker mode at runtime

void Awake() {
	Debug.Log ("Caps: " + AudioSettings.driverCapabilities);
	Debug.Log ("Speaker mode: " + AudioSettings.speakerMode);

	AudioConfiguration conf = AudioSettings.GetConfiguration ();
	conf.speakerMode = AudioSpeakerMode.Quad;
	AudioSettings.Reset (conf);

but it doesn’t help.

Use the XAudio DLL patch

The link you’ve posted about patching the XAudio2 DLL doesn’t work here on Windows 10. The ZIP file contains only patches for XAudio2_0.dll, XAudio2_1.dll, …, XAudio2_7.dll but on my system there are only XAudio2_8.dll and XAudio2_9.dll.

Try to patch XAudio2_8.dll and XAudio2_9.dll with a Hexeditor

Found this post about patching the DLL.

Changing xaudio2 DLL files works fine
to fix realtek dolby digital live.
just hex edit the dll files replace

Unfortunately I doesn’t found this hex string in the DLL files, using wxHexEditor.

Use FMOD instead

I know, this is not the best solution, but it works.
By default, FMOD also use stereo sound on this system, but you can force FMOD to use 5.1 sound. In the menu go to FMOD > Edit Settings. Change the Speaker Mode of Play in Editor Settings and Default Settings to 5.1. The disadvantages with this solution are obviously a third party library, managing an additional project (the FMOD Studio project), licensing etc.

Hope anybody find a fix that works with Unity’s native sound engine.

Edit: The FMOD solution works only on my laptop but not for the PC with a on board sound card with a Realtek ALC892.

Additional Test with a new sound card

I’ve test it with a new sound card, a Creative Sound Blaster Z1500 and it works with FMOD and also with Unity’s native sound engine. You have to turn DTS on (Cinema settings in the Control Panel), make loudspeakers as the default audio endpoint (in Windows). FMOD can play stereo WAV files from 3d positions. When I downmix the WAV from stereo to mono, it works with Unity’s native sound engine too. Default Speaker mode is set to Surround 5.1, AudioSource Spatial Blend is set to 1 (=3D) and Spread is set to 360.