HRTF Info

Folks, I’m moving my HRTF/spatial sound project over to Patreon. Lots of interesting news! Check out the main post to see what its all about!! 🙂

Contents

Spatial Sound: An Introduction

(Excerpts taken from: http://interface.idav.ucdavis.edu/sound )

Spatial hearing

The hearing scientist Georg von Békésy once said that the purpose of the ears is to point the eyes. As with vision, hearing is three dimensional. We not only hear sounds to the left or right, but also up or down and near or far. How we do this has been studied for a long time, and although some mysteries remain, the major mechanisms are well understood. For example, it is well known that the primary right/left or azimuth cue comes from the difference in the times at which sound waves arrive at the two ears, and the primary up/down or elevation cues come from the spectral changes produced by the outer ears or pinnae. By manipulating these cues, it is possible to change the apparent location of a sound in space.




HRTFs — Head-Related Transfer Functions

The key to this binaural approach to generating synthetic spatial sound is the so-called Head-Related Transfer Function or HRTF, for short. The HRTF captures the location-dependent spectral changes that occur when a sound wave propagates from a sound source to the listener’s ear drum. These spectral changes are due to diffraction of the sound wave by the torso, head, and outer ears or pinnae, and their character depends on the azimuth, elevation, and range from the listener to the source. In general, the HRTF is a complex function of the location of the source relative to the listener, as well as the physical size and shape of the particular listener. When a sound signal is filtered by accurate HRTFs and sent to the listener’s two ears (for example, over headphones), the synthesized sound is experienced as a virtual source at the desired location in space.

Detailes info about HRTF on Wikipedia

Enabling HRTF

(Information taken from this Reddit post and discussion)

OpenAL is the audio library that a handful of games (but most of the ones on Linux) use for positional audio processing. Now, without HRTF, what you’re looking at getting is two arbitrary stereo sources. They only count the audio falloff as it reaches those two sources, giving you barely any sense of direction.

However, HRTF is a technique by which a computer can use a recorded table of how precisely sound is altered as it passes through your ear canal, relative to its position. This tricks your brain into giving you the same audio positioning as real life!

Unfortunately, due to Creative suing to death most/all of the companies putting these capabilities in their sound cards, true positional audio has been somewhat stagnant for quite a while.

However, with a more recent release of OpenAL Soft, they added HRTF right into the base framework!

Linux instructions:

System wide:

For linux users, as long as your ALsoft is reasonably current(>=1.14), all you have to do is this:

echo "hrtf = true" >> ~/.alsoftrc 

(or the system-wide file in /etc/openal/alsoft.conf).
This should enable it for, well, almost all Linux games, including TF2, L4D2, and Wine games!

Windows instructions:

System wide:

For windows, your alsoft.ini is %AppData%\alsoft.ini. Edit this file (or create it) and add:

hrtf = true

Chances are however, your OpenAL is slightly out of date. No worries though, easy to add in.

Download and unzip this file.

On 32-bit Windows: Copy Win32/soft_oal.dll over C:\Windows\System32\OpenAL32.dll

On 64-bit Windows: Copy Win64/soft_oal.dll over C:\Windows\System32\OpenAL32.dll (Yes I know. The naming was their idea, but it really is the 64-bit dll). Then copy Win32/soft_oal.dll over C:\Windows\SysWOW64\OpenAL32.dll (That’s the 32-bit one. Confusing enough yet?)

Using custom HRTF tables

OpenALSoft’s implementation of HRFT uses one dataset to calculate how sound propagates to each ear. Different heads and ear shapes will receive sound differentely, so you may get better spatial sound with different HRTF tables.

Step 1: Pick an HRTF

-Go to http://recherche.ircam.fr/equipes/salles/listen/ and click on DEMO SOUNDS.
-Download every sample (it might take a while).
-Plug in and put on the headphones you will be using for gaming (good-quality IEMs, in theory, will give the best result, but regular headphones are good enough).
-Listen to each sample and mark down the ones that give any sense of positioning (I think the main thing you’re looking for is that it goes in front of you and behind you). It helps if you close your eyes and set it on repeat.
-Once you’ve got the best ones marked, go back through and try to figure out which one’s the best.
-Mark down the number (10**)
-Go to DOWNLOAD and download the file next to your number.
-Unzip it somewhere

Step 2: Convert it to a useable file

Linux Instructions:
All we’re really interested in is the utility that comes with OpenAL Soft called “makehrtf”. It’s a little undocumented, and my linux install didn’t already have OpenAL Soft, so I don’t know if you’ve already got this somewhere. If you do, you can skip the parts where we get it.
-Go to http://kcat.strangesoft.net/openal.html and download the source files.
-Follow the instructions on the site for installing everything.
-At the end of it all, you should have a file called “makehrtf” in the extracted folder.
-Go into the utils folder and find the file called “IRC_1005.def”
-Open the file in a text editor and do a search and replace:
Search: IRC_1005
Replace: IRC_10** (whatever your number is)
-Save it, and then move the file to the root directory, where “makehrtf” is.
-Now, go find the folder where you extracted your HRTF, and copy the whole thing over to the “makehrtf” directory.
-The folder you just copied, rename it to IRC.
-If you’ve done everything right so far, you should be in a directory with a file called “makehrtf”, a file called “IRC_1005.def”, and a folder called IRC. Inside of IRC, there should be two folders called RAW and COMPENSATED.
-Now, open up terminal and change directory to the one with the three things I just listed. Enter the following command:
./makehrtf -m -i=IRC_1005.def
-If it runs properly, it will create a new file in this directory called “oalsoft_hrtf_44100.mhr”

Windows Instructions:
-Go to http://kcat.strangesoft.net/openal.html and download the windows binaries. This is the same file that was in OP’s post, so if you still have it, just use that.
-Extract it somewhere.
-Open the folder and go into “hrtf_defs”.
-Locate a file called IRC_1005.def
-Open the file in a text editor and do a search and replace:
Search: IRC_1005
Replace: IRC_10** (whatever your number is)
-Save it, and then move the file up one level to the main folder.
-Now, go find the folder where you extracted your HRTF, and copy the whole thing over to the folder we’re working in.
-The folder you just copied, rename it to IRC
-If you’ve done everything right so far, you should be in a directory with a file called “makehrtf.exe”, a file called “IRC_1005.def”, and a folder called IRC. Inside of IRC, there should be two folders called RAW and COMPENSATED.
-Open up a command line. You can do this by either finding it in the start menu, or pressing [Windows Key]+R, typing in cmd, and hitting enter (the 1337 way).
-In the command line, change directory to the one with those three things I just mentioned. You can change directory by typing cd “my\directory\here”. If your directory has any spaces in it, the quotes are necessary.
-Now run the following command:
makehrtf.exe -m -i=IRC_1005.def
-If it works properly, it will create a new file called “oalsoft_hrtf_44100.mhr” in that folder.

Step 3: Change the config file

Linux Instructions:
-Open terminal and run
echo “hrtf_tables = \”oalsoft_hrtf_44100.mhr\”” >> ~/.alsoftrc
-Copy the “oalsoft_hrtf_44100.mhr” file to your ~ folder.

Windows Instructions:
-Go to your %APPDATA% folder. I recommend using the method that OP described, where you simply type that into the bar on the start menu. Otherwise, you might put your stuff in the wrong folder (which is what I did), and it won’t work.
-Open the “alsoft.ini” file, which should already be there, if you did what you were supposed to. Add a line which says
hrtf_tables = “oalsoft_hrtf_44100.mhr”
-Copy the “oalsoft_hrtf_44100.mhr” file to the %APPDATA% folder.

HRTF Test Tool

In the downloads page, you can get a small HRTF test app, that plays a simple sound in 3d space. You can then move the sound with the keyboard and test how it feels.