diff options
author | Chris Robinson <[email protected]> | 2022-03-31 13:07:58 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-03-31 13:07:58 -0700 |
commit | 6f9311b1ba26211895b507670b421356cc305bee (patch) | |
tree | 4967d53a2aa182b1f2178210d56ad01dfff6628e /core/bformatdec.cpp | |
parent | 7c60d0f16362415a1bf77f2e814c488f64088d26 (diff) |
Don't manually reverse samples
Diffstat (limited to 'core/bformatdec.cpp')
-rw-r--r-- | core/bformatdec.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/core/bformatdec.cpp b/core/bformatdec.cpp index 1ad46f95..606093c0 100644 --- a/core/bformatdec.cpp +++ b/core/bformatdec.cpp @@ -133,31 +133,25 @@ void BFormatDec::processStablize(const al::span<FloatBufferLine> OutBuffer, for(size_t i{0};i < SamplesToDo;++i) side[FrontStablizer::DelayLength+i] += OutBuffer[lidx][i] - OutBuffer[ridx][i]; - /* Combine the delayed mid signal with the decoded mid signal. Note that - * the samples are stored and combined in reverse, so the newest samples - * are at the front and the oldest at the back. - */ - al::span<float> tmpbuf{mStablizer->TempBuf.data(), SamplesToDo+FrontStablizer::DelayLength}; - auto tmpiter = tmpbuf.begin() + SamplesToDo; - std::copy(mStablizer->MidDelay.cbegin(), mStablizer->MidDelay.cend(), tmpiter); - for(size_t i{0};i < SamplesToDo;++i) - *--tmpiter = OutBuffer[lidx][i] + OutBuffer[ridx][i]; + /* Combine the delayed mid signal with the decoded mid signal. */ + float *tmpbuf{mStablizer->TempBuf.data()}; + auto tmpiter = std::copy(mStablizer->MidDelay.cbegin(), mStablizer->MidDelay.cend(), tmpbuf); + for(size_t i{0};i < SamplesToDo;++i,++tmpiter) + *tmpiter = OutBuffer[lidx][i] + OutBuffer[ridx][i]; /* Save the newest samples for next time. */ - std::copy_n(tmpbuf.cbegin(), mStablizer->MidDelay.size(), mStablizer->MidDelay.begin()); + std::copy_n(tmpbuf+SamplesToDo, mStablizer->MidDelay.size(), mStablizer->MidDelay.begin()); - /* Apply an all-pass on the reversed signal, then reverse the samples to - * get the forward signal with a reversed phase shift. The future samples - * are included with the all-pass to reduce the error in the output - * samples (the smaller the delay, the more error is introduced). + /* Apply an all-pass on the signal in reverse. The future samples are + * included with the all-pass to reduce the error in the output samples + * (the smaller the delay, the more error is introduced). */ - mStablizer->MidFilter.applyAllpass(tmpbuf); - tmpbuf = tmpbuf.subspan<FrontStablizer::DelayLength>(); - std::reverse(tmpbuf.begin(), tmpbuf.end()); + mStablizer->MidFilter.applyAllpassRev({tmpbuf, SamplesToDo+FrontStablizer::DelayLength}); /* Now apply the band-splitter, combining its phase shift with the reversed * phase shift, restoring the original phase on the split signal. */ - mStablizer->MidFilter.process(tmpbuf, mStablizer->MidHF.data(), mStablizer->MidLF.data()); + mStablizer->MidFilter.process({tmpbuf, SamplesToDo}, mStablizer->MidHF.data(), + mStablizer->MidLF.data()); /* This pans the separate low- and high-frequency signals between being on * the center channel and the left+right channels. The low-frequency signal |