diff options
author | Chris Robinson <[email protected]> | 2018-05-14 23:41:29 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-05-14 23:41:29 -0700 |
commit | 4ee04cd444e770fb12adf607c9711f7d892f76bd (patch) | |
tree | 6892db1546a2da8617e6ed7948c65f0ecbc6dca0 /Alc/mixer/hrtf_inc.c | |
parent | 43dccc880703d6e07e86a32e38c5c4cac235016f (diff) |
Use a step counter for gain stepping
This should provide more stable stepping, preventing floating-point errors from
accumulating on each step/sample.
Diffstat (limited to 'Alc/mixer/hrtf_inc.c')
-rw-r--r-- | Alc/mixer/hrtf_inc.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/Alc/mixer/hrtf_inc.c b/Alc/mixer/hrtf_inc.c index d6bd8042..3ef22f24 100644 --- a/Alc/mixer/hrtf_inc.c +++ b/Alc/mixer/hrtf_inc.c @@ -22,8 +22,9 @@ void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, { const ALfloat (*Coeffs)[2] = ASSUME_ALIGNED(hrtfparams->Coeffs, 16); const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] }; - ALfloat gainstep = hrtfparams->GainStep; - ALfloat gain = hrtfparams->Gain; + const ALfloat gainstep = hrtfparams->GainStep; + const ALfloat gain = hrtfparams->Gain; + ALfloat g, stepcount = 0.0f; ALfloat left, right; ALsizei i; @@ -35,8 +36,10 @@ void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, for(i = 0;i < BufferSize;i++) { hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++); - left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*gain; - right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*gain; + + g = gain + gainstep*stepcount; + left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*g; + right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*g; hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f; hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f; @@ -45,10 +48,10 @@ void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0]; *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1]; - gain += gainstep; + stepcount += 1.0f; Offset++; } - hrtfparams->Gain = gain; + hrtfparams->Gain = gain + gainstep*stepcount; } void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, @@ -59,12 +62,13 @@ void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, { const ALfloat (*OldCoeffs)[2] = ASSUME_ALIGNED(oldparams->Coeffs, 16); const ALsizei OldDelay[2] = { oldparams->Delay[0], oldparams->Delay[1] }; - ALfloat oldGain = oldparams->Gain; - ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize; + const ALfloat oldGain = oldparams->Gain; + const ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize; const ALfloat (*NewCoeffs)[2] = ASSUME_ALIGNED(newparams->Coeffs, 16); const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] }; - ALfloat newGain = newparams->Gain; - ALfloat newGainStep = newparams->GainStep; + const ALfloat newGain = newparams->Gain; + const ALfloat newGainStep = newparams->GainStep; + ALfloat g, stepcount = 0.0f; ALfloat left, right; ALsizei i; @@ -80,22 +84,23 @@ void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++); - left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*oldGain; - right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*oldGain; + g = oldGain + oldGainStep*stepcount; + left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*g; + right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*g; ApplyCoeffs(Offset, hrtfstate->Values, IrSize, OldCoeffs, left, right); - left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*newGain; - right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*newGain; + g = newGain + newGainStep*stepcount; + left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*g; + right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*g; ApplyCoeffs(Offset, hrtfstate->Values, IrSize, NewCoeffs, left, right); *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0]; *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1]; - oldGain += oldGainStep; - newGain += newGainStep; + stepcount += 1.0f; Offset++; } - newparams->Gain = newGain; + newparams->Gain = newGain + newGainStep*stepcount; } void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, |