From d5707b318495829e489196f8c3f02e7cd8085e2e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 25 Nov 2021 19:53:52 -0800 Subject: Use a base for the UhjEncoder/Decoder common properties --- core/uhjfilter.cpp | 16 ++++++---------- core/uhjfilter.h | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) (limited to 'core') diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index f4ef61f8..0e583965 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -14,11 +14,9 @@ namespace { -static_assert(UhjEncoder::sFilterDelay==UhjDecoder::sFilterDelay, "UHJ filter delays mismatch"); - using complex_d = std::complex; -const PhaseShifterT PShift{}; +const PhaseShifterT PShift{}; } // namespace @@ -33,11 +31,11 @@ const PhaseShifterT PShift{}; * T = j(-0.1432*W + 0.6511746*X) - 0.7071068*Y * Q = 0.9772*Z * - * where j is a wide-band +90 degree phase shift. T is excluded from 2-channel - * output, and Q is excluded from 2- and 3-channel output. + * where j is a wide-band +90 degree phase shift. 3-channel UHJ excludes Q, + * while 2-channel excludes Q and T. * - * The phase shift is done using a FIR filter derived from an FFT'd impulse - * with the desired shift. + * The phase shift is done using a linear FIR filter derived from an FFT'd + * impulse with the desired shift. */ void UhjEncoder::encode(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, @@ -103,9 +101,7 @@ void UhjEncoder::encode(const FloatBufferSpan LeftOut, const FloatBufferSpan Rig * Z = 1.023332*Q * * where j is a +90 degree phase shift. 3-channel UHJ excludes Q, while 2- - * channel excludes Q and T. The B-Format signal reconstructed from 2-channel - * UHJ should not be run through a normal B-Format decoder, as it needs - * different shelf filters. + * channel excludes Q and T. */ void UhjDecoder::decode(const al::span samples, const size_t offset, const size_t samplesToDo, const size_t forwardSamples) diff --git a/core/uhjfilter.h b/core/uhjfilter.h index e535cfb7..0f4668cd 100644 --- a/core/uhjfilter.h +++ b/core/uhjfilter.h @@ -8,12 +8,14 @@ #include "resampler_limits.h" -struct UhjEncoder { +struct UhjFilterBase { /* The filter delay is half it's effective size, so a delay of 128 has a * FIR length of 256. */ - constexpr static size_t sFilterDelay{128}; + static constexpr size_t sFilterDelay{128}; +}; +struct UhjEncoder : public UhjFilterBase { /* Delays and processing storage for the unfiltered signal. */ alignas(16) std::array mS{}; alignas(16) std::array mD{}; @@ -35,10 +37,8 @@ struct UhjEncoder { }; -struct UhjDecoder { - constexpr static size_t sFilterDelay{128}; - - constexpr static size_t sLineSize{BufferLineSize+MaxResamplerPadding+sFilterDelay}; +struct UhjDecoder : public UhjFilterBase { + static constexpr size_t sLineSize{BufferLineSize+MaxResamplerPadding+sFilterDelay}; using BufferLine = std::array; alignas(16) std::array mS{}; @@ -53,8 +53,10 @@ struct UhjDecoder { /** * Decodes a 3- or 4-channel UHJ signal into a B-Format signal with FuMa * channel ordering and UHJ scaling. For 3-channel, the 3rd channel may be - * attenuated by 'n', where 0 <= n <= 1. So 2-channel UHJ can be decoded by - * leaving the 3rd channel input silent (n=0). + * attenuated by 'n', where 0 <= n <= 1. So to decode 2-channel UHJ, supply + * 3 channels with the 3rd channel silent (n=0). The B-Format signal + * reconstructed from 2-channel UHJ should not be run through a normal + * B-Format decoder, as it needs different shelf filters. */ void decode(const al::span samples, const size_t offset, const size_t samplesToDo, const size_t forwardSamples); -- cgit v1.2.3