From 188a06664223dbb82bb378c8b5ba512ca7e38a70 Mon Sep 17 00:00:00 2001 From: yuygfgg <140488233+yuygfgg@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:46:18 +0800 Subject: [PATCH] fix: use the correct filterbank for Rosella rendering Replace the shared SOFA filterbank in the personalized headphone path with a dedicated Rosella bank. The previous variant caused a frequency-dependent room-tail error despite correct room processing. - Use the matching QMF prototype and 11-tap hybrid filters - Apply the 3-slot high-band delay and 448-sample filterbank latency - Resize the rendered buffer correctly for short final blocks - Add reference-vector, chunking, reset, isolation, and latency tests - Document the filterbank differences and validation results --- CMakeLists.txt | 7 +- docs/binaural.en.md | 6 +- docs/rosella_filterbank.en.md | 76 +++++++ src/hrtf/public_filterbank.h | 4 - src/hrtf/rosella_filterbank.cpp | 173 +++++++++++++++ src/hrtf/rosella_filterbank.h | 38 ++++ src/hrtf/rosella_filterbank_tables.h | 317 +++++++++++++++++++++++++++ src/hrtf/rosella_renderer.cpp | 21 +- tests/rosella_filterbank_vectors.h | 149 +++++++++++++ tests/test_rosella_filterbank.cpp | 126 +++++++++++ 10 files changed, 899 insertions(+), 18 deletions(-) create mode 100644 docs/rosella_filterbank.en.md create mode 100644 src/hrtf/rosella_filterbank.cpp create mode 100644 src/hrtf/rosella_filterbank.h create mode 100644 src/hrtf/rosella_filterbank_tables.h create mode 100644 tests/rosella_filterbank_vectors.h create mode 100644 tests/test_rosella_filterbank.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fce7982..e11b93f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ set(JOC_INTERNAL_SOURCES src/foundation/status.cpp src/hrtf/jochrtf.cpp src/hrtf/public_filterbank.cpp + src/hrtf/rosella_filterbank.cpp src/hrtf/rosella_model.cpp src/hrtf/rosella_renderer.cpp src/hrtf/kernel_tables.cpp @@ -287,6 +288,10 @@ if(JOC_BUILD_TESTS) target_link_libraries(joc_tests PRIVATE joc_core_impl joc_core) target_include_directories(joc_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") add_test(NAME core COMMAND joc_tests) + add_executable(joc_rosella_filterbank_tests tests/test_rosella_filterbank.cpp) + target_link_libraries(joc_rosella_filterbank_tests PRIVATE joc_core_impl) + target_include_directories(joc_rosella_filterbank_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") + add_test(NAME rosella_filterbank COMMAND joc_rosella_filterbank_tests) # The public headers must stay valid C and C++: these targets exist to prove it. add_library(joc_headers_c OBJECT tests/test_headers.c) target_include_directories(joc_headers_c PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") @@ -323,7 +328,7 @@ if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS) list(APPEND JOC_MSVC_TARGETS joc_core_impl) endif() if(JOC_BUILD_TESTS) - list(APPEND JOC_MSVC_TARGETS joc_tests joc_headers_c joc_headers_cpp) + list(APPEND JOC_MSVC_TARGETS joc_tests joc_rosella_filterbank_tests joc_headers_c joc_headers_cpp) endif() if(JOC_BUILD_DEVTOOLS) list(APPEND JOC_MSVC_TARGETS joc_rosella_probe joc_dump joc_stream_probe joc_sofa_probe joc_sofa_field_probe joc_dictionary_probe) diff --git a/docs/binaural.en.md b/docs/binaural.en.md index 1d891cc..8bc8b98 100644 --- a/docs/binaural.en.md +++ b/docs/binaural.en.md @@ -112,7 +112,7 @@ No path may add a second ear delay or phase-group delay. ## Public filterbank and directional field -The runtime is fixed at: +The SOFA and `.jochrtf` runtime is fixed at: - 48 kHz; - a 64-sample QMF hop; @@ -121,6 +121,10 @@ The runtime is fixed at: - fifth order, 36 terms, ACN/N3D real spherical harmonics; - float64 PCM, delay, SH, and room state; complex128 band transfers and spectra. +The `.personalized_headphone` path uses a separate Rosella filterbank with +448 samples of latency. See [Rosella filterbank](rosella_filterbank.en.md) for +its parameters and validation results. The SOFA bank described here is unchanged. + Real and imaginary unit gains for every hybrid band pass through the same analysis/synthesis chain to form a 154-real-parameter impulse dictionary. The compiler does not sample 77 FFT bins. Defaults are `1e-3` projection ridge and diff --git a/docs/rosella_filterbank.en.md b/docs/rosella_filterbank.en.md new file mode 100644 index 0000000..f7ea4a4 --- /dev/null +++ b/docs/rosella_filterbank.en.md @@ -0,0 +1,76 @@ +# Rosella filterbank + +The Rosella renderer uses a separate 64-band QMF and 77-band hybrid filterbank. +The SOFA compiler and renderer continue to use `PublicFilterbank`. + +## Why the banks differ + +The reference headphone renderer selects its analysis and synthesis callbacks +during preparation, after initialization. Capturing only the initial callbacks +identified the wrong filterbank variant. + +Runtime buffer captures identified these parameters: + +| Parameter | Rosella bank | Public bank | +| --- | --- | --- | +| QMF prototype | 640 asymmetric coefficients | Separate prototype | +| Low-band hybrid filter | 11 taps | 13 taps | +| High-band hybrid delay | 3 slots | 6 slots | +| Analysis/synthesis latency | 448 samples | 961 samples | + +The wrong variant produced a frequency-dependent room-tail error. With the +captured room send as input, the existing room recursion already matched the +reference. The fix changes the filterbank, not the room coefficients, direct +HRTF calculation, phase mapping, or output EQ. + +## Implementation + +`RosellaFilterbank` keeps separate analysis, hybrid, and synthesis histories for +each channel. QMF data uses `[slot, channel, 64]` order. Hybrid data uses +`[slot, channel, 77]` order. The half-step methods preserve state between calls. + +`rosella_filterbank_tables.h` stores the captured float32 prototype, rotation, +and hybrid coefficients as hexadecimal literals. Processing uses double +precision. The tables do not contain the personalized HRTF or room tuning. + +The runtime removes 448 startup samples and uses the same latency when it +calculates flush capacity. Its rendered buffer is resized to the current block +length, including a short final block. + +## Validation + +Run the self-contained tests: + +```sh +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build --parallel +ctest --test-dir build --output-on-failure +``` + +`rosella_filterbank` checks deterministic analysis, hybrid, folding, and synthesis +vectors from an independent NumPy implementation. It also checks empty and +unequal chunks, reset, channel isolation, and impulse latency. The tests need no +reference binary, audio fixture, or personalized headphone file. + +Before integration with the upstream bed-layout changes, four captured-input +tests gave the following room PCM residuals. No gain fitting was used for this +table. Residual is `10 * log10(sum(abs(reference - candidate)^2) / +sum(abs(reference)^2))`. + +| Input | Room PCM residual | +| --- | ---: | +| Left-front click | -133.94 dB | +| Left-front log sweep | -135.40 dB | +| Left-front noise | -133.50 dB | +| Right-front signal | -133.34 dB | + +The old bank produced room residuals near -10 to -11 dB on these captures. +A 30-second music replay using the reference decoder's object PCM reached +correlation 0.9999999503 and a -70.02 dB residual after delay alignment and one +global gain fit. A full-file render through this project's decoder reached +correlation 0.99988816 after alignment and gain fitting. + +These are separate experiments, not bit-exactness claims. A fixed gain +difference of approximately 1.0004885 remains in the captured chain. The patch +does not compensate for that difference. Decoder differences and the remaining +music residual are outside this fix. diff --git a/src/hrtf/public_filterbank.h b/src/hrtf/public_filterbank.h index 4da85e9..da5fa9c 100644 --- a/src/hrtf/public_filterbank.h +++ b/src/hrtf/public_filterbank.h @@ -7,10 +7,6 @@ #include "hrtf/jochrtf.h" -// Public 64-QMF / 77-hybrid filterbank, shared by the SOFA field compiler and the -// Rosella renderer (upstream public_filterbank.py and rosella_filterbank.py are -// the same bank). Everything is float64/complex128, as the reference computes it, -// and the stateful half-steps are exposed because Rosella drives them directly. namespace joc::hrtf { inline constexpr int kQmfBands = 64; diff --git a/src/hrtf/rosella_filterbank.cpp b/src/hrtf/rosella_filterbank.cpp new file mode 100644 index 0000000..11d87cd --- /dev/null +++ b/src/hrtf/rosella_filterbank.cpp @@ -0,0 +1,173 @@ +#include "hrtf/rosella_filterbank.h" + +#include +#include + +#include "foundation/fft.h" +#include "hrtf/rosella_filterbank_tables.h" + +namespace joc::hrtf { +namespace { + +constexpr std::size_t kBands = 64; +constexpr std::size_t kQmfTaps = 10; +constexpr std::size_t kHybridTaps = 11; +constexpr std::size_t kHybridDelay = 3; +constexpr std::array kHybridOrder = {0, 7, 1, 6, 2, 9, 3, 4, + 10, 5, 11, 15, 8, 12, 13, 14}; + +const dsp::FftPlan& qmf_plan() { + static const dsp::FftPlan plan(kBands, false); + return plan; +} + +const dsp::FftPlan& hybrid_plan(std::size_t bands) { + static const dsp::FftPlan eight(8, false); + static const dsp::FftPlan four(4, false); + return bands == 8 ? eight : four; +} + +double tap_sign(std::size_t tap) { return (tap / 2) % 2 == 0 ? 1.0 : -1.0; } + +} + +RosellaFilterbank::RosellaFilterbank(std::size_t channels) + : channels_(channels), analysis_history_(kQmfTaps * channels * kBands), + hybrid_history_(kHybridTaps * channels * kBands), + synthesis_history_(kQmfTaps * channels * kBands), spectrum_(kBands), hybrid_eight_(8), + hybrid_four_(4) {} + +void RosellaFilterbank::reset() { + analysis_position_ = 0; + hybrid_position_ = 0; + synthesis_position_ = 0; + std::fill(analysis_history_.begin(), analysis_history_.end(), 0.0); + std::fill(hybrid_history_.begin(), hybrid_history_.end(), Complex{}); + std::fill(synthesis_history_.begin(), synthesis_history_.end(), Complex{}); +} + +void RosellaFilterbank::analyze_qmf(const std::vector& hops, std::size_t slots, + std::vector* qmf) { + const std::size_t stride = channels_ * kBands; + qmf->resize(slots * stride); + for (std::size_t slot = 0; slot < slots; ++slot) { + std::copy_n(hops.data() + slot * stride, stride, + analysis_history_.data() + analysis_position_ * stride); + for (std::size_t channel = 0; channel < channels_; ++channel) { + for (std::size_t band = 0; band < kBands; ++band) { + double even = 0.0; + double odd = 0.0; + for (std::size_t tap = 0; tap < kQmfTaps; ++tap) { + const std::size_t history_slot = (analysis_position_ + tap + 1) % kQmfTaps; + const double value = + analysis_history_[history_slot * stride + channel * kBands + band]; + const double contribution = + value * 0.5 * rosella_filterbank_tables::kPrototype[band * kQmfTaps + tap] * + tap_sign(tap); + (tap % 2 == 0 ? even : odd) += contribution; + } + spectrum_[band] = Complex(odd, even) * rosella_filterbank_tables::kRotation[band]; + } + dsp::fft_radix2(&spectrum_, qmf_plan()); + Complex* destination = qmf->data() + slot * stride + channel * kBands; + for (std::size_t band = 0; band < kBands / 2; ++band) { + destination[2 * band] = spectrum_[band] / 64.0; + destination[2 * band + 1] = std::conj(spectrum_[63 - band]) / 64.0; + } + } + analysis_position_ = (analysis_position_ + 1) % kQmfTaps; + } +} + +void RosellaFilterbank::analyze_hybrid(const std::vector& qmf, std::size_t slots, + std::vector* hybrid) { + const std::size_t stride = channels_ * kBands; + hybrid->resize(slots * channels_ * kHybridBandCount); + for (std::size_t slot = 0; slot < slots; ++slot) { + std::copy_n(qmf.data() + slot * stride, stride, + hybrid_history_.data() + hybrid_position_ * stride); + for (std::size_t channel = 0; channel < channels_; ++channel) { + std::array low{}; + for (std::size_t band = 0; band < 3; ++band) { + std::vector& spectrum = band == 0 ? hybrid_eight_ : hybrid_four_; + std::fill(spectrum.begin(), spectrum.end(), Complex{}); + for (std::size_t tap = 0; tap < kHybridTaps; ++tap) { + const std::size_t history_slot = (hybrid_position_ + tap + 1) % kHybridTaps; + const std::size_t bin = + (tap + kHybridDelay + 1 + 2 * spectrum.size() - kHybridTaps) % + spectrum.size(); + spectrum[bin] += + hybrid_history_[history_slot * stride + channel * kBands + band] * + rosella_filterbank_tables::kHybrid[(band == 0 ? 0 : kHybridTaps) + tap]; + } + dsp::fft_radix2(&spectrum, hybrid_plan(spectrum.size())); + std::copy(spectrum.begin(), spectrum.end(), + low.begin() + (band == 0 ? 0 : 4 + band * 4)); + } + Complex* destination = hybrid->data() + (slot * channels_ + channel) * kHybridBandCount; + for (std::size_t band = 0; band < low.size(); ++band) { + destination[band] = low[kHybridOrder[band]]; + } + destination[1] = std::conj(destination[1]); + destination[3] = std::conj(destination[3]); + const std::size_t delayed = + (hybrid_position_ + kHybridTaps - kHybridDelay) % kHybridTaps; + std::copy_n(hybrid_history_.data() + delayed * stride + channel * kBands + 3, + kBands - 3, destination + 16); + } + hybrid_position_ = (hybrid_position_ + 1) % kHybridTaps; + } +} + +void RosellaFilterbank::synthesize_hybrid(const std::vector& hybrid, std::size_t slots, + std::vector* qmf) { + qmf->resize(slots * channels_ * kBands); + for (std::size_t row = 0; row < slots * channels_; ++row) { + const Complex* source = hybrid.data() + row * kHybridBandCount; + Complex* destination = qmf->data() + row * kBands; + destination[0] = source[0] + source[2] + source[4] + source[6] + source[7] + source[9] + + std::conj(source[3]) + std::conj(source[1]); + destination[1] = source[12] + source[5] + source[8] + source[10]; + destination[2] = source[13] + source[14] + source[15] + source[11]; + std::copy_n(source + 16, kBands - 3, destination + 3); + } +} + +void RosellaFilterbank::synthesize_qmf(const std::vector& qmf, std::size_t slots, + std::vector* hops) { + const std::size_t stride = channels_ * kBands; + hops->resize(slots * stride); + for (std::size_t slot = 0; slot < slots; ++slot) { + for (std::size_t channel = 0; channel < channels_; ++channel) { + const Complex* source = qmf.data() + slot * stride + channel * kBands; + for (std::size_t band = 0; band < kBands / 2; ++band) { + spectrum_[band] = std::conj(source[2 * band]); + spectrum_[32 + band] = source[63 - 2 * band]; + } + dsp::fft_radix2(&spectrum_, qmf_plan()); + Complex* current = + synthesis_history_.data() + synthesis_position_ * stride + channel * kBands; + for (std::size_t band = 0; band < kBands; ++band) { + current[band] = spectrum_[band] * rosella_filterbank_tables::kRotation[band]; + } + for (std::size_t band = 0; band < kBands; ++band) { + double value = 0.0; + for (std::size_t lag = 0; lag < kQmfTaps; ++lag) { + const std::size_t history_slot = + (synthesis_position_ + kQmfTaps - lag) % kQmfTaps; + const Complex sample = + synthesis_history_[history_slot * stride + channel * kBands + band]; + const double component = lag % 2 == 0 ? sample.real() : sample.imag(); + value += + component * + rosella_filterbank_tables::kPrototype[(63 - band) * kQmfTaps + 9 - lag] * + tap_sign(lag) * 2.0; + } + (*hops)[slot * stride + channel * kBands + band] = value; + } + } + synthesis_position_ = (synthesis_position_ + 1) % kQmfTaps; + } +} + +} diff --git a/src/hrtf/rosella_filterbank.h b/src/hrtf/rosella_filterbank.h new file mode 100644 index 0000000..1ea783e --- /dev/null +++ b/src/hrtf/rosella_filterbank.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include "hrtf/public_filterbank.h" + +namespace joc::hrtf { + +class RosellaFilterbank { +public: + static constexpr int kLatencySamples = 448; + + explicit RosellaFilterbank(std::size_t channels); + + void reset(); + void analyze_qmf(const std::vector& hops, std::size_t slots, std::vector* qmf); + void analyze_hybrid(const std::vector& qmf, std::size_t slots, + std::vector* hybrid); + void synthesize_hybrid(const std::vector& hybrid, std::size_t slots, + std::vector* qmf); + void synthesize_qmf(const std::vector& qmf, std::size_t slots, + std::vector* hops); + +private: + std::size_t channels_; + std::size_t analysis_position_ = 0; + std::size_t hybrid_position_ = 0; + std::size_t synthesis_position_ = 0; + std::vector analysis_history_; + std::vector hybrid_history_; + std::vector synthesis_history_; + std::vector spectrum_; + std::vector hybrid_eight_; + std::vector hybrid_four_; +}; + +} diff --git a/src/hrtf/rosella_filterbank_tables.h b/src/hrtf/rosella_filterbank_tables.h new file mode 100644 index 0000000..231e403 --- /dev/null +++ b/src/hrtf/rosella_filterbank_tables.h @@ -0,0 +1,317 @@ +#pragma once + +#include +#include + +namespace joc::hrtf::rosella_filterbank_tables { + +inline constexpr std::array kPrototype = { + 0x1.89b0a40000000p-14f, -0x1.9405b80000000p-11f, 0x1.caf19e0000000p-11f, + 0x1.b88a900000000p-8f, 0x1.a3899a0000000p-8f, -0x1.fa22860000000p-4f, + 0x1.5a540e0000000p-4f, 0x1.c420360000000p-1f, 0x1.1fb7200000000p-1f, + -0x1.eb519a0000000p-12f, 0x1.fe69400000000p-14f, -0x1.aebea80000000p-11f, + 0x1.0b0c7c0000000p-10f, 0x1.baec6c0000000p-8f, 0x1.7fc1900000000p-8f, + -0x1.0209c80000000p-3f, 0x1.88474c0000000p-4f, 0x1.c7781c0000000p-1f, + 0x1.1929680000000p-1f, -0x1.6f0b9e0000000p-9f, 0x1.0c4e040000000p-13f, + -0x1.cabdf80000000p-11f, 0x1.3039ee0000000p-10f, 0x1.bd5e600000000p-8f, + 0x1.590ba60000000p-8f, -0x1.06dd700000000p-3f, 0x1.b728e40000000p-4f, + 0x1.ca9d100000000p-1f, 0x1.1298c60000000p-1f, -0x1.430d400000000p-8f, + 0x1.09af720000000p-13f, -0x1.e7140c0000000p-11f, 0x1.553e000000000p-10f, + 0x1.bfe6ee0000000p-8f, 0x1.2f581e0000000p-8f, -0x1.0b89600000000p-3f, + 0x1.e6f2b20000000p-4f, 0x1.cd8f8e0000000p-1f, 0x1.0c066e0000000p-1f, + -0x1.c5fd4e0000000p-8f, 0x1.01e0d60000000p-13f, -0x1.01e8060000000p-10f, + 0x1.7a2d9e0000000p-10f, 0x1.c2890c0000000p-8f, 0x1.028f2c0000000p-8f, + -0x1.100a6e0000000p-3f, 0x1.0bcf280000000p-3f, 0x1.d04eb00000000p-1f, + 0x1.0573b40000000p-1f, -0x1.1fe42e0000000p-7f, 0x1.e4c9900000000p-14f, + -0x1.1083480000000p-10f, 0x1.9ef9b00000000p-10f, 0x1.c548880000000p-8f, + 0x1.a536b40000000p-9f, -0x1.145d660000000p-3f, 0x1.2492a60000000p-3f, + 0x1.d2d9d00000000p-1f, 0x1.fdc3f40000000p-2f, -0x1.584fbc0000000p-7f, + 0x1.bbe1f00000000p-14f, -0x1.1f4cc40000000p-10f, 0x1.c3a28c0000000p-10f, + 0x1.c828fe0000000p-8f, 0x1.3ed0ae0000000p-9f, -0x1.187f1e0000000p-3f, + 0x1.3dc0340000000p-3f, 0x1.d530800000000p-1f, 0x1.f0a4d80000000p-2f, + -0x1.8c9d380000000p-7f, 0x1.8b83740000000p-14f, -0x1.2e42340000000p-10f, + 0x1.e827840000000p-10f, 0x1.cb2f1a0000000p-8f, 0x1.a38bba0000000p-10f, + -0x1.1c6c620000000p-3f, 0x1.5754320000000p-3f, 0x1.d7522c0000000p-1f, + 0x1.e38cc40000000p-2f, -0x1.bccca00000000p-7f, 0x1.51b3dc0000000p-14f, + -0x1.3d59c40000000p-10f, 0x1.0642740000000p-9f, 0x1.ce5f720000000p-8f, + 0x1.77c5740000000p-11f, -0x1.2021ea0000000p-3f, 0x1.714ae20000000p-3f, + 0x1.d93e620000000p-1f, 0x1.d67e3e0000000p-2f, -0x1.e902340000000p-7f, + 0x1.1135380000000p-14f, -0x1.4c72680000000p-10f, 0x1.184f0e0000000p-9f, + 0x1.d1bcf80000000p-8f, -0x1.cd43660000000p-13f, -0x1.239c8a0000000p-3f, + 0x1.8ba0220000000p-3f, 0x1.daf4c80000000p-1f, 0x1.c97bac0000000p-2f, + -0x1.08b5360000000p-6f, 0x1.9380400000000p-15f, -0x1.5b82640000000p-10f, + 0x1.2a36bc0000000p-9f, 0x1.d54b040000000p-8f, -0x1.3d508c0000000p-10f, + -0x1.26d9020000000p-3f, 0x1.a64ff60000000p-3f, 0x1.dc75060000000p-1f, + 0x1.bc87920000000p-2f, -0x1.1b117c0000000p-6f, 0x1.ef2dd20000000p-16f, + -0x1.6a7bb60000000p-10f, 0x1.3bf6ea0000000p-9f, 0x1.d90d680000000p-8f, + -0x1.27adc40000000p-9f, -0x1.29d4040000000p-3f, 0x1.c156200000000p-3f, + 0x1.ddbed80000000p-1f, 0x1.afa4460000000p-2f, -0x1.2ba7240000000p-6f, + 0x1.4b90ac0000000p-17f, -0x1.7946720000000p-10f, 0x1.4d8e5a0000000p-9f, + 0x1.dd07fe0000000p-8f, -0x1.b800720000000p-9f, -0x1.2c8a500000000p-3f, + 0x1.dcae220000000p-3f, 0x1.ded2060000000p-1f, 0x1.a2d44a0000000p-2f, + -0x1.3a80720000000p-6f, -0x1.700b940000000p-17f, -0x1.87d4460000000p-10f, + 0x1.5ef8ce0000000p-9f, 0x1.e13c820000000p-8f, -0x1.27dccc0000000p-8f, + -0x1.2ef8a80000000p-3f, 0x1.f853940000000p-3f, 0x1.dfae620000000p-1f, + 0x1.9619e20000000p-2f, -0x1.47ad4c0000000p-6f, -0x1.1120780000000p-15f, + -0x1.960c8c0000000p-10f, 0x1.7033800000000p-9f, 0x1.e5adfa0000000p-8f, + -0x1.7778760000000p-8f, -0x1.311bc00000000p-3f, 0x1.0a20dc0000000p-2f, + 0x1.e053dc0000000p-1f, 0x1.8977600000000p-2f, -0x1.533fe20000000p-6f, + -0x1.ca9a980000000p-15f, -0x1.a3dfa80000000p-10f, 0x1.813d240000000p-9f, + 0x1.ea5d320000000p-8f, -0x1.cade8a0000000p-8f, -0x1.32f0680000000p-3f, + 0x1.1839ec0000000p-2f, 0x1.e0c25e0000000p-1f, 0x1.7cef0e0000000p-2f, + -0x1.5d41a40000000p-6f, -0x1.45160a0000000p-14f, -0x1.b13e1c0000000p-10f, + 0x1.9211160000000p-9f, 0x1.ef4d0a0000000p-8f, -0x1.110bcc0000000p-7f, + -0x1.3473540000000p-3f, 0x1.2672860000000p-2f, 0x1.e0f9ee0000000p-1f, + 0x1.7083220000000p-2f, -0x1.65bf6a0000000p-6f, -0x1.a5d63c0000000p-14f, + -0x1.be0c7c0000000p-10f, 0x1.a2ad420000000p-9f, 0x1.f47de80000000p-8f, + -0x1.3e95720000000p-7f, -0x1.35a15c0000000p-3f, 0x1.34c8260000000p-2f, + 0x1.e0faa00000000p-1f, 0x1.6435c80000000p-2f, -0x1.6cc7d80000000p-6f, + -0x1.0363300000000p-13f, -0x1.ca38de0000000p-10f, 0x1.b30fc40000000p-9f, + 0x1.f9f0320000000p-8f, -0x1.6e0f4e0000000p-7f, -0x1.3677520000000p-3f, + 0x1.43383c0000000p-2f, 0x1.e0c4920000000p-1f, 0x1.58091e0000000p-2f, + -0x1.7268700000000p-6f, -0x1.33a4780000000p-13f, -0x1.d5b2c20000000p-10f, + 0x1.c336cc0000000p-9f, 0x1.ffa3600000000p-8f, -0x1.9f7bd20000000p-7f, + -0x1.36f2140000000p-3f, 0x1.51c02e0000000p-2f, 0x1.e057f20000000p-1f, + 0x1.4bff340000000p-2f, -0x1.76ae0c0000000p-6f, -0x1.63044a0000000p-13f, + -0x1.e062560000000p-10f, 0x1.d321240000000p-9f, 0x1.02cb720000000p-7f, + -0x1.d2dcc20000000p-7f, -0x1.370e8a0000000p-3f, 0x1.605d580000000p-2f, + 0x1.dfb5020000000p-1f, 0x1.401a140000000p-2f, -0x1.79a3480000000p-6f, + -0x1.91dea40000000p-13f, -0x1.ea3a6c0000000p-10f, 0x1.e2cc1c0000000p-9f, + 0x1.05e49c0000000p-7f, -0x1.04190e0000000p-6f, -0x1.36c9a00000000p-3f, + 0x1.6f0cfe0000000p-2f, 0x1.dedc080000000p-1f, 0x1.345b9e0000000p-2f, + -0x1.7b56a00000000p-6f, -0x1.bfa7220000000p-13f, -0x1.f327920000000p-10f, + 0x1.f234380000000p-9f, 0x1.091c860000000p-7f, -0x1.1fbe040000000p-6f, + -0x1.36205c0000000p-3f, 0x1.7dcc500000000p-2f, 0x1.ddcd600000000p-1f, + 0x1.28c5be0000000p-2f, -0x1.7bd6c00000000p-6f, -0x1.ebbcb00000000p-13f, + -0x1.fb17ea0000000p-10f, 0x1.00ad9a0000000p-8f, 0x1.0c71000000000p-7f, + -0x1.3c5cfa0000000p-6f, -0x1.350fba0000000p-3f, 0x1.8c989a0000000p-2f, + 0x1.dc89760000000p-1f, 0x1.1d5a3e0000000p-2f, -0x1.7b2ea80000000p-6f, + -0x1.0afed40000000p-12f, -0x1.00fdf80000000p-9f, 0x1.081ef40000000p-8f, + 0x1.0fe0aa0000000p-7f, -0x1.59f4a60000000p-6f, -0x1.3394de0000000p-3f, + 0x1.9b6efe0000000p-2f, 0x1.db10b80000000p-1f, 0x1.121ad80000000p-2f, + -0x1.796b8c0000000p-6f, -0x1.1f023c0000000p-12f, -0x1.03dff00000000p-9f, + 0x1.0f6d1a0000000p-8f, 0x1.1368de0000000p-7f, -0x1.7883900000000p-6f, + -0x1.31acee0000000p-3f, 0x1.aa4c940000000p-2f, 0x1.d963ae0000000p-1f, + 0x1.07092e0000000p-2f, -0x1.769b420000000p-6f, -0x1.31d35c0000000p-12f, + -0x1.062c000000000p-9f, 0x1.1697660000000p-8f, 0x1.1706fa0000000p-7f, + -0x1.9807dc0000000p-6f, -0x1.2f55300000000p-3f, 0x1.b92e760000000p-2f, + 0x1.d782e20000000p-1f, 0x1.f84daa0000000p-3f, -0x1.72cc440000000p-6f, + -0x1.435c0e0000000p-12f, -0x1.07dcd20000000p-9f, 0x1.1d9da20000000p-8f, + 0x1.1ab8380000000p-7f, -0x1.b87f060000000p-6f, -0x1.2c8af40000000p-3f, + 0x1.c811b40000000p-2f, 0x1.d56ef40000000p-1f, 0x1.e2ea940000000p-3f, + -0x1.6e0bd80000000p-6f, -0x1.5382940000000p-12f, -0x1.08eac40000000p-9f, + 0x1.247f400000000p-8f, 0x1.1e79ce0000000p-7f, -0x1.d9e6460000000p-6f, + -0x1.294b8c0000000p-3f, 0x1.d6f34e0000000p-2f, 0x1.d3288c0000000p-1f, + 0x1.cdebe00000000p-3f, -0x1.6865f20000000p-6f, -0x1.624b420000000p-12f, + -0x1.0952b80000000p-9f, 0x1.2b3bdc0000000p-8f, 0x1.2247060000000p-7f, + -0x1.fc3a1a0000000p-6f, -0x1.2594900000000p-3f, 0x1.e5d0500000000p-2f, + 0x1.d0b05e0000000p-1f, 0x1.b9542e0000000p-3f, -0x1.61ea740000000p-6f, + -0x1.6f8fc20000000p-12f, -0x1.090d6a0000000p-9f, 0x1.31d25e0000000p-8f, + 0x1.261bfc0000000p-7f, -0x1.0fbb460000000p-5f, -0x1.21637c0000000p-3f, + 0x1.f4a5aa0000000p-2f, 0x1.ce072e0000000p-1f, 0x1.a525de0000000p-3f, + -0x1.5aa7b40000000p-6f, -0x1.7b53da0000000p-12f, -0x1.0819600000000p-9f, + 0x1.3842c00000000p-8f, 0x1.29f3580000000p-7f, -0x1.21cbac0000000p-5f, + -0x1.1cb60a0000000p-3f, 0x1.01b82e0000000p-1f, 0x1.cb2dca0000000p-1f, + 0x1.9163520000000p-3f, -0x1.52aada0000000p-6f, -0x1.85a5dc0000000p-12f, + -0x1.0671aa0000000p-9f, 0x1.3e8b260000000p-8f, 0x1.2dc77c0000000p-7f, + -0x1.344b9e0000000p-5f, -0x1.1789fc0000000p-3f, 0x1.0916a80000000p-1f, + 0x1.c824fc0000000p-1f, 0x1.7e0e860000000p-3f, -0x1.4a023a0000000p-6f, + -0x1.8e754e0000000p-12f, -0x1.0411fc0000000p-9f, 0x1.44aa780000000p-8f, + 0x1.3192620000000p-7f, -0x1.4738520000000p-5f, -0x1.11dd300000000p-3f, + 0x1.106cbc0000000p-1f, 0x1.c4edac0000000p-1f, 0x1.6b29640000000p-3f, + -0x1.40bbf00000000p-6f, -0x1.95db9a0000000p-12f, -0x1.00fbba0000000p-9f, + 0x1.4aa1d60000000p-8f, 0x1.354e160000000p-7f, -0x1.5a8eb80000000p-5f, + -0x1.0bad980000000p-3f, 0x1.17b8dc0000000p-1f, 0x1.c188c20000000p-1f, + 0x1.58b59e0000000p-3f, -0x1.36e7a40000000p-6f, -0x1.9be6720000000p-12f, + -0x1.fa5a8a0000000p-10f, 0x1.506fe80000000p-8f, 0x1.38f3740000000p-7f, + -0x1.6e4b4c0000000p-5f, -0x1.04f9500000000p-3f, 0x1.1ef9820000000p-1f, + 0x1.bdf7340000000p-1f, 0x1.46b4b40000000p-3f, -0x1.2c935c0000000p-6f, + -0x1.a0ae100000000p-12f, -0x1.f14b760000000p-10f, 0x1.5614b40000000p-8f, + 0x1.3c7bfe0000000p-7f, -0x1.826b260000000p-5f, -0x1.fb7d1c0000000p-4f, + 0x1.262d200000000p-1f, 0x1.ba3a080000000p-1f, 0x1.3527ea0000000p-3f, + -0x1.21cb9e0000000p-6f, -0x1.a45ab20000000p-12f, -0x1.e6cbec0000000p-10f, + 0x1.5b8f3c0000000p-8f, 0x1.3fdefe0000000p-7f, -0x1.96ea060000000p-5f, + -0x1.ebf76a0000000p-4f, 0x1.2d52300000000p-1f, 0x1.b652420000000p-1f, + 0x1.24103e0000000p-3f, -0x1.16a0ec0000000p-6f, -0x1.a6fa860000000p-12f, + -0x1.dadcf00000000p-10f, 0x1.60df2e0000000p-8f, 0x1.4315740000000p-7f, + -0x1.abc3c80000000p-5f, -0x1.db5e1e0000000p-4f, 0x1.3467220000000p-1f, + 0x1.b240fa0000000p-1f, 0x1.136ebc0000000p-3f, -0x1.0b217a0000000p-6f, + -0x1.a8bb460000000p-12f, -0x1.cd821e0000000p-10f, 0x1.6605500000000p-8f, + 0x1.4617c60000000p-7f, -0x1.c0f3f60000000p-5f, -0x1.c9aeee0000000p-4f, + 0x1.3b6a700000000p-1f, 0x1.ae07440000000p-1f, 0x1.03441c0000000p-3f, + -0x1.feb4ba0000000p-7f, -0x1.a9e0be0000000p-12f, -0x1.bebef20000000p-10f, + 0x1.6b004c0000000p-8f, 0x1.48dc4a0000000p-7f, -0x1.d675c20000000p-5f, + -0x1.b6e6ae0000000p-4f, 0x1.425a960000000p-1f, 0x1.a9a64c0000000p-1f, + 0x1.e7217e0000000p-4f, -0x1.e6b55c0000000p-7f, -0x1.aa85020000000p-12f, + -0x1.ae9b460000000p-10f, 0x1.6fd00c0000000p-8f, 0x1.4b59340000000p-7f, + -0x1.ec43c80000000p-5f, -0x1.a303a20000000p-4f, 0x1.49360c0000000p-1f, + 0x1.a51f340000000p-1f, 0x1.c8a9d20000000p-4f, -0x1.ce5e0a0000000p-7f, + -0x1.aade480000000p-12f, -0x1.9d1b940000000p-10f, 0x1.7474cc0000000p-8f, + 0x1.4d85040000000p-7f, -0x1.012c820000000p-4f, -0x1.8e03600000000p-4f, + 0x1.4ffb520000000p-1f, 0x1.a073360000000p-1f, 0x1.ab21ee0000000p-4f, + -0x1.b5ce920000000p-7f, -0x1.ab1c980000000p-12f, -0x1.8a49160000000p-10f, + 0x1.78eec60000000p-8f, 0x1.4f55b00000000p-7f, -0x1.0c57ca0000000p-4f, + -0x1.77e4720000000p-4f, 0x1.56a8e60000000p-1f, 0x1.9ba3820000000p-1f, + 0x1.8e894a0000000p-4f, -0x1.9d20fe0000000p-7f, -0x1.ab834e0000000p-12f, + -0x1.762b260000000p-10f, 0x1.7d3dde0000000p-8f, 0x1.50c0480000000p-7f, + -0x1.17a0ae0000000p-4f, -0x1.60a5560000000p-4f, 0x1.5d3d4e0000000p-1f, + 0x1.96b1680000000p-1f, 0x1.72df7c0000000p-4f, -0x1.846b160000000p-7f, + -0x1.ac64680000000p-12f, -0x1.60cd740000000p-10f, 0x1.81625a0000000p-8f, + 0x1.51b9dc0000000p-7f, -0x1.2303ee0000000p-4f, -0x1.4845000000000p-4f, + 0x1.63b7140000000p-1f, 0x1.919e200000000p-1f, 0x1.5823340000000p-4f, + -0x1.6bcd900000000p-7f, -0x1.adf08e0000000p-12f, -0x1.4a3ac20000000p-10f, + 0x1.855cfe0000000p-8f, 0x1.5237680000000p-7f, -0x1.2e7e4e0000000p-4f, + -0x1.2ec2760000000p-4f, 0x1.6a14c00000000p-1f, 0x1.8c6afe0000000p-1f, + 0x1.3e53ba0000000p-4f, -0x1.53608c0000000p-7f, -0x1.b06dac0000000p-12f, + -0x1.327bec0000000p-10f, 0x1.892e780000000p-8f, 0x1.522d9c0000000p-7f, + -0x1.3a0c300000000p-4f, -0x1.141d6e0000000p-4f, 0x1.7054ee0000000p-1f, + 0x1.87194e0000000p-1f, 0x1.256f780000000p-4f, -0x1.3b3a720000000p-7f, + -0x1.b4260a0000000p-12f, -0x1.199f100000000p-10f, 0x1.8cd8000000000p-8f, + 0x1.5190560000000p-7f, -0x1.45aa140000000p-4f, -0x1.f0ab120000000p-5f, + 0x1.7676320000000p-1f, 0x1.81aa700000000p-1f, 0x1.0d73ae0000000p-4f, + -0x1.2378140000000p-7f, -0x1.b946980000000p-12f, -0x1.ff5dae0000000p-11f, + 0x1.905a600000000p-8f, 0x1.5053d20000000p-7f, -0x1.5154220000000p-4f, + -0x1.b6d5d40000000p-5f, 0x1.7c772e0000000p-1f, 0x1.7c1fb80000000p-1f, + 0x1.ecbc3e0000000p-5f, -0x1.0c29f20000000p-7f, -0x1.c0151e0000000p-12f, + -0x1.c96f140000000p-11f, 0x1.93b7460000000p-8f, 0x1.4e6c1e0000000p-7f, + -0x1.5d064a0000000p-4f, -0x1.7abc7a0000000p-5f, 0x1.8256860000000p-1f, + 0x1.767a860000000p-1f, 0x1.c059b00000000p-5f, -0x1.eadf100000000p-8f, + -0x1.c8cc9c0000000p-12f, -0x1.918eb80000000p-11f, 0x1.96effa0000000p-8f, + 0x1.4bcc520000000p-7f, -0x1.68bca00000000p-4f, -0x1.3c5fe80000000p-5f, + 0x1.8812e80000000p-1f, 0x1.70bc380000000p-1f, 0x1.95b8180000000p-5f, + -0x1.bebb380000000p-8f, -0x1.d3ab2e0000000p-12f, -0x1.57d51e0000000p-11f, + 0x1.9a075e0000000p-8f, 0x1.4868760000000p-7f, -0x1.7472b40000000p-4f, + -0x1.f785a60000000p-6f, 0x1.8dab0e0000000p-1f, 0x1.6ae6480000000p-1f, + 0x1.6cd0a40000000p-5f, -0x1.93fad20000000p-8f, -0x1.e0dd0e0000000p-12f, + -0x1.1c6a140000000p-11f, 0x1.9cfe1a0000000p-8f, 0x1.44329c0000000p-7f, + -0x1.80243a0000000p-4f, -0x1.71cfa40000000p-6f, 0x1.931db60000000p-1f, + 0x1.64fa0a0000000p-1f, 0x1.459afa0000000p-5f, -0x1.6ae5d80000000p-8f, + -0x1.f0751e0000000p-12f, -0x1.bea86e0000000p-12f, 0x1.9fd7d60000000p-8f, + 0x1.3f20100000000p-7f, -0x1.8bcca00000000p-4f, -0x1.cf4aee0000000p-7f, + 0x1.9869a40000000p-1f, 0x1.5ef8f00000000p-1f, 0x1.2010120000000p-5f, + -0x1.43917e0000000p-8f, -0x1.014d9e0000000p-11f, -0x1.41769a0000000p-12f, + 0x1.a2962a0000000p-8f, 0x1.39224a0000000p-7f, -0x1.9767380000000p-4f, + -0x1.643b740000000p-8f, 0x1.9d8dac0000000p-1f, 0x1.58e4620000000p-1f, + 0x1.f8505c0000000p-6f, -0x1.1e15b40000000p-8f, -0x1.0bbd1e0000000p-11f, + -0x1.82f5720000000p-13f, 0x1.a53c820000000p-8f, 0x1.322da40000000p-7f, + -0x1.a2ef380000000p-4f, 0x1.cf4bf20000000p-9f, 0x1.a288b20000000p-1f, + 0x1.52bdd00000000p-1f, 0x1.b3a9200000000p-6f, -0x1.f55fc60000000p-9f, + -0x1.1795420000000p-11f, -0x1.f78ba40000000p-15f, 0x1.a7cd100000000p-8f, + 0x1.2a34100000000p-7f, -0x1.ae5f920000000p-4f, 0x1.a272920000000p-7f, + 0x1.a7599a0000000p-1f, 0x1.4c86bc0000000p-1f, 0x1.72191a0000000p-6f, + -0x1.b278bc0000000p-9f, -0x1.24d82e0000000p-11f, 0x1.176aba0000000p-14f, + 0x1.aa4b400000000p-8f, 0x1.21297e0000000p-7f, -0x1.b9b3340000000p-4f, + 0x1.6cd36a0000000p-6f, 0x1.abff500000000p-1f, 0x1.46406e0000000p-1f, + 0x1.3392320000000p-6f, -0x1.7413460000000p-9f, -0x1.3371980000000p-11f, + 0x1.9954380000000p-13f, 0x1.acba4a0000000p-8f, 0x1.1700e40000000p-7f, + -0x1.c4e4ec0000000p-4f, 0x1.0655200000000p-5f, 0x1.b078e40000000p-1f, + 0x1.3fec680000000p-1f, 0x1.efd5a20000000p-7f, -0x1.3a3eea0000000p-9f, + -0x1.43727a0000000p-11f, 0x1.5542700000000p-12f, 0x1.af1de80000000p-8f, + 0x1.0bacb40000000p-7f, -0x1.cfef6c0000000p-4f, 0x1.58574a0000000p-5f, + 0x1.b4c5620000000p-1f, 0x1.398c3c0000000p-1f, 0x1.7e1d1c0000000p-7f, + -0x1.039df20000000p-9f, -0x1.54c2b80000000p-11f, 0x1.df54960000000p-12f, + 0x1.b17a740000000p-8f, 0x1.fe42040000000p-8f, -0x1.dacd4c0000000p-4f, + 0x1.ac68700000000p-5f, 0x1.b8e3f00000000p-1f, 0x1.33211a0000000p-1f, + 0x1.11a4f80000000p-7f, -0x1.a3b4ea0000000p-10f, -0x1.671b880000000p-11f, + 0x1.3568c80000000p-11f, 0x1.b3d4520000000p-8f, 0x1.e2a46e0000000p-8f, + -0x1.e579200000000p-4f, 0x1.013ff60000000p-4f, 0x1.bcd3ee0000000p-1f, + 0x1.2cacd00000000p-1f, 0x1.53b1420000000p-8f, -0x1.42fb1c0000000p-10f, + -0x1.7b9bba0000000p-11f, 0x1.7c27840000000p-11f, 0x1.b62ed40000000p-8f, + 0x1.c465e60000000p-8f, -0x1.efecf00000000p-4f, 0x1.2d4b160000000p-4f, + 0x1.c093960000000p-1f, 0x1.2631fe0000000p-1f, 0x1.21b5e00000000p-9f, + -0x1.a0c52c0000000p-11f, +}; + +inline constexpr std::array, 64> kRotation = {{ + {0x1.fff6220000000p-1f, -0x1.921d200000000p-7f}, + {0x1.ffa72e0000000p-1f, -0x1.2d86580000000p-5f}, + {0x1.ff09560000000p-1f, -0x1.f656e80000000p-5f}, + {0x1.fe1cb00000000p-1f, -0x1.5f6d000000000p-4f}, + {0x1.fce1600000000p-1f, -0x1.c3785c0000000p-4f}, + {0x1.fb57980000000p-1f, -0x1.139f0c0000000p-3f}, + {0x1.f97f920000000p-1f, -0x1.45576c0000000p-3f}, + {0x1.f7599a0000000p-1f, -0x1.76dd9e0000000p-3f}, + {0x1.f4e6040000000p-1f, -0x1.a82a020000000p-3f}, + {0x1.f225300000000p-1f, -0x1.d934fe0000000p-3f}, + {0x1.ef178a0000000p-1f, -0x1.04fb800000000p-2f}, + {0x1.ebbd8c0000000p-1f, -0x1.1d34440000000p-2f}, + {0x1.e817ba0000000p-1f, -0x1.35410c0000000p-2f}, + {0x1.e426a40000000p-1f, -0x1.4d1e240000000p-2f}, + {0x1.dfeae60000000p-1f, -0x1.64c7de0000000p-2f}, + {0x1.db65260000000p-1f, -0x1.7c3a940000000p-2f}, + {0x1.d696180000000p-1f, -0x1.9372a60000000p-2f}, + {0x1.d17e780000000p-1f, -0x1.aa6c820000000p-2f}, + {0x1.cc1f100000000p-1f, -0x1.c1249e0000000p-2f}, + {0x1.c678b40000000p-1f, -0x1.d797760000000p-2f}, + {0x1.c08c420000000p-1f, -0x1.edc1960000000p-2f}, + {0x1.ba5aa60000000p-1f, -0x1.01cfc80000000p-1f}, + {0x1.b3e4d40000000p-1f, -0x1.0c97040000000p-1f}, + {0x1.ad2bca0000000p-1f, -0x1.1734d60000000p-1f}, + {0x1.a630920000000p-1f, -0x1.21a79a0000000p-1f}, + {0x1.9ef43e0000000p-1f, -0x1.2bedb20000000p-1f}, + {0x1.9777f00000000p-1f, -0x1.36058c0000000p-1f}, + {0x1.8fbcca0000000p-1f, -0x1.3fed960000000p-1f}, + {0x1.87c4000000000p-1f, -0x1.49a44a0000000p-1f}, + {0x1.7f8ece0000000p-1f, -0x1.53282a0000000p-1f}, + {0x1.771e760000000p-1f, -0x1.5c77bc0000000p-1f}, + {0x1.6e74460000000p-1f, -0x1.6591920000000p-1f}, + {0x1.6591920000000p-1f, -0x1.6e74460000000p-1f}, + {0x1.5c77bc0000000p-1f, -0x1.771e760000000p-1f}, + {0x1.53282a0000000p-1f, -0x1.7f8ece0000000p-1f}, + {0x1.49a44a0000000p-1f, -0x1.87c4000000000p-1f}, + {0x1.3fed960000000p-1f, -0x1.8fbcca0000000p-1f}, + {0x1.36058c0000000p-1f, -0x1.9777f00000000p-1f}, + {0x1.2bedb20000000p-1f, -0x1.9ef43e0000000p-1f}, + {0x1.21a79a0000000p-1f, -0x1.a630920000000p-1f}, + {0x1.1734d60000000p-1f, -0x1.ad2bca0000000p-1f}, + {0x1.0c97040000000p-1f, -0x1.b3e4d40000000p-1f}, + {0x1.01cfc80000000p-1f, -0x1.ba5aa60000000p-1f}, + {0x1.edc1960000000p-2f, -0x1.c08c420000000p-1f}, + {0x1.d797760000000p-2f, -0x1.c678b40000000p-1f}, + {0x1.c1249e0000000p-2f, -0x1.cc1f100000000p-1f}, + {0x1.aa6c820000000p-2f, -0x1.d17e780000000p-1f}, + {0x1.9372a60000000p-2f, -0x1.d696180000000p-1f}, + {0x1.7c3a940000000p-2f, -0x1.db65260000000p-1f}, + {0x1.64c7de0000000p-2f, -0x1.dfeae60000000p-1f}, + {0x1.4d1e240000000p-2f, -0x1.e426a40000000p-1f}, + {0x1.35410c0000000p-2f, -0x1.e817ba0000000p-1f}, + {0x1.1d34440000000p-2f, -0x1.ebbd8c0000000p-1f}, + {0x1.04fb800000000p-2f, -0x1.ef178a0000000p-1f}, + {0x1.d934fe0000000p-3f, -0x1.f225300000000p-1f}, + {0x1.a82a020000000p-3f, -0x1.f4e6040000000p-1f}, + {0x1.76dd9e0000000p-3f, -0x1.f7599a0000000p-1f}, + {0x1.45576c0000000p-3f, -0x1.f97f920000000p-1f}, + {0x1.139f0c0000000p-3f, -0x1.fb57980000000p-1f}, + {0x1.c3785c0000000p-4f, -0x1.fce1600000000p-1f}, + {0x1.5f6d000000000p-4f, -0x1.fe1cb00000000p-1f}, + {0x1.f656e80000000p-5f, -0x1.ff09560000000p-1f}, + {0x1.2d86580000000p-5f, -0x1.ffa72e0000000p-1f}, + {0x1.921d200000000p-7f, -0x1.fff6220000000p-1f}, +}}; + +inline constexpr std::array, 22> kHybrid = {{ + {-0x1.3a7de80000000p-7f, 0x1.0488900000000p-8f}, + {-0x1.4f39c60000000p-6f, 0x1.4f39c60000000p-6f}, + {-0x1.4f65900000000p-6f, 0x1.94dc0e0000000p-5f}, + {0x0.0p+0f, 0x1.4382f00000000p-4f}, + {0x1.3844900000000p-5f, 0x1.78f0ca0000000p-4f}, + {0x1.459b100000000p-4f, 0x1.459b100000000p-4f}, + {0x1.c49e200000000p-4f, 0x1.76f5f60000000p-5f}, + {0x1.0000000000000p-3f, 0x0.0p+0f}, + {0x1.c426000000000p-4f, -0x1.7692720000000p-5f}, + {0x1.2d4d820000000p-5f, -0x1.2d4d820000000p-5f}, + {0x1.e4029a0000000p-6f, -0x1.2420400000000p-4f}, + {-0x1.1ce09c0000000p-7f, 0x1.1ce0900000000p-7f}, + {0x0.0p+0f, 0x1.b5bb180000000p-6f}, + {0x1.586f240000000p-6f, 0x1.586f2c0000000p-6f}, + {0x0.0p+0f, 0x0.0p+0f}, + {-0x1.9eb2460000000p-5f, 0x1.9eb2460000000p-5f}, + {0x0.0p+0f, 0x1.5019100000000p-3f}, + {0x1.515a8e0000000p-3f, 0x1.515a8e0000000p-3f}, + {0x1.0000000000000p-2f, 0x0.0p+0f}, + {0x1.515b660000000p-3f, -0x1.515b660000000p-3f}, + {0x0.0p+0f, -0x1.1f2f040000000p-3f}, + {-0x1.af372a0000000p-5f, -0x1.af372a0000000p-5f}, +}}; + +} diff --git a/src/hrtf/rosella_renderer.cpp b/src/hrtf/rosella_renderer.cpp index 87e73d1..72f9085 100644 --- a/src/hrtf/rosella_renderer.cpp +++ b/src/hrtf/rosella_renderer.cpp @@ -12,7 +12,7 @@ #include #include "foundation/fft.h" -#include "hrtf/public_filterbank.h" +#include "hrtf/rosella_filterbank.h" namespace joc::hrtf { @@ -1003,8 +1003,8 @@ struct RosellaRuntime::Impl { std::vector field_left; std::vector field_right; Core core; - std::unique_ptr analysis_bank; - std::unique_ptr synthesis_bank; + std::unique_ptr analysis_bank; + std::unique_ptr synthesis_bank; timeline::OamdPositionTimeline timeline{timeline::kTimelineObjects}; std::vector buffer; // [chunk_samples][16] @@ -1051,9 +1051,7 @@ struct RosellaRuntime::Impl { analysis_bank->analyze_qmf(hops_, slots, &qmf_); analysis_bank->analyze_hybrid(qmf_, slots, &hybrid_); - if (rendered_.size() < slots * 2u * kHybridBands) { - rendered_.resize(slots * 2u * kHybridBands); - } + rendered_.resize(slots * 2u * kHybridBands); if (room_sends_buffer_.size() != slots * kHybridBands) { room_sends_buffer_.resize(slots * kHybridBands); } @@ -1141,10 +1139,8 @@ struct RosellaRuntime::Impl { return Status::success(); } - // The reference drops the first 961 samples of the raw stream (the filterbank's - // latency) and returns everything after that. void append_output(const double* stereo, std::size_t count) { - const std::int64_t remaining = static_cast(kLatencySamples) - + const std::int64_t remaining = static_cast(RosellaFilterbank::kLatencySamples) - static_cast(raw_output_samples); const std::size_t skip = static_cast( std::max(0, std::min(static_cast(count), @@ -1203,8 +1199,8 @@ Status RosellaRuntime::open(const RosellaModel& model, const RosellaRenderOption return status; } // The analysis bank runs sixteen sources, the synthesis bank two output ears. - impl_->analysis_bank = std::make_unique(builtin_kernels(), kSourceChannels); - impl_->synthesis_bank = std::make_unique(builtin_kernels(), kOutputChannels); + impl_->analysis_bank = std::make_unique(kSourceChannels); + impl_->synthesis_bank = std::make_unique(kOutputChannels); impl_->buffer.assign(impl_->chunk_samples() * kSourceChannels, 0.0); impl_->room_sends_buffer_.assign( (impl_->chunk_samples() / kQmfHop) * kHybridBands, Complex(0.0, 0.0)); @@ -1309,7 +1305,8 @@ Status RosellaRuntime::finish(std::uint32_t flush_samples, std::vector* } std::uint32_t RosellaRuntime::finish_capacity(double tail_seconds) const { - const double samples = tail_seconds * 48000.0 + static_cast(kLatencySamples) + + const double samples = tail_seconds * 48000.0 + + static_cast(RosellaFilterbank::kLatencySamples) + static_cast(kBlockSamples); const double blocks = std::ceil(samples / static_cast(kBlockSamples)); return static_cast(blocks) * kBlockSamples; diff --git a/tests/rosella_filterbank_vectors.h b/tests/rosella_filterbank_vectors.h new file mode 100644 index 0000000..492710a --- /dev/null +++ b/tests/rosella_filterbank_vectors.h @@ -0,0 +1,149 @@ +#pragma once + +#include +#include +#include + +namespace rosella_test_vectors { +struct ComplexSample { + std::size_t index; + std::complex value; +}; +struct RealSample { + std::size_t index; + double value; +}; + +inline const std::array kAnalysis = {{ + {0, {7.775565228424679e-06, 7.906356926119044e-05}}, + {1, {0.00012425227206597824, -4.6868619154722554e-05}}, + {31, {-4.138787216985311e-05, 5.162831590295054e-05}}, + {63, {-3.295086025588919e-05, -1.278928940280279e-06}}, + {64, {-3.351389443094305e-05, -0.00022684860394147635}}, + {69, {5.8879855585687005e-05, -0.0002184987979386939}}, + {127, {0.00017914426737246358, 9.642064782431324e-05}}, + {131, {0.0007132287349731125, 0.005832527881460842}}, + {175, {-0.0007411187757106858, 0.0006807654251128285}}, + {242, {-0.00614632667390274, -0.0018421222212599044}}, + {257, {0.019850879270364816, -0.006693042832175101}}, + {293, {-0.012195686344065404, -0.05921478919952099}}, + {301, {-0.002478141082434576, -0.003954837666622094}}, + {326, {-0.0025580636031437235, 0.0011174056358154022}}, + {510, {-0.017663241703992184, 0.0035507173965086524}}, + {544, {-0.008784632095067399, -0.009135393193440677}}, + {574, {-0.0009629093082367752, 0.0013287365759095497}}, + {603, {-0.0005141177077425535, 0.013385273817837683}}, + {637, {0.011278058600388273, 0.005937452476230072}}, + {643, {-0.00696332728884343, -0.004978700787364526}}, + {729, {0.0050457117591332055, 0.0016826727046474407}}, + {775, {0.003469262666915679, -0.004257569406861563}}, + {790, {-0.026299750617793667, 0.00416375313051273}}, + {856, {-0.011484924452018283, -0.00982872323688277}}, + {922, {0.012688560629388848, -0.00728168396968646}}, + {1000, {0.0011519072188212057, 0.006119400449478027}}, + {1061, {0.020940840595677954, -0.06189070534623452}}, + {1207, {0.010885743908845955, -0.006471503744246215}}, + {1431, {-0.007917589523676893, -0.004370087901858095}}, + {1458, {-0.008628466739126659, -0.0049257923325374}}, + {1511, {-0.004288762266687254, -0.0037576188137696497}}, + {1883, {0.008904981656753283, 0.004748622951092901}}, + {1985, {-0.01717853841839118, 0.033529024231708275}}, + {2009, {-0.006341206558393465, -0.0074488295721425605}}, + {2092, {0.004890829038856598, -0.0021667714905464486}}, + {2158, {0.006867229461380485, -0.0007371346599858038}}, + {2334, {-0.008248554400186915, -0.008662518985429475}}, + {2341, {-0.050888945810442746, 0.04982127826658001}}, + {2357, {-0.005734420983740394, -0.00038765299755766716}}, + {2429, {0.005443893166595231, -0.004923640532580573}}, + {2634, {0.011669730754497142, 0.020050423296197745}}, + {2779, {0.00020074872192237295, -0.006839871400930875}}, + {2955, {0.015493214930132214, 0.0018690053738887411}}, + {3008, {-0.011124416898103392, 0.006642606867866255}}, + {3071, {0.01165356921865766, -0.0044997289743379885}}, +}}; + +inline const std::array kHybrid = {{ + {0, {5.868502326194375e-06, 1.7811152741480289e-06}}, + {1, {-5.4090964786860795e-06, -2.8902191018360635e-06}}, + {31, {0.0, 0.0}}, + {63, {0.0, 0.0}}, + {64, {0.0, 0.0}}, + {83, {-1.5188745949094245e-05, 9.09168380003381e-06}}, + {127, {0.0, 0.0}}, + {158, {0.00022583760103915134, -0.0004918103466920481}}, + {211, {0.0, 0.0}}, + {291, {0.0, 0.0}}, + {309, {-0.00015653046815661031, -0.0007306572668268195}}, + {353, {0.0, 0.0}}, + {362, {0.0, 0.0}}, + {392, {0.0007376543189844669, 0.00037513740947532886}}, + {614, {8.188514820841106e-06, 0.00018887636186503467}}, + {655, {-0.0002652390760717492, -0.0003838899787227982}}, + {691, {-0.0006112716629595866, -0.0002847050760692751}}, + {726, {-0.018681684150467052, 0.0024137001732511764}}, + {766, {-0.0011129045309462016, -0.0020692542444214848}}, + {774, {0.0008947778929531689, 0.0023555612398049788}}, + {878, {0.15610973092082112, 0.027180902851271033}}, + {933, {-0.0009923870793706617, -0.0004164569559879513}}, + {950, {-0.010556238335200434, -0.001222834781836447}}, + {1030, {0.012704796696902542, 0.0067623566227308024}}, + {1109, {-0.15244884147047966, -0.10978580650105556}}, + {1204, {-0.003434582532641294, 0.013677101643146762}}, + {1277, {0.002232145931138603, -0.00245876551959133}}, + {1452, {0.0013877744513344833, 0.010560167634531287}}, + {1722, {-0.008778455102118702, -0.009435079990235172}}, + {1754, {0.0008815091566413778, -0.0035065893857165464}}, + {1818, {-0.016024996427009656, 0.0034474393638554944}}, + {2265, {-0.045198220401304445, -0.10361062266400728}}, + {2388, {0.0005725894600346051, 0.0015359513917156335}}, + {2418, {-0.0019316669156428739, 0.21602300351272932}}, + {2517, {0.00201767915456565, -0.0028188485607173333}}, + {2596, {-0.00038944457447919844, 0.0015101147811087895}}, + {2809, {-0.008143911805470605, 0.01292515077837547}}, + {2817, {-0.0027510729690434243, 0.006659055212161834}}, + {2836, {-9.369629609244992e-05, -0.0026304132267606292}}, + {2922, {0.019245886198162414, -0.009431432730065513}}, + {3169, {-0.010855219707682658, 0.013010869795091879}}, + {3343, {-0.04505161077995541, -0.11044313232127823}}, + {3555, {-0.003976142798898398, -0.007486276873628099}}, + {3619, {0.00010380687898299806, 0.001843237344836469}}, + {3695, {-0.007436310982457473, -0.013161158071572683}}, +}}; + +inline const std::array kFold = {{ + {0, {-2.109375, -0.71875}}, {1, {0.046875, 0.0}}, {31, {-0.09375, 0.71875}}, + {63, {0.515625, -0.359375}}, {64, {-1.03125, -0.296875}}, {69, {-0.75, 0.46875}}, + {127, {0.453125, 0.125}}, {131, {0.234375, 0.546875}}, {175, {-0.703125, 0.390625}}, + {242, {0.03125, -0.03125}}, {257, {0.625, 0.171875}}, {293, {-0.328125, -0.671875}}, + {301, {0.21875, -0.5625}}, {326, {-0.734375, -0.421875}}, {510, {-0.1875, -0.203125}}, + {544, {-0.328125, 0.25}}, {574, {-0.25, 0.28125}}, {603, {-0.140625, -0.28125}}, + {637, {-0.578125, 0.5625}}, {643, {-0.265625, -0.125}}, {729, {0.78125, 0.28125}}, + {775, {0.671875, 0.140625}}, {790, {-0.078125, 0.15625}}, {856, {0.390625, -0.46875}}, + {922, {-0.71875, 0.421875}}, {1000, {-0.21875, 0.71875}}, {1061, {0.5, 0.59375}}, + {1207, {0.421875, 0.671875}}, {1431, {-0.4375, 0.65625}}, {1458, {0.421875, 0.078125}}, + {1511, {0.59375, -0.15625}}, {1883, {0.1875, 0.3125}}, {1985, {0.1875, -0.5625}}, + {2009, {-0.46875, -0.640625}}, {2092, {-0.21875, 0.671875}}, {2158, {0.25, 0.046875}}, + {2334, {0.546875, -0.234375}}, {2341, {-0.75, -0.328125}}, {2357, {0.34375, -0.109375}}, + {2429, {-0.75, 0.484375}}, {2634, {-0.34375, -0.359375}}, {2779, {-0.6875, -0.484375}}, + {2955, {-0.390625, 0.75}}, {3008, {-0.359375, -0.59375}}, {3071, {0.734375, -0.328125}}, +}}; + +inline const std::array kSynthesis = {{ + {0, -0.001658459165691889}, {1, 0.010948236643244243}, {31, -0.10085266025508711}, + {63, -0.003503870976352294}, {64, 0.0034821124123800007}, {69, 0.0036009386713644993}, + {127, -0.004572690451391407}, {131, -0.0968983768626099}, {175, 3.956732506047194}, + {242, -0.02213695704158057}, {257, 5.161514411138107}, {293, -2.22783403263535}, + {301, 1.658025919090119}, {326, 0.7270199192910349}, {510, 10.646246826011666}, + {544, 4.02304233235568}, {574, -1.8869149188681806}, {603, -3.6776755660477827}, + {637, 7.303828443375595}, {643, -6.429907198877739}, {729, 0.5963645962389459}, + {775, 3.801043327575303}, {790, -31.546778942872983}, {856, -0.16830000749121746}, + {922, -2.2137404260494975}, {1000, 0.24234450303821295}, {1061, 0.13427657788640274}, + {1207, -7.446434384896017}, {1431, -5.137441688406155}, {1458, -6.380668393736482}, + {1511, -5.013969777723457}, {1883, -6.706452727886115}, {1985, 9.437019480312102}, + {2009, -7.787276846635089}, {2092, -1.285900598190846}, {2158, -9.98553088525826}, + {2334, 0.621609996592438}, {2341, 4.2410850082140366}, {2357, 0.7274497164538002}, + {2429, 4.407873764785114}, {2634, -5.023050721472806}, {2779, -0.7007366475135158}, + {2955, 4.26452198462612}, {3008, 4.390815174418314}, {3071, -13.869120688929403}, +}}; + +} diff --git a/tests/test_rosella_filterbank.cpp b/tests/test_rosella_filterbank.cpp new file mode 100644 index 0000000..31ac906 --- /dev/null +++ b/tests/test_rosella_filterbank.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include + +#include "hrtf/rosella_filterbank.h" +#include "rosella_filterbank_vectors.h" + +namespace { + +int failures = 0; + +void check(bool passed, const char* name) { + if (!passed) { + std::fprintf(stderr, "FAIL: %s\n", name); + ++failures; + } +} + +using joc::hrtf::Complex; +using joc::hrtf::RosellaFilterbank; + +template +void check_samples(const std::vector& actual, const Expected& expected, const char* name) { + for (const auto& sample : expected) { + check(std::abs(actual.at(sample.index) - sample.value) < 1e-10, name); + } +} + +void test_reference_and_streaming() { + constexpr std::size_t slots = 24; + constexpr std::size_t channels = 2; + std::vector input(slots * channels * 64); + for (std::size_t index = 0; index < input.size(); ++index) { + input[index] = (static_cast((index * 37 + 11) % 257) - 128) / 128.0; + } + RosellaFilterbank bank(channels); + std::vector qmf, hybrid, folded; + std::vector time; + bank.analyze_qmf(input, slots, &qmf); + bank.analyze_hybrid(qmf, slots, &hybrid); + check_samples(qmf, rosella_test_vectors::kAnalysis, "analysis reference"); + check_samples(hybrid, rosella_test_vectors::kHybrid, "hybrid reference"); + + std::vector synthetic(slots * channels * 77); + for (std::size_t index = 0; index < synthetic.size(); ++index) { + synthetic[index] = Complex((static_cast((index * 17 + 3) % 101) - 50) / 64.0, + (static_cast((index * 13 + 7) % 97) - 48) / 64.0); + } + bank.synthesize_hybrid(synthetic, slots, &folded); + bank.synthesize_qmf(folded, slots, &time); + check_samples(folded, rosella_test_vectors::kFold, "fold reference"); + check_samples(time, rosella_test_vectors::kSynthesis, "synthesis reference"); + + for (int repeat = 0; repeat < 2; ++repeat) { + bank.reset(); + std::vector joined_qmf, joined_hybrid, joined_folded; + std::vector joined_time; + std::size_t first = 0; + for (const std::size_t count : {0u, 1u, 7u, 0u, 3u, 13u}) { + std::vector part_input(input.begin() + first * channels * 64, + input.begin() + (first + count) * channels * 64); + std::vector part_synthetic(synthetic.begin() + first * channels * 77, + synthetic.begin() + + (first + count) * channels * 77); + std::vector part_qmf, part_hybrid, part_folded; + std::vector part_time; + bank.analyze_qmf(part_input, count, &part_qmf); + bank.analyze_hybrid(part_qmf, count, &part_hybrid); + bank.synthesize_hybrid(part_synthetic, count, &part_folded); + bank.synthesize_qmf(part_folded, count, &part_time); + joined_qmf.insert(joined_qmf.end(), part_qmf.begin(), part_qmf.end()); + joined_hybrid.insert(joined_hybrid.end(), part_hybrid.begin(), part_hybrid.end()); + joined_folded.insert(joined_folded.end(), part_folded.begin(), part_folded.end()); + joined_time.insert(joined_time.end(), part_time.begin(), part_time.end()); + first += count; + } + check(joined_qmf == qmf, "analysis chunk/reset invariance"); + check(joined_hybrid == hybrid, "hybrid chunk/reset invariance"); + check(joined_folded == folded, "fold chunk/reset invariance"); + check(joined_time == time, "synthesis chunk/reset invariance"); + } + + for (std::size_t channel = 0; channel < channels; ++channel) { + RosellaFilterbank mono(1); + std::vector mono_input; + for (std::size_t slot = 0; slot < slots; ++slot) { + const auto first = input.begin() + (slot * channels + channel) * 64; + mono_input.insert(mono_input.end(), first, first + 64); + } + std::vector mono_qmf, mono_hybrid; + mono.analyze_qmf(mono_input, slots, &mono_qmf); + mono.analyze_hybrid(mono_qmf, slots, &mono_hybrid); + for (std::size_t slot = 0; slot < slots; ++slot) { + check(std::equal(mono_hybrid.begin() + slot * 77, mono_hybrid.begin() + (slot + 1) * 77, + hybrid.begin() + (slot * channels + channel) * 77), + "channel isolation"); + } + } +} + +void test_latency() { + RosellaFilterbank bank(1); + std::vector impulse(64 * 64); + impulse[0] = 1.0; + std::vector qmf, hybrid; + std::vector output; + bank.analyze_qmf(impulse, 64, &qmf); + bank.analyze_hybrid(qmf, 64, &hybrid); + bank.synthesize_hybrid(hybrid, 64, &qmf); + bank.synthesize_qmf(qmf, 64, &output); + const auto peak = std::max_element(output.begin(), output.end(), [](double left, double right) { + return std::abs(left) < std::abs(right); + }); + check(peak - output.begin() == RosellaFilterbank::kLatencySamples, "roundtrip latency"); + check(std::abs(*peak - 0.999989847495873) < 1e-10, "roundtrip gain"); +} + +} + +int main() { + test_reference_and_streaming(); + test_latency(); + std::printf("Rosella filterbank: %d failures\n", failures); + return failures == 0 ? 0 : 1; +}