2014-02-24 05:11:01 +00:00
|
|
|
#ifndef ALC_HRTF_H
|
|
|
|
#define ALC_HRTF_H
|
|
|
|
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
|
2017-01-19 03:16:24 +00:00
|
|
|
#include "alMain.h"
|
2015-09-20 11:10:21 +00:00
|
|
|
#include "alstring.h"
|
2017-04-06 20:00:29 +00:00
|
|
|
#include "atomic.h"
|
2015-09-20 11:10:21 +00:00
|
|
|
|
2016-07-07 17:26:42 +00:00
|
|
|
|
2017-04-05 18:29:58 +00:00
|
|
|
/* The maximum number of virtual speakers used to generate HRTF coefficients
|
|
|
|
* for decoding B-Format.
|
|
|
|
*/
|
|
|
|
#define HRTF_AMBI_MAX_CHANNELS 16
|
|
|
|
|
|
|
|
|
2017-04-05 19:27:30 +00:00
|
|
|
struct HrtfEntry;
|
|
|
|
|
2016-07-07 17:26:42 +00:00
|
|
|
struct Hrtf {
|
2017-04-06 20:00:29 +00:00
|
|
|
RefCount ref;
|
|
|
|
|
2016-07-07 17:26:42 +00:00
|
|
|
ALuint sampleRate;
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei irSize;
|
2017-10-23 20:26:35 +00:00
|
|
|
|
|
|
|
ALfloat distance;
|
2016-07-07 17:26:42 +00:00
|
|
|
ALubyte evCount;
|
|
|
|
|
|
|
|
const ALubyte *azCount;
|
|
|
|
const ALushort *evOffset;
|
2017-04-07 15:46:50 +00:00
|
|
|
const ALfloat (*coeffs)[2];
|
|
|
|
const ALubyte (*delays)[2];
|
2016-07-07 17:26:42 +00:00
|
|
|
};
|
2014-02-24 05:11:01 +00:00
|
|
|
|
2017-01-19 03:16:24 +00:00
|
|
|
|
2015-10-06 13:48:53 +00:00
|
|
|
void FreeHrtfs(void);
|
|
|
|
|
2017-04-05 18:29:58 +00:00
|
|
|
vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname);
|
|
|
|
void FreeHrtfList(vector_EnumeratedHrtf *list);
|
2017-04-05 19:27:30 +00:00
|
|
|
struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
|
2017-04-06 20:00:29 +00:00
|
|
|
void Hrtf_IncRef(struct Hrtf *hrtf);
|
|
|
|
void Hrtf_DecRef(struct Hrtf *hrtf);
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2017-03-12 02:04:06 +00:00
|
|
|
void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
|
2014-02-24 05:11:01 +00:00
|
|
|
|
2017-01-19 03:16:24 +00:00
|
|
|
/**
|
|
|
|
* Produces HRTF filter coefficients for decoding B-Format, given a set of
|
|
|
|
* virtual speaker positions and HF/LF matrices for decoding to them. The
|
|
|
|
* returned coefficients are ordered and scaled according to the matrices.
|
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-12 06:20:35 +00:00
|
|
|
*/
|
2017-07-31 08:20:42 +00:00
|
|
|
void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const ALfloat (*restrict AmbiPoints)[2], const ALfloat (*restrict AmbiMatrix)[2][MAX_AMBI_COEFFS], ALsizei AmbiCount);
|
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-12 06:20:35 +00:00
|
|
|
|
2014-02-24 05:11:01 +00:00
|
|
|
#endif /* ALC_HRTF_H */
|