63 Commits

Author SHA1 Message Date
Chris Robinson
12999f9efe Simplify calculating azimuth and elevation indices for HRTF 2019-03-14 22:26:19 -07:00
Chris Robinson
e4b76d2627 Reverse the HRTF field array
Most often a sound's distance will be beyond the farthest field measurement, so
It's more efficient to have the farthest field first and avoid looping through
the whole field array for them.
2019-02-27 23:13:40 -08:00
Chris Robinson
194fcb6bb7 Rename MAX_AMBI_COEFFS and MAX_AMBI2D_COEFFS 2019-02-19 15:39:33 -08:00
Chris Robinson
69d8c6546d Use std::arrays for HRIR coeffs and values 2019-02-07 08:38:49 -08:00
Chris Robinson
4c740636c2 Pass the distance to GetHrtfCoeffs 2019-01-28 22:22:34 -08:00
Chris Robinson
2d93a9cdb1 Collect HRTF field info into a struct 2019-01-28 20:43:34 -08:00
Chris Robinson
98be1d1bf5 Make IncRef and DecRef member functions 2019-01-24 10:05:37 -08:00
Chris Robinson
d64eaba322 Use a flexible array for DirectHrtfState and ALvoice 2019-01-12 01:25:33 -08:00
Chris Robinson
673983dc5d Make Create methods for structs with flexible array members ...
... that are used with unique_ptr.
2019-01-08 23:44:08 -08:00
Chris Robinson
208ea76922 Cleanup some includes 2018-12-25 11:09:41 -08:00
Chris Robinson
87724db6e3 Rename a couple HRTF structs 2018-12-22 09:20:50 -08:00
Chris Robinson
3553ce1f67 Don't convert the HRTF decoder virtual speaker positions to radians 2018-12-21 08:55:22 -08:00
Chris Robinson
e5db9b2378 Avoid static global initialization functions 2018-12-08 21:58:44 -08:00
Chris Robinson
30ee6e1b3f Make a DirectHrtfState constructor to try appeasing MSVC 2018-11-22 14:36:37 -08:00
Chris Robinson
9c155a57fb Use unique_ptr for DirectHrtfState 2018-11-22 07:54:29 -08:00
Chris Robinson
ab6db9a589 Clean up some unnecessary specifiers 2018-11-22 06:59:32 -08:00
Chris Robinson
e23796aabe Use a standard string for the enumerated HRTF names 2018-11-18 21:18:19 -08:00
Chris Robinson
2c06ec7093 Use a regular vector for the enumerated HRTF list 2018-11-18 19:19:35 -08:00
Chris Robinson
ab9f8162b8 Pass a normal const char* to EnumerateHrtf 2018-11-15 05:38:27 -08:00
Chris Robinson
4bfaa173c4 Convert panning.c to C++ 2018-11-03 19:05:23 -07:00
Chris Robinson
fd1361c198 Add a RESTRICT macro to help with C++ compatibility 2018-10-29 10:10:37 -07:00
Chris Robinson
ec84a107a4 Don't hardcode the max channels for HRTF B-Format decoding 2018-05-26 00:26:11 -07:00
Chris Robinson
72e39ba1c9 Fix a function comment 2018-05-15 22:11:10 -07:00
Chris Robinson
6ff50558a0 Use a proper struct for specifying angular points 2018-02-18 23:56:51 -08:00
Chris Robinson
59768674f1 Use an alternate ambisonic HRTF decode layout
Similar to the previous, but includes the top and bottom HRTF responses. The
higher-order decode (for the "basic" HRTF output) also now uses 2H1P mixed-
order instead of 2H1V, which seems more stable.
2018-02-13 03:03:26 -08:00
Chris Robinson
ee3d53a673 Use an alternate virtual layout for Ambisonic HRTF decoding
This uses 16 channels, an 8-channel octagon + 8-channel cube, which should
improve horizontal resolution without affecting vertical too much.
2018-02-10 05:16:28 -08:00
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