openal-soft/alc/hrtf.h

116 lines
2.6 KiB
C
Raw Normal View History

#ifndef ALC_HRTF_H
#define ALC_HRTF_H
#include <array>
#include <cstddef>
#include <memory>
2018-12-25 11:09:41 -08:00
#include <string>
#include "AL/al.h"
2018-11-22 07:54:29 -08:00
#include "almalloc.h"
2019-09-25 02:11:37 -07:00
#include "alspan.h"
#include "ambidefs.h"
#include "atomic.h"
#include "vector.h"
struct HrtfHandle;
2019-07-28 21:29:59 -07:00
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 HrtfEntry {
2019-09-14 18:27:57 -07:00
RefCount mRef;
ALuint sampleRate;
2019-09-13 09:38:35 -07:00
ALuint irSize;
2019-01-28 20:31:58 -08:00
struct Field {
ALfloat distance;
ALubyte evCount;
2019-01-28 20:31:58 -08:00
};
/* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
* field[fdCount-1] is the nearest.
*/
2019-09-13 09:38:35 -07:00
ALuint fdCount;
const Field *field;
struct Elevation {
ALushort azCount;
ALushort irOffset;
};
Elevation *elev;
const ALfloat (*coeffs)[2];
const ALubyte (*delays)[2];
void IncRef();
void DecRef();
DEF_PLACE_NEWDEL()
};
2018-12-25 11:09:41 -08:00
struct EnumeratedHrtf {
std::string name;
HrtfHandle *hrtf;
};
using float2 = std::array<float,2>;
2019-07-31 10:46:33 -07:00
using HrirArray = std::array<float2,HRIR_LENGTH>;
2018-11-22 06:59:32 -08:00
struct HrtfState {
alignas(16) std::array<ALfloat,HRTF_HISTORY_LENGTH> History;
2018-11-22 06:59:32 -08:00
};
2018-01-11 03:53:25 -08:00
2019-06-18 06:20:35 -07:00
struct HrtfFilter {
2019-07-31 10:46:33 -07:00
alignas(16) HrirArray Coeffs;
2018-01-11 03:53:25 -08:00
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 */
2019-09-13 09:38:35 -07:00
ALuint IrSize{0};
al::FlexArray<HrirArray,16> Coeffs;
2018-11-22 07:54:29 -08:00
DirectHrtfState(size_t numchans) : Coeffs{numchans} { }
static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
2019-09-11 03:59:53 -07:00
DEF_FAM_NEWDEL(DirectHrtfState, Coeffs)
2018-11-22 06:59:32 -08:00
};
2018-01-11 03:53:25 -08:00
struct ElevRadius { float value; };
struct AzimRadius { float value; };
struct AngularPoint {
ElevRadius Elev;
AzimRadius 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);
2015-10-06 00:23:11 -07:00
void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance,
2019-07-31 10:46:33 -07:00
ALfloat spread, HrirArray &coeffs, ALsizei (&delays)[2]);
/**
* 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.
*/
2019-09-25 02:11:37 -07:00
void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state,
const al::span<const AngularPoint> AmbiPoints, const ALfloat (*AmbiMatrix)[MAX_AMBI_CHANNELS],
const ALfloat *AmbiOrderHFGain);
#endif /* ALC_HRTF_H */