Commit Graph

37 Commits

Author SHA1 Message Date
Chris Robinson
2c8e4467c3 Move some HRTF structures to hrtf.h 2018-01-11 03:53:25 -08:00
Chris Robinson
b82d2cf055 Store the HRTF distance in the Hrtf handle 2017-10-23 13:26:35 -07:00
Chris Robinson
88c0d22e7c Don't bother returning the IR length for B-Format decoding 2017-07-31 01:20:42 -07:00
Chris Robinson
e25ba747e6 Remove unused macros 2017-07-25 17:42:16 -07:00
Chris Robinson
8f2e4d46ec Store the HRTF coeffs as a stereo pair
This will make it easier to handle HRTF data sets that have separate left and
right ear responses. Will need an mhr version update to take advantage of that.
2017-04-07 08:46:50 -07:00
Chris Robinson
338d61f907 Reference count HRTFs and unload them when unused 2017-04-06 13:00:29 -07:00
Chris Robinson
2eaa10fc21 Load HRTF files as needed
Currently only applies to external files, rather than embedded datasets. Also,
HRTFs aren't unloaded after being loaded, until library shutdown.
2017-04-05 12:27:30 -07:00
Chris Robinson
f76dea0c03 Store the loaded hrtf entry container in the enumerated hrtf entry 2017-04-05 11:29:58 -07:00
Chris Robinson
e7ca61e8b5 Store the HRTF's filename separate from the entry storage 2017-04-05 07:09:16 -07:00
Chris Robinson
9fb07101dc Load HRTF coefficients as pre-normalized floats 2017-03-31 04:59:09 -07:00
Chris Robinson
96aaab9366 Rework HRTF coefficient fading
This improves fading between HRIRs as sources pan around. In particular, it
improves the issue with individual coefficients having various rounding errors
in the stepping values, as well as issues with interpolating delay values.

It does this by doing two mixing passes for each source. First using the last
coefficients that fade to silence, and then again using the new coefficients
that fade from silence. When added together, it creates a linear fade from one
to the other. Additionally, the gain is applied separately so the individual
coefficients don't step with rounding errors. Although this does increase CPU
cost since it's doing two mixes per source, each mix is a bit cheaper now since
the stepping is simplified to a single gain value, and the overall quality is
improved.
2017-03-11 18:04:06 -08:00
Chris Robinson
98e8f941b7 Allocate as many channels for DirectHrtfState as needed 2017-03-11 06:20:04 -08:00
Chris Robinson
aa56af1ecb Move the B-Format HRTF virtual speaker stuff to InitHrtfPanning
This keeps the decoder matrices and coefficient mapping together for if it
changes in the future.
2017-01-18 19:16:24 -08:00
Chris Robinson
cbb796bf31 Use ALsizei for sizes and offsets with the mixer
Unsigned 32-bit offsets actually have some potential overhead on 64-bit targets
for pointer/array accesses due to rules on integer wrapping. No idea how much
impact it has in practice, but it's nice to be correct about it.
2017-01-16 08:06:25 -08:00
Chris Robinson
9f23d17333 Use second-order ambisonics for basic HRTF rendering
This should improve positional quality for relatively low cost. Full HRTF
rendering still only uses first-order since the only use of the dry buffer
there is for first-order content (B-Format buffers, effects).
2017-01-15 13:57:22 -08:00
Chris Robinson
4bb6b9589f Don't interpolate between nearest HRIRs
It still fades between HRIRs when it changes, but now it selects the nearest
one instead of blending the nearest four. Due to the minimum-phase nature of
the HRIRs, interpolating between delays lead to some oddities which are
exasperated by the fading (and the fading is needed to avoid clicks and pops,
and smooth out changes).
2016-10-09 00:37:47 -07:00
Chris Robinson
c6c6e3324d Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.

This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.

Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-11 23:20:35 -07:00
Chris Robinson
7ec89b4b6e Avoid function calls to get the HRTF sample rate and IR size 2016-07-07 10:26:42 -07:00
Chris Robinson
f0871c8cfc Improve radius behavior with scaling of ambisonic coefficients 2016-04-24 21:42:59 -07:00
Chris Robinson
c2dd681940 Remove an unused declaration 2016-02-20 21:01:24 -08:00
Chris Robinson
e2bbee653e Include the HRTF filename in the HRTF memory chunk 2016-02-20 05:32:42 -08:00
Chris Robinson
e1ce7f9180 Use an 8-channel cube for HRTF's virtual format.
There were phase issues caused by applying HRTF directly to the B-Format
channels, since the HRIR delays were all averaged which removed the inter-aural
time-delay, which in turn removed significant spatial information.
2016-02-20 00:53:01 -08:00
Chris Robinson
ecdc93f3ca Calculate HRTF stepping params right before mixing
This means we track the current params and the target params, rather than the
target params and the stepping. This closer matches the non-HRTF mixers.
2016-02-14 03:23:06 -08:00
Chris Robinson
a9135ec39d Don't pass the channel count to GetBFormatHrtfCoeffs
Since it's hard-coded anyway, there's no need to specify it.
2016-02-09 21:42:24 -08:00
Chris Robinson
0eef6d9d51 Use the enumerated HRTF list for selecting an HRTF
Also report the proper specifier of the one currently in use.
2015-10-06 06:48:53 -07:00
Chris Robinson
1b51ee8b87 Store the Hrtf struct with the corresponding HrtfEntry
Also store the filename with the Hrtf struct so it can be reused for multiple
HrtfEntry objects.
2015-10-06 04:01:53 -07:00
Chris Robinson
a4c378dd00 Enumerate and list HRTFs per-device 2015-10-06 00:23:11 -07:00
Chris Robinson
5f5eebc4df Allow the hrtf_tables option to be device-specific 2015-09-20 08:28:34 -07:00
Chris Robinson
a6e574ba9e Calculate HRTF coefficients for all B-Format channels at once
It's possible to calculate HRTF coefficients for full third-order ambisonics
now, but it's still not possible to use them here without upmixing first-order
content.
2015-02-10 11:22:28 -08:00
Chris Robinson
b9e81794e4 Pass the (FuMa) channel number to GetBFormatHrtfCoeffs 2015-02-10 06:46:02 -08:00
Chris Robinson
a1d4847d07 Use B-Format for HRTF's virtual output format
This adds the ability to directly decode B-Format with HRTF, though only first-
order (WXYZ) for now. Second- and third-order would be easilly doable, however
we'd need to be able to up-mix first-order content (from the BFORMAT2D and
BFORMAT3D buffer formats) since it would be inappropriate to decode lower-order
content with a higher-order decoder.
2015-02-09 15:59:29 -08:00
Chris Robinson
d6ebf5d1b6 Make CalcHrtfDelta more generic 2014-11-24 01:53:45 -08:00
Chris Robinson
45d6bb58a4 Partially revert "Use a different method for HRTF mixing"
The sound localization with virtual channel mixing was just too poor, so while
it's more costly to do per-source HRTF mixing, it's unavoidable if you want
good localization.

This is only partially reverted because having the virtual channel is still
beneficial, particularly with B-Format rendering and effect mixing which
otherwise skip HRTF processing. As before, the number of virtual channels can
potentially be customized, specifying more or less channels depending on the
system's needs.
2014-11-23 10:49:54 -08:00
Chris Robinson
a27e5e1652 Use a different method for HRTF mixing
This new method mixes sources normally into a 14-channel buffer with the
channels placed all around the listener. HRTF is then applied to the channels
given their positions and written to a 2-channel buffer, which gets written out
to the device.

This method has the benefit that HRTF processing becomes more scalable. The
costly HRTF filters are applied to the 14-channel buffer after the mix is done,
turning it into a post-process with a fixed overhead. Mixing sources is done
with normal non-HRTF methods, so increasing the number of playing sources only
incurs normal mixing costs.

Another benefit is that it improves B-Format playback since the soundfield gets
mixed into speakers covering all three dimensions, which then get filtered
based on their locations.

The main downside to this is that the spatial resolution of the HRTF dataset
does not play a big role anymore. However, the hope is that with ambisonics-
based panning, the perceptual position of panned sounds will still be good. It
is also an option to increase the number of virtual channels for systems that
can handle it, or maybe even decrease it for weaker systems.
2014-11-22 04:20:17 -08:00
Chris Robinson
f4cdecebcf Add a source radius property that determines the directionality of a sound
At 0 distance from the listener, the sound is omni-directional. As the source
and listener become 'radius' units apart, the sound becomes more directional.

With HRTF, an omni-directional sound is handled using 0-delay, pass-through
filter coefficients, which is blended with the real delay and coefficients as
needed to become more directional.
2014-07-11 00:03:13 -07:00
Chris Robinson
be903d67b8 Don't pass the device to HRTF methods 2014-06-20 16:43:14 -07:00
Chris Robinson
c68ce288d0 Move HRTF macros and function declarations to a separate header 2014-02-23 21:11:01 -08:00