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
This commit is contained in:
yuygfgg committed 2026-10-30 17:46:18 +08:00
1 parent 8e688d496e
commit 188a066642
10 files changed
+899 -18

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
#pragma once
#include <array>
#include <complex>
#include <cstddef>
namespace rosella_test_vectors {
struct ComplexSample {
std::size_t index;
std::complex<double> value;
};
struct RealSample {
std::size_t index;
double value;
};
inline const std::array<ComplexSample, 45> 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<ComplexSample, 45> 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<ComplexSample, 45> 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<RealSample, 45> 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},
}};
}
+126
View File
@@ -0,0 +1,126 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#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 <typename Value, typename Expected>
void check_samples(const std::vector<Value>& 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<double> input(slots * channels * 64);
for (std::size_t index = 0; index < input.size(); ++index) {
input[index] = (static_cast<int>((index * 37 + 11) % 257) - 128) / 128.0;
}
RosellaFilterbank bank(channels);
std::vector<Complex> qmf, hybrid, folded;
std::vector<double> 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<Complex> synthetic(slots * channels * 77);
for (std::size_t index = 0; index < synthetic.size(); ++index) {
synthetic[index] = Complex((static_cast<int>((index * 17 + 3) % 101) - 50) / 64.0,
(static_cast<int>((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<Complex> joined_qmf, joined_hybrid, joined_folded;
std::vector<double> joined_time;
std::size_t first = 0;
for (const std::size_t count : {0u, 1u, 7u, 0u, 3u, 13u}) {
std::vector<double> part_input(input.begin() + first * channels * 64,
input.begin() + (first + count) * channels * 64);
std::vector<Complex> part_synthetic(synthetic.begin() + first * channels * 77,
synthetic.begin() +
(first + count) * channels * 77);
std::vector<Complex> part_qmf, part_hybrid, part_folded;
std::vector<double> 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<double> 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<Complex> 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<double> impulse(64 * 64);
impulse[0] = 1.0;
std::vector<Complex> qmf, hybrid;
std::vector<double> 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;
}