Add a local HRTF gain adjustment. Gain adjustments are persistent and properly interpolated.

This commit is contained in:
Ken Cooke 2017-01-11 10:05:39 -08:00
parent 8b45afecde
commit 083c7bc523
2 changed files with 13 additions and 2 deletions

View file

@ -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);

View file

@ -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;
};