diff options
author | Chris Robinson <[email protected]> | 2023-02-11 00:24:37 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-02-11 00:24:37 -0800 |
commit | 74d7d60a6c78893d0e05e40b6a55f7d8642bac19 (patch) | |
tree | 02a1a4afd1864085b90a252390bdcf92a1556604 | |
parent | ca419e2966f43ccec5a023afc206972ddbf0a137 (diff) |
Don't require samplesToDo > forwardSamples for decoders
-rw-r--r-- | core/uhjfilter.cpp | 20 | ||||
-rw-r--r-- | core/uhjfilter.h | 6 |
2 files changed, 13 insertions, 13 deletions
diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index ac5f2d40..da253300 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -336,7 +336,7 @@ void UhjDecoderIIR::decode(const al::span<float*> samples, const size_t samplesT mFilter2DT.process(Filter2Coeff, {mTemp.data(), samplesToDo}, forwardSamples, xoutput); /* Apply filter1 to S and store in mTemp. */ - mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo-1}, forwardSamples, mTemp.data()+1); + mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, forwardSamples, mTemp.data()+1); mTemp[0] = mDelayS; mDelayS = mTemp[forwardSamples]; /* W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) */ @@ -347,18 +347,18 @@ void UhjDecoderIIR::decode(const al::span<float*> samples, const size_t samplesT xoutput[i] = 0.418496f*mTemp[i] - xoutput[i]; - /* Apply filter1 to (0.795968*D - 0.676392*T) and store in youtput. */ - std::transform(mD.cbegin(), mD.cbegin()+samplesToDo, youtput, mTemp.begin(), + /* Apply filter1 to (0.795968*D - 0.676392*T) and store in mTemp. */ + std::transform(mD.cbegin(), mD.cbegin()+samplesToDo, youtput, youtput, [](const float d, const float t) noexcept { return 0.795968f*d - 0.676392f*t; }); - mFilter1DT.process(Filter1Coeff, {mTemp.data(), samplesToDo-1}, forwardSamples, youtput+1); - youtput[0] = mDelayDT; mDelayDT = youtput[forwardSamples]; + mFilter1DT.process(Filter1Coeff, {youtput, samplesToDo}, forwardSamples, mTemp.data()+1); + mTemp[0] = mDelayDT; mDelayDT = mTemp[forwardSamples]; - /* Precompute j*S and store in mTemp. */ - mFilter2S.process(Filter2Coeff, {mS.data(), samplesToDo}, forwardSamples, mTemp.data()); + /* Precompute j*S and store in youtput. */ + mFilter2S.process(Filter2Coeff, {mS.data(), samplesToDo}, forwardSamples, youtput); /* Y = 0.795968*D - 0.676392*T + j(0.186633*S) */ for(size_t i{0};i < samplesToDo;++i) - youtput[i] = youtput[i] + 0.186633f*mTemp[i]; + youtput[i] = mTemp[i] + 0.186633f*youtput[i]; if(samples.size() > 3) @@ -506,7 +506,7 @@ void UhjStereoDecoderIIR::decode(const al::span<float*> samples, const size_t sa float *RESTRICT youtput{al::assume_aligned<16>(samples[2])}; /* Apply filter1 to S and store in mTemp. */ - mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo-1}, forwardSamples, mTemp.data()+1); + mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, forwardSamples, mTemp.data()+1); mTemp[0] = mDelayS; mDelayS = mTemp[forwardSamples]; /* Precompute j*D and store in xoutput. */ @@ -523,7 +523,7 @@ void UhjStereoDecoderIIR::decode(const al::span<float*> samples, const size_t sa mFilter2S.process(Filter2Coeff, {mS.data(), samplesToDo}, forwardSamples, youtput); /* Apply filter1 to D and store in mTemp. */ - mFilter1D.process(Filter1Coeff, {mD.data(), samplesToDo-1}, forwardSamples, mTemp.data()+1); + mFilter1D.process(Filter1Coeff, {mD.data(), samplesToDo}, forwardSamples, mTemp.data()+1); mTemp[0] = mDelayD; mDelayD = mTemp[forwardSamples]; /* Y = 1.6822415*w*D - 0.2156194*j*S */ diff --git a/core/uhjfilter.h b/core/uhjfilter.h index 0cdd0f90..ebab14e5 100644 --- a/core/uhjfilter.h +++ b/core/uhjfilter.h @@ -164,13 +164,13 @@ struct UhjDecoderIIR final : public DecoderBase { /* FIXME: These IIR decoder filters actually have a 1-sample delay on the * non-filtered components, which is not reflected in the source latency * value. sInputPadding is 0, however, because it doesn't need any extra - * input samples as long as 'forwardSamples' is less than 'samplesToDo'. + * input samples. */ static constexpr size_t sInputPadding{0}; alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mS{}; alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mD{}; - alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mTemp{}; + alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge+1> mTemp{}; float mDelayS{}, mDelayDT{}, mDelayQ{}; UhjAllPassFilter mFilter1S; @@ -218,7 +218,7 @@ struct UhjStereoDecoderIIR final : public DecoderBase { alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mS{}; alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mD{}; - alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge> mTemp{}; + alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge+1> mTemp{}; float mDelayS{}, mDelayD{}; UhjAllPassFilter mFilter1S; |