Track the buffer's mapped section
[openal-soft.git] / docs / hrtf.txt
blobba8cd8fa2e6df5f77e2c11ce775279014130a215
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 default data set is based on the KEMAR HRTF data provided by MIT, which can
16 be found at <http://sound.media.mit.edu/resources/KEMAR.html>. It's only
17 available when using 44100hz or 48000hz playback.
20 Custom 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 default 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 is specified below. It uses little-endian byte order.
32 ALchar   magic[8] = "MinPHR02";
33 ALuint   sampleRate;
34 ALubyte  sampleType;  /* Can be 0 (16-bit) or 1 (24-bit). */
35 ALubyte  channelType; /* Can be 0 (mono) or 1 (stereo). */
36 ALubyte  hrirSize;    /* Can be 8 to 128 in steps of 8. */
37 ALubyte  fdCount;     /* Can be 1 to 16. */
39 struct {
40     ALushort distance;        /* Can be 50mm to 2500mm. */
41     ALubyte evCount;          /* Can be 5 to 128. */
42     ALubyte azCount[evCount]; /* Each can be 1 to 128. */
43 } fields[fdCount];
45 /* NOTE: ALtype can be ALshort (16-bit) or ALbyte[3] (24-bit) depending on
46  * sampleType,
47  * hrirCount is the sum of all azCounts.
48  * channels can be 1 (mono) or 2 (stereo) depending on channelType.
49  */
50 ALtype coefficients[hrirCount][hrirSize][channels];
51 ALubyte delays[hrirCount][channels]; /* Each can be 0 to 63. */
54 The data is described as thus:
56 The file first starts with the 8-byte marker, "MinPHR02", to identify it as an
57 HRTF data set. This is followed by an unsigned 32-bit integer, specifying the
58 sample rate the data set is designed for (OpenAL Soft will not use it if the
59 output device's playback rate doesn't match).
61 Afterward, an unsigned 8-bit integer specifies how many sample points (or
62 finite impulse response filter coefficients) make up each HRIR.
64 The following unsigned 8-bit integer specifies the number of fields used by the
65 data set.  Then for each field an unsigned 16-bit short specifies the distance
66 for that field (in millimeters), followed by an 8-bit integer for the number of
67 elevations.  These elevations start at the bottom (-90 degrees), and increment
68 upwards.  Following this is an array of unsigned 8-bit integers, one for each
69 elevation which specifies the number of azimuths (and thus HRIRs) that make up
70 each elevation.  Azimuths start clockwise from the front, constructing a full
71 circle.  Mono HRTFs use the same HRIRs for both ears by reversing the azimuth
72 calculation (ie. left = angle, right = 360-angle).
74 The actual coefficients follow. Each coefficient is a signed 16-bit or 24-bit
75 sample.  Stereo HRTFs interleave left/right ear coefficients.  The HRIRs must
76 be minimum-phase.  This allows the use of a smaller filter length, reducing
77 computation.  For reference, the default data set uses a 32-point filter while
78 even the smallest data set provided by MIT used a 128-sample filter (a 4x
79 reduction by applying minimum-phase reconstruction).
81 After the coefficients is an array of unsigned 8-bit delay values, one for
82 each HRIR (with stereo HRTFs interleaving left/right ear delays). This is the
83 propagation delay (in samples) a signal must wait before being convolved with
84 the corresponding minimum-phase HRIR filter.