diff options
author | Chris Robinson <[email protected]> | 2019-03-28 09:29:20 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-28 09:34:31 -0700 |
commit | dfb81ff42de27b474d27e5d9e30c8fbe538db5ca (patch) | |
tree | 8bc8f3b53eaa6e2fc52b5d5c5d75f9dfeb69a888 /Alc/mixvoice.cpp | |
parent | e7bfe1ebd00fe01514f590f4b143c676034fcf6e (diff) |
Avoid using the HRTF history buffer as a ring buffer
The HRTF mixers now get a full input buffer with the history prepended, so the
delay offsets just need to account for the start point and read forward for
each sample.
Diffstat (limited to 'Alc/mixvoice.cpp')
-rw-r--r-- | Alc/mixvoice.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index fcd08d0b..558586d3 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -624,10 +624,23 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc if((voice->mFlags&VOICE_HAS_HRTF)) { + auto &HrtfSamples = Device->HrtfSourceData; const ALfloat TargetGain{UNLIKELY(vstate == ALvoice::Stopping) ? 0.0f : parms.Hrtf.Target.Gain}; ALsizei fademix{0}; + /* Copy the HRTF history and new input samples into a temp + * buffer. + */ + auto src_iter = std::copy(parms.Hrtf.State.History.begin(), + parms.Hrtf.State.History.end(), std::begin(HrtfSamples)); + std::copy_n(samples, DstBufferSize, src_iter); + /* Copy the last used samples back into the history buffer + * for later. + */ + std::copy_n(std::begin(HrtfSamples) + DstBufferSize, + parms.Hrtf.State.History.size(), parms.Hrtf.State.History.begin()); + /* If fading, the old gain is not silence, and this is the * first mixing pass, fade between the IRs. */ @@ -657,7 +670,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc MixHrtfBlendSamples( voice->mDirect.Buffer[OutLIdx], voice->mDirect.Buffer[OutRIdx], - samples, voice->mOffset, OutPos, IrSize, &parms.Hrtf.Old, + HrtfSamples, voice->mOffset, OutPos, IrSize, &parms.Hrtf.Old, &hrtfparams, &parms.Hrtf.State, fademix); /* Update the old parameters with the result. */ parms.Hrtf.Old = parms.Hrtf.Target; @@ -691,7 +704,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc static_cast<ALfloat>(todo); MixHrtfSamples( voice->mDirect.Buffer[OutLIdx], voice->mDirect.Buffer[OutRIdx], - samples+fademix, voice->mOffset+fademix, OutPos+fademix, IrSize, + HrtfSamples+fademix, voice->mOffset+fademix, OutPos+fademix, IrSize, &hrtfparams, &parms.Hrtf.State, todo); /* Store the interpolated gain or the final target gain * depending if the fade is done. |