115 Commits

Author SHA1 Message Date
Chris Robinson
566d449e53 Always load HRTF files through memory pointers 2016-08-31 08:16:49 -07:00
Chris Robinson
f791b8c517 Add a compile-time macro to use dual-band ambisonic HRTF processing
Use single-band processing for now, to see if dual-band is causing a drop in
quality at all.
2016-08-30 22:33:33 -07:00
Chris Robinson
846cdd472d Band-split the HRIRs when building the ambisonic decoder filters
This allows each HRIR to contribute a frequency-dependent response, essentially
acting like a dual-band decoder playing over the cube speaker array.
2016-08-21 03:05:42 -07:00
Chris Robinson
d16954c34e Fix HRTF index calculations for B-Format coefficients
The CalcEvIndices and CalcAzIndices methods were dependent on the FPU being in
round-to-zero mode, which is not the case for panning initialization. And since
we just need the closest index and don't need to lerp between them, it's better
to just directly calculate the index with rounding.
2016-08-18 23:33:08 -07:00
Chris Robinson
e13c6bca20 Only use the cube points for generating the ambisonic HRTF coefficients
Using all the HRIRs seems to have problems with volume balancing, due in part
to HRTF data sets not having uniform enough measurements for a simple decoder
matrix to work (and generating a proper one that would work better is not that
easy). This still maintains the benefits of decoding ambisonics directly to
HRTF, namely that it only needs to filter the 4 ambisonic channels and can use
more optimized HRTF filtering methods on those channels. It can also be
improved further with frequency-dependent processing baked into the generated
coefficients, incurring no extra run-time cost for it.
2016-08-17 05:34:09 -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
c0e7aab823 Properly skip loading of already-loaded HRTF data sets
Previously, if an HRTF file was loaded it would not only skip loading it, but
it would also skip adding it to the output enumeration list. Now it properly
skips loading it when it's already loaded, but still adds it to the enumeration
list if it's not already in it.
2016-07-24 21:59:02 -07:00
Chris Robinson
ee929a2eea Enumerate the embedded HRTF resources when available 2016-07-12 19:02:19 -07:00
Chris Robinson
745cad5231 Avoid standard malloc/free for Hrtf allocation 2016-07-07 10:31:43 -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
f4ff5fc106 Shorten VECTOR_ITER_ macros to VECTOR_ 2016-04-15 12:22:54 -07:00
Chris Robinson
b6824ca716 Add and use a copy-range string function 2016-02-24 04:53:32 -08:00
Chris Robinson
d04970e568 Exclude the file extension from the HRTF name 2016-02-24 04:21:03 -08:00
Chris Robinson
68a2ae4024 Replace the hrtf_tables option with hrtf-paths 2016-02-23 10:56:06 -08:00
Chris Robinson
ae1a2fa9c0 Allow selecting a preferred HRTF in alsoft-config
This currently only checks the default paths when they're being used.
2016-02-23 06:52:13 -08:00
Chris Robinson
bd233c8cdb Avoid enumerating the same HRTF file twice 2016-02-21 04:46:14 -08:00
Chris Robinson
e6f120df23 Add a config option to specify the preferred HRTF 2016-02-21 02:44:02 -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
7ff5cf7820 Allocate each HRTF as a single chunk 2016-02-16 19:56:44 -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
455d5f48c0 Use %s.mhr for the default hrtf table list 2015-12-05 17:49:05 -08:00
Chris Robinson
de74498cd9 Use more accurate floating point literals 2015-11-06 10:27:28 -08:00
Chris Robinson
8d89c8be9e Remove a couple unused parameters 2015-10-24 16:57:32 -07: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
64858e3e94 Fix B-Format HRTF decoding 2015-09-23 16:02:46 -07:00
Chris Robinson
4bdd58bc83 Use N3D scaling instead of FuMa 2015-09-23 15:03:53 -07:00
Chris Robinson
5f5eebc4df Allow the hrtf_tables option to be device-specific 2015-09-20 08:28:34 -07:00
Chris Robinson
b348abf5c3 Rename F_2PI to F_TAU 2015-09-13 08:46:48 -07:00
Chris Robinson
e5fa4ee25d Allow for device-specific config values 2015-08-28 14:10:39 -07:00
Chris Robinson
bbc16e2c15 Use ACN ordering for ambisonics coefficients arrays
Note that it still uses FuMa scalings internally. Coefficients loaded from
config files specify if they're FuMa (in both ordering and scaling) or N3D,
and will get reordered or rescaled as needed.
2015-08-28 10:58:30 -07:00
Chris Robinson
b4c9744d6a Fix the HRTF B-Format decoder's W coefficient
And limit it to first-order again, since there will likely need to be extra
scalings applied.
2015-02-14 12:11:50 -08: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
cf5856ed48 Correct conversion from polar to cartesian coords for HRTF
A functional no-op (cos(a) == cos(-a), -sin(a) == sin(-a)), but Ambisonics
expects the azimuth angle to go counter-clockwise.
2015-02-10 05:38:16 -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
c37a971947 Rename step to steps 2014-11-24 00:24:12 -08:00
Chris Robinson
837b38b166 Swap delta and step, remove double semicolons 2014-11-23 18:07:19 -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
François Cami
3c13e1e333 Update COPYING to the latest https://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt to fix the FSF' address Fix the FSF' address in the source 2014-08-18 11:34:29 -07:00
Chris Robinson
23cae7783d Properly scale the first HRTF pass-through coefficient
Coefficients are scaled by 32767. For pass-through, this is attenuated by
sqrt(0.5) to maintain a consistent perceived volume.
2014-07-17 18:02:23 -07:00
Chris Robinson
15d7ed2f0d Cleanup some HRTF code
Use loops instead of duplicating code, rewrite some lines to be clearer.
2014-07-16 13:26:47 -07:00
Chris Robinson
0d3b18b17d Fix omni-directional moving HRTF coeffs 2014-07-14 09:15:12 -07: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