This is a small library to quickly and prototype .NET apps with real hrtf positional audio with a super simple interface, without the need of a huge middleware like Unity.
It's a simple wrapper over the XAudio 2 HRTF XAPO, introduced by Microsoft to develop immersive apps with Hololens.
-
This library targets Microsoft Windows 10 only, as it leverages the latest XAudio 2.9, shipped by default with this system version. Previous Windows versions won't work.
-
XAudio 2 hrtf APO only supports 48k samplerate mono wav files. There's no conversion on any kind in this library for now, so act accordingly.
PositionalSound sound = new PositionalSound("path_to/sound_file.wav");
Creates an infinite looping positional sound, placed in the origin, in a Small environment.
PositionalSound sound = new PositionalSound("path_to/sound_file.wav", 10);
Creates a positional sound lasting 10 loops, in a small environment.
PositionalSound sound = new PositionalSound("path_to/sound_file.wav", 10, HrtfEnvironment.Outdoors);
Creates a positional sound lasting 10 loops, in a Outdoor environment.
sound.Play();
sound.Stop();
sound.X = 1.0f;
sound.Y = 10;
sound.Z = -2.0f;
sound.SetPosition(1.0f, 10, -2.0f);
Both these methods will immediately update the sound, as soon as values change.
sound.Volume = 0.5f;
A sound will react differently to the size of the surrounding environment. You can change a sound environment at any moment via the HrtfEnvironment enum:
sound.Environment = HrtfEnvironment.Medium;
These environments are currently available:
- Small
- Medium
- Large
- Outdoors
This project ships with a simple WPF test app, allowing to play with the library features. Clone the repository, build the solution and run Xaudio2HrtfWPFTest project.
As you can see, this library is far from being complete: only omnidirectional sources with very basic customization. If anyone finds this project interesting and wants to fill the gaps, improve testing or anything else, can freely do so.
This code is released under MIT license.
The test sound and part of the WAV loader comes from Microsoft Universal Samples also released under MIT license.