diff --git a/libraries/audio/src/AudioHRTF.cpp b/libraries/audio/src/AudioHRTF.cpp index 84e3622498..2a191b5821 100644 --- a/libraries/audio/src/AudioHRTF.cpp +++ b/libraries/audio/src/AudioHRTF.cpp @@ -392,8 +392,8 @@ static void crossfade_4x2(float* src, float* dst, const float* win, int numFrame // linear interpolation with gain static void interpolate(float* dst, const float* src0, const float* src1, float frac, float gain) { - __m128 f0 = _mm_set1_ps(HRTF_GAIN * gain * (1.0f - frac)); - __m128 f1 = _mm_set1_ps(HRTF_GAIN * gain * frac); + __m128 f0 = _mm_set1_ps(gain * (1.0f - frac)); + __m128 f1 = _mm_set1_ps(gain * frac); assert(HRTF_TAPS % 4 == 0); @@ -861,6 +861,9 @@ void AudioHRTF::render(int16_t* input, float* output, int index, float azimuth, ALIGN32 float bqBuffer[4 * HRTF_BLOCK]; // 4-channel (interleaved) int delay[4]; // 4-channel (interleaved) + // apply global and local gain adjustment + gain *= _gainAdjust; + // to avoid polluting the cache, old filters are recomputed instead of stored setFilters(firCoef, bqCoef, delay, index, _azimuthState, _distanceState, _gainState, L0); diff --git a/libraries/audio/src/AudioHRTF.h b/libraries/audio/src/AudioHRTF.h index 08ae82b854..c9d053bec4 100644 --- a/libraries/audio/src/AudioHRTF.h +++ b/libraries/audio/src/AudioHRTF.h @@ -44,6 +44,11 @@ public: // void renderSilent(int16_t* input, float* output, int index, float azimuth, float distance, float gain, int numFrames); + // + // HRTF local gain adjustment + // + void setGainAdjustment(float gain) { _gainAdjust = HRTF_GAIN * gain; }; + private: AudioHRTF(const AudioHRTF&) = delete; AudioHRTF& operator=(const AudioHRTF&) = delete; @@ -73,6 +78,9 @@ private: float _distanceState = 0.0f; float _gainState = 0.0f; + // global and local gain adjustment + float _gainAdjust = HRTF_GAIN; + bool _silentState = false; };