Add --rosella-filterbank and restore the public bank as the default
ci / ubuntu-latest (push) Failing after 16s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s

The Rosella path picks its analysis and synthesis bank instead of
hard-coding one. Bank 1 is the shared public bank the renderer used
before the captured variant landed: 13-tap hybrid filters, the 6-slot
high-band delay and 961 samples of latency. Bank 2 is the captured
Rosella bank: 11-tap filters, the 3-slot delay and 448 samples. Both
keep their own coefficients, histories and flush behaviour.

- Drive either bank through one RosellaBank interface, and derive the
  startup skip and the flush capacity from the selected bank
- Add joc_rosella_filterbank to joc_task_config and joc_stream_config
  by replacing the reserved words (struct sizes unchanged, config
  version 3 -> 4)
- Reject an out-of-range value and bank 2 without a Rosella model
  instead of silently falling back
- Expose --rosella-filterbank 1|2 in the CLI with bank 1 as default,
  and reject it outside the personalized headphone path
- Cover bank identity, chunking, reset and per-bank latency in tests
- Document both banks, the selector and the CLI help

Renders of --rosella-filterbank 1 (and the default) match the pre-merge
reference byte for byte; --rosella-filterbank 2 matches the PR #3
reference byte for byte.
This commit is contained in:
TheM14 committed 2026-10-31 01:11:44 +08:00
1 parent 6674cb5386
commit 34a722f56a
19 files changed
+477 -34

No files matched your search

+31
View File
@@ -927,6 +927,36 @@ std::vector<float> drive_objects16_stream(const std::vector<float>& block, std::
return rendered;
}
void test_rosella_filterbank_config() {
// validate() reports a selector it cannot honour instead of ignoring it: the
// captured bank needs the Rosella model, and any other value is out of range.
const auto reported = [](std::uint32_t selector, const char* personalized) {
joc_task_config config{};
config.struct_size = sizeof(config);
config.struct_version = JOC_TASK_CONFIG_VERSION;
config.input_path = "input.eac3";
config.output_path = "output.wav";
config.operation = JOC_OP_BINAURAL;
config.binaural_mode = JOC_BINAURAL_MID;
config.personalized_headphone_path = personalized;
config.hrtf_path = personalized == nullptr ? "cache.jochrtf" : nullptr;
config.rosella_filterbank = selector;
std::vector<joc_validation_issue> issues;
std::uint32_t errors = 0;
joc::task::validate(config, &issues, &errors);
for (const joc_validation_issue& issue : issues) {
if (std::string(issue.field) == "rosella_filterbank") {
return true;
}
}
return false;
};
CHECK(!reported(JOC_ROSELLA_FILTERBANK_PUBLIC, "model.personalized_headphone"));
CHECK(!reported(JOC_ROSELLA_FILTERBANK_CAPTURED, "model.personalized_headphone"));
CHECK(reported(3u, "model.personalized_headphone"));
CHECK(reported(JOC_ROSELLA_FILTERBANK_CAPTURED, nullptr));
}
// A push renders every frame it makes ready, so the stream bounds how far ahead of
// the caller it renders. A batch pushed at once must therefore leave a bounded
// backlog, and it must render the same samples as pushing one frame at a time.
@@ -1126,6 +1156,7 @@ int main() {
test_sofa_reader_errors();
test_hrtf_cache_policy();
test_rosella_model_errors();
test_rosella_filterbank_config();
test_stream_render_ahead();
test_clipgain_first_frame_uses_its_own_gain();
test_clipgain_change_applies_to_the_current_frame();
+143
View File
@@ -1,8 +1,12 @@
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <vector>
#include "hrtf/public_filterbank.h"
#include "hrtf/rosella_bank.h"
#include "hrtf/rosella_filterbank.h"
#include "rosella_filterbank_vectors.h"
@@ -18,6 +22,9 @@ void check(bool passed, const char* name) {
}
using joc::hrtf::Complex;
using joc::hrtf::PublicFilterbank;
using joc::hrtf::RosellaBank;
using joc::hrtf::RosellaBankKind;
using joc::hrtf::RosellaFilterbank;
template <typename Value, typename Expected>
@@ -116,11 +123,147 @@ void test_latency() {
check(std::abs(*peak - 0.999989847495873) < 1e-10, "roundtrip gain");
}
// One pass of the four half-steps, split into the given slot counts; the
// concatenation is what a single call with the total count produces.
struct BankTrace {
std::vector<Complex> qmf;
std::vector<Complex> hybrid;
std::vector<Complex> folded;
std::vector<double> time;
};
BankTrace run_bank(RosellaBank& bank, const std::vector<double>& hops,
const std::vector<Complex>& synthetic, const std::vector<std::size_t>& chunks,
std::size_t channels) {
BankTrace trace;
std::size_t first = 0;
for (const std::size_t count : chunks) {
const std::vector<double> part_hops(hops.begin() + first * channels * 64,
hops.begin() + (first + count) * channels * 64);
const std::vector<Complex> part_synthetic(
synthetic.begin() + first * channels * 77,
synthetic.begin() + (first + count) * channels * 77);
std::vector<Complex> qmf, hybrid, folded;
std::vector<double> time;
bank.analyze_qmf(part_hops, count, &qmf);
bank.analyze_hybrid(qmf, count, &hybrid);
bank.synthesize_hybrid(part_synthetic, count, &folded);
bank.synthesize_qmf(folded, count, &time);
trace.qmf.insert(trace.qmf.end(), qmf.begin(), qmf.end());
trace.hybrid.insert(trace.hybrid.end(), hybrid.begin(), hybrid.end());
trace.folded.insert(trace.folded.end(), folded.begin(), folded.end());
trace.time.insert(trace.time.end(), time.begin(), time.end());
first += count;
}
return trace;
}
bool same_trace(const BankTrace& left, const BankTrace& right) {
return left.qmf == right.qmf && left.hybrid == right.hybrid &&
left.folded == right.folded && left.time == right.time;
}
void test_bank_selection() {
constexpr std::size_t slots = 24;
constexpr std::size_t channels = 2;
std::vector<double> hops(slots * channels * 64);
for (std::size_t index = 0; index < hops.size(); ++index) {
hops[index] = (static_cast<int>((index * 37 + 11) % 257) - 128) / 128.0;
}
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);
}
// The selector is only a choice of implementation: each kind must reproduce
// exactly what its own class computes, and the two banks must stay separate.
std::vector<Complex> public_hybrid;
std::vector<Complex> captured_hybrid;
for (const RosellaBankKind kind : {RosellaBankKind::Public, RosellaBankKind::Captured}) {
std::vector<Complex> direct_qmf, direct_hybrid;
if (kind == RosellaBankKind::Public) {
PublicFilterbank bank(joc::hrtf::builtin_kernels(), channels);
bank.analyze_qmf(hops, slots, &direct_qmf);
bank.analyze_hybrid(direct_qmf, slots, &direct_hybrid);
} else {
RosellaFilterbank bank(channels);
bank.analyze_qmf(hops, slots, &direct_qmf);
bank.analyze_hybrid(direct_qmf, slots, &direct_hybrid);
}
std::unique_ptr<RosellaBank> selected = RosellaBank::create(kind, channels);
std::vector<Complex> selected_qmf, selected_hybrid;
selected->analyze_qmf(hops, slots, &selected_qmf);
selected->analyze_hybrid(selected_qmf, slots, &selected_hybrid);
check(selected_qmf == direct_qmf, "selector analysis matches the bank");
check(selected_hybrid == direct_hybrid, "selector hybrid matches the bank");
if (kind == RosellaBankKind::Public) {
public_hybrid = selected_hybrid;
} else {
captured_hybrid = selected_hybrid;
}
BankTrace whole;
{
std::unique_ptr<RosellaBank> fresh = RosellaBank::create(kind, channels);
whole = run_bank(*fresh, hops, synthetic, {slots}, channels);
}
check(whole.qmf == selected_qmf, "whole chunk analysis");
check(whole.hybrid == selected_hybrid, "whole chunk hybrid");
for (int repeat = 0; repeat < 2; ++repeat) {
std::unique_ptr<RosellaBank> split = RosellaBank::create(kind, channels);
const BankTrace parts =
run_bank(*split, hops, synthetic, {0u, 5u, 0u, 7u, 12u}, channels);
check(same_trace(whole, parts), "chunk/reset invariance");
}
}
check(public_hybrid != captured_hybrid, "the two banks produce different hybrid data");
}
// Distance from the impulse to the absolute peak of the analysis/synthesis
// roundtrip, which is the latency the runtime skips at the head of the stream.
std::size_t roundtrip_peak(RosellaBank& bank, std::size_t slots) {
std::vector<double> impulse(slots * 64, 0.0);
impulse[0] = 1.0;
std::vector<Complex> qmf, hybrid;
std::vector<double> output;
bank.analyze_qmf(impulse, slots, &qmf);
bank.analyze_hybrid(qmf, slots, &hybrid);
bank.synthesize_hybrid(hybrid, slots, &qmf);
bank.synthesize_qmf(qmf, slots, &output);
const auto peak = std::max_element(output.begin(), output.end(), [](double left, double right) {
return std::abs(left) < std::abs(right);
});
return static_cast<std::size_t>(peak - output.begin());
}
void test_bank_latency_and_reset() {
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Public) ==
static_cast<std::uint32_t>(joc::hrtf::kLatencySamples),
"public latency is the public filterbank latency");
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Captured) ==
static_cast<std::uint32_t>(RosellaFilterbank::kLatencySamples),
"captured latency is the Rosella filterbank latency");
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Public) == 961u,
"public latency is 961 samples");
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Captured) == 448u,
"captured latency is 448 samples");
for (const RosellaBankKind kind : {RosellaBankKind::Public, RosellaBankKind::Captured}) {
std::unique_ptr<RosellaBank> bank = RosellaBank::create(kind, 1);
const std::size_t first = roundtrip_peak(*bank, 64);
check(first == joc::hrtf::rosella_bank_latency(kind), "bank roundtrip latency");
bank->reset();
check(roundtrip_peak(*bank, 64) == first, "bank reset restores the startup delay");
}
}
}
int main() {
test_reference_and_streaming();
test_latency();
test_bank_selection();
test_bank_latency_and_reset();
std::printf("Rosella filterbank: %d failures\n", failures);
return failures == 0 ? 0 : 1;
}