Add a text file explaining OpenAL Soft's HRTF support and data file format
[openal-soft.git] / hrtf.txt
blob5810ea7a1babfc8af2459e7f2189099f4e43cc11
1 HRTF Support
2 ============
4 Starting with OpenAL Soft 1.14, HRTFs can be used to enable enhanced
5 spatialization for both 3D (mono) and multi-channel sources, when used with
6 headphones/stereo output. This can be enabled using the 'hrtf' config option.
8 For multi-channel sources this creates a virtual speaker effect, making it
9 sound as if speakers provide a discrete position for each channel around the
10 listener. For mono sources this provides much more versatility in the perceived
11 placement of sounds, making it seem as though they are coming from all around,
12 including above and below the listener, instead of just to the front, back, and
13 sides.
15 The built-in data set is based on the KEMAR HRTF diffuse data provided by MIT,
16 which can be found at <http://sound.media.mit.edu/resources/KEMAR.html>. It's
17 only available when using 44100hz playback.
20 External HRTF Data Sets
21 =======================
23 OpenAL Soft also provides an option to use user-specified data sets, in
24 addition to or in place of the built-in set. This allows users to provide their
25 own data sets, which could be better suited for their heads, or to work with
26 stereo speakers instead of headphones, or to support more playback sample
27 rates, for example.
29 The file format for the data sets is specified below. It uses little-endian
30 byte order. Certain data fields are restricted to specific values (these
31 restriction may be lifted in future versions of the lib).
34 ALchar   magic[8] = "MinPHR00";
35 ALuint   sampleRate;
37 ALushort hrirCount; /* Required value: 828 */
38 ALushort hrirSize;  /* Required value: 32 */
39 ALubyte  evCount;   /* Required value: 19 */
41 ALushort evOffset[evCount]; /* Required values:
42   { 0, 1, 13, 37, 73, 118, 174, 234, 306, 378, 450, 522, 594, 654, 710, 755,
43     791, 815, 827 } */
45 ALshort coefficients[hrirCount][hrirSize];
46 ALubyte delays[hrirCount]; /* Element values must not exceed 127 */
49 The data are described as thus:
51 The file first starts with the 8-byte marker, "MinPHR00", to identify it as an
52 HRTF data set. This is followed by an unsigned 32-bit integer, specifying the
53 sample rate the data set is designed for (OpenAL will not use it if the output
54 device's playback rate doesn't match).
56 Afterward, an unsigned 16-bit integer specifies the total number of HRIR sets
57 (each HRIR set is a collection of impulse responses forming the coefficients
58 for a convolution filter). The next unsigned 16-bit integer specifies how many
59 samples are in each HRIR set (the number of coefficients in the set). The
60 following unsigned 8-bit integer specifies the number of elevations used by the
61 data set.
63 Following this is an array of unsigned 16-bit integers, one for each elevation
64 which specifies the offset to the start of the HRIR sets for each given
65 elevation (the number of HRIRs at each elevation is infered by the offset to
66 the next elevation, or by the total count for the last elevation).
68 The actual coefficients follow. Each coefficient is a signed 16-bit sample,
69 with each HRIR set being a consecutive number of samples. For each elevation,
70 the HRIR sets first start with a "neutral" set (that is, one that is applied
71 equally to the left and right outputs). After this, the HRIR sets follow a
72 clockwise pattern, with the first half specifying the "occluded" HRIRs (for the
73 ears on the opposite side of the sound source) for half of the head, and the
74 remaining specify the un-occluded HRIRs (for the ears on the side of the sound
75 source) for half of the head. OpenAL Soft will automatically select the HRIR
76 sets to use based on the angle to the source from the listener, and swap them
77 depending on which side the sound is on.
79 After the coefficients is an array of unsigned 8-bit delay values, one for each
80 HRIR set. This is the delay, in samples, after recieving an input sample before
81 before it's added in to the convolution filter that the corresponding HRIR set
82 operates on.