openal-soft/Alc/hrtf.h

102 lines
2.7 KiB
C
Raw Normal View History

#ifndef ALC_HRTF_H
#define ALC_HRTF_H
#include <memory>
2018-12-25 11:09:41 -08:00
#include <string>
#include "AL/al.h"
#include "AL/alc.h"
#include "vector.h"
2018-11-22 07:54:29 -08:00
#include "almalloc.h"
2018-01-11 03:53:25 -08:00
#define HRTF_HISTORY_BITS (6)
#define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
#define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
#define HRIR_BITS (7)
#define HRIR_LENGTH (1<<HRIR_BITS)
#define HRIR_MASK (HRIR_LENGTH-1)
2018-12-22 09:20:50 -08:00
struct HrtfHandle;
2018-12-22 09:20:50 -08:00
struct HrtfEntry {
RefCount ref;
ALuint sampleRate;
ALsizei irSize;
ALfloat distance;
ALubyte evCount;
const ALubyte *azCount;
const ALushort *evOffset;
const ALfloat (*coeffs)[2];
const ALubyte (*delays)[2];
};
2018-12-25 11:09:41 -08:00
struct EnumeratedHrtf {
std::string name;
HrtfHandle *hrtf;
};
2018-11-22 06:59:32 -08:00
struct HrtfState {
2018-01-11 03:53:25 -08:00
alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
alignas(16) ALfloat Values[HRIR_LENGTH][2];
2018-11-22 06:59:32 -08:00
};
2018-01-11 03:53:25 -08:00
2018-11-22 06:59:32 -08:00
struct HrtfParams {
2018-01-11 03:53:25 -08:00
alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
ALsizei Delay[2];
ALfloat Gain;
2018-11-22 06:59:32 -08:00
};
2018-01-11 03:53:25 -08:00
2018-11-22 06:59:32 -08:00
struct DirectHrtfState {
2018-01-11 03:53:25 -08:00
/* HRTF filter state for dry buffer content */
ALsizei Offset{0};
ALsizei IrSize{0};
struct ChanData {
2018-01-11 03:53:25 -08:00
alignas(16) ALfloat Values[HRIR_LENGTH][2];
alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
};
al::FlexArray<ChanData> Chan;
2018-11-22 07:54:29 -08:00
DirectHrtfState(size_t numchans) : Chan{numchans} { }
DirectHrtfState(const DirectHrtfState&) = delete;
DirectHrtfState& operator=(const DirectHrtfState&) = delete;
static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
static constexpr size_t Sizeof(size_t numchans) noexcept
{ return al::FlexArray<ChanData>::Sizeof(numchans, offsetof(DirectHrtfState, Chan)); }
2018-11-22 07:54:29 -08:00
DEF_PLACE_NEWDEL()
2018-11-22 06:59:32 -08:00
};
2018-01-11 03:53:25 -08:00
struct AngularPoint {
ALfloat Elev;
ALfloat Azim;
};
2018-01-11 03:53:25 -08:00
al::vector<EnumeratedHrtf> EnumerateHrtf(const char *devname);
2018-12-22 09:20:50 -08:00
HrtfEntry *GetLoadedHrtf(HrtfHandle *handle);
void Hrtf_IncRef(HrtfEntry *hrtf);
void Hrtf_DecRef(HrtfEntry *hrtf);
2015-10-06 00:23:11 -07:00
2018-12-22 09:20:50 -08:00
void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays);
/**
* Produces HRTF filter coefficients for decoding B-Format, given a set of
2018-05-15 22:11:10 -07:00
* virtual speaker positions, a matching decoding matrix, and per-order high-
* frequency gains for the decoder. The calculated impulse responses are
* ordered and scaled according to the matrix input. Note the specified virtual
* positions should be in degrees, not radians!
*/
2018-12-22 09:20:50 -08:00
void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALsizei NumChannels, const AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], const ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain);
#endif /* ALC_HRTF_H */