Log the buffer format when queueing mismatched buffers
[openal-soft.git] / core / hrtf.h
blobeb18682a52226d1aa93551f0ad7e64477539a950
1 #ifndef CORE_HRTF_H
2 #define CORE_HRTF_H
4 #include <array>
5 #include <cstddef>
6 #include <memory>
7 #include <string>
9 #include "almalloc.h"
10 #include "aloptional.h"
11 #include "alspan.h"
12 #include "atomic.h"
13 #include "ambidefs.h"
14 #include "bufferline.h"
15 #include "mixer/hrtfdefs.h"
16 #include "intrusive_ptr.h"
17 #include "vector.h"
20 struct HrtfStore {
21 RefCount mRef;
23 uint mSampleRate : 24;
24 uint mIrSize : 8;
26 struct Field {
27 float distance;
28 ubyte evCount;
30 /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
31 * field[fdCount-1] is the nearest.
33 al::span<const Field> mFields;
35 struct Elevation {
36 ushort azCount;
37 ushort irOffset;
39 Elevation *mElev;
40 const HrirArray *mCoeffs;
41 const ubyte2 *mDelays;
43 void getCoeffs(float elevation, float azimuth, float distance, float spread, HrirArray &coeffs,
44 const al::span<uint,2> delays);
46 void add_ref();
47 void dec_ref();
49 DEF_PLACE_NEWDEL()
51 using HrtfStorePtr = al::intrusive_ptr<HrtfStore>;
54 struct EvRadians { float value; };
55 struct AzRadians { float value; };
56 struct AngularPoint {
57 EvRadians Elev;
58 AzRadians Azim;
62 struct DirectHrtfState {
63 std::array<float,BufferLineSize> mTemp;
65 /* HRTF filter state for dry buffer content */
66 uint mIrSize{0};
67 al::FlexArray<HrtfChannelState> mChannels;
69 DirectHrtfState(size_t numchans) : mChannels{numchans} { }
70 /**
71 * Produces HRTF filter coefficients for decoding B-Format, given a set of
72 * virtual speaker positions, a matching decoding matrix, and per-order
73 * high-frequency gains for the decoder. The calculated impulse responses
74 * are ordered and scaled according to the matrix input.
76 void build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin,
77 const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
78 const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain);
80 static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
82 DEF_FAM_NEWDEL(DirectHrtfState, mChannels)
86 al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt);
87 HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate);
89 #endif /* CORE_HRTF_H */