12 #ifndef hifi_AudioHRTF_h
13 #define hifi_AudioHRTF_h
19 #include "AudioHelpers.h"
21 static const int HRTF_AZIMUTHS = 72;
22 static const int HRTF_TAPS = 64;
23 static const int HRTF_TABLES = 25;
25 static const int HRTF_DELAY = 24;
26 static const int HRTF_BLOCK = 240;
28 static const float HRTF_GAIN = 1.0f;
31 static const float HRTF_AZIMUTH_REF = 2.0f;
32 static const float HRTF_NEARFIELD_MAX = 1.0f;
33 static const float HRTF_NEARFIELD_MIN = 0.125f;
34 static const float HRTF_HEAD_RADIUS = 0.0875f;
37 static const float ATTN_DISTANCE_REF = 2.0f;
38 static const float ATTN_GAIN_MAX = 16.0f;
41 static const float LPF_DISTANCE_REF = 256.0f;
58 void render(int16_t* input,
float* output,
int index,
float azimuth,
float distance,
float gain,
int numFrames,
59 float lpfDistance = LPF_DISTANCE_REF);
64 void mixMono(int16_t* input,
float* output,
float gain,
int numFrames);
65 void mixStereo(int16_t* input,
float* output,
float gain,
int numFrames);
70 void setParameterHistory(
float azimuth,
float distance,
float gain,
float lpfDistance = LPF_DISTANCE_REF) {
72 _azimuthState = azimuth;
73 _distanceState = distance;
76 _lpfState = 0.5f * fastLog2f(std::max(distance, 1.0f)) / fastLog2f(std::max(lpfDistance, 2.0f));
77 _lpfState = std::min(std::max(_lpfState, 0.0f), 1.0f);
83 void setGainAdjustment(
float gain) { _gainAdjust = HRTF_GAIN * gain; };
84 float getGainAdjustment() {
return _gainAdjust; }
90 memset(_firState, 0,
sizeof(_firState));
93 memset(_delayState, 0,
sizeof(_delayState));
96 memset(_bqState, 0,
sizeof(_bqState));
100 _distanceState = 0.0f;
111 AudioHRTF(
const AudioHRTF&) =
delete;
112 AudioHRTF& operator=(
const AudioHRTF&) =
delete;
126 float _firState[HRTF_TAPS] = {};
129 float _delayState[4][HRTF_DELAY] = {};
132 float _bqState[3][8] = {};
135 float _azimuthState = 0.0f;
136 float _distanceState = 0.0f;
137 float _gainState = 0.0f;
138 float _lpfState = 0.0f;
141 float _gainAdjust = HRTF_GAIN;
143 bool _resetState =
true;