aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-11-25 19:53:52 -0800
committerChris Robinson <[email protected]>2021-11-25 19:53:52 -0800
commitd5707b318495829e489196f8c3f02e7cd8085e2e (patch)
treea29c2f62da4d2f58d52f5969bd5ecf117e4f1780 /core
parent08a4e8a6b2d3e48647f53a6c1957b94dd1a667bb (diff)
Use a base for the UhjEncoder/Decoder common properties
Diffstat (limited to 'core')
-rw-r--r--core/uhjfilter.cpp16
-rw-r--r--core/uhjfilter.h18
2 files changed, 16 insertions, 18 deletions
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<double>;
-const PhaseShifterT<UhjEncoder::sFilterDelay*2> PShift{};
+const PhaseShifterT<UhjFilterBase::sFilterDelay*2> PShift{};
} // namespace
@@ -33,11 +31,11 @@ const PhaseShifterT<UhjEncoder::sFilterDelay*2> 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<BufferLine> 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<float,BufferLineSize+sFilterDelay> mS{};
alignas(16) std::array<float,BufferLineSize+sFilterDelay> 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<float,sLineSize>;
alignas(16) std::array<float,BufferLineSize+MaxResamplerEdge+sFilterDelay> 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<BufferLine> samples, const size_t offset, const size_t samplesToDo,
const size_t forwardSamples);