diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2026-05-11 18:04:28 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2026-05-11 18:04:28 -0600 |
| commit | 54fb665402f2dd5f145f8b3ecb4bed0218709a9e (patch) | |
| tree | a7471b85e4e46a8dabf075dfd279f353ef635687 | |
| parent | 9b3eef94e58065273d17a802ac26e13ffa49a19f (diff) | |
Fixed yaml entries from audio not getting generated
| -rw-r--r-- | src/factories/naudio/v1/AudioTableFactory.cpp | 22 | ||||
| -rw-r--r-- | src/factories/naudio/v1/SampleFactory.cpp | 10 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/factories/naudio/v1/AudioTableFactory.cpp b/src/factories/naudio/v1/AudioTableFactory.cpp index cc6386f..72f1f65 100644 --- a/src/factories/naudio/v1/AudioTableFactory.cpp +++ b/src/factories/naudio/v1/AudioTableFactory.cpp @@ -133,6 +133,28 @@ std::optional<std::shared_ptr<IParsedData>> AudioTableFactory::parse(std::vector SPDLOG_INFO("medium: {}", bmedium); SPDLOG_INFO("addr: {}", baddr); + // Before the SoundFont cascade begins, pre-populate sampleDedup with every + // explicitly-declared NAUDIO:V1:SAMPLE entry so that auto-generated + // duplicates (same bankId + sampleAddr, different parent) are suppressed + // and don't shadow the explicit canonical entries. + if (type == AudioTableType::FONT_TABLE) { + auto explicitSamples = Companion::Instance->GetNodesByType("NAUDIO:V1:SAMPLE"); + if (explicitSamples.has_value()) { + for (auto& [path, node] : explicitSamples.value()) { + auto sampleOffset = GetSafeNode<uint32_t>(node, "offset"); + auto sampleBankId = GetSafeNode<uint32_t>(node, "sampleBankId"); + // Read physical sampleAddr (second u32 in the Sample struct) from + // the font-table buffer. flags is first, sampleAddr is second. + auto sReader = AudioContext::MakeReader(AudioTableType::FONT_TABLE, sampleOffset); + sReader.ReadUInt32(); // skip flags + uint32_t sampleAddr = sReader.ReadUInt32(); + if (sampleAddr == 0) continue; + uint64_t key = ((uint64_t)sampleBankId << 32) | (uint64_t)sampleAddr; + AudioContext::sampleDedup[key] = path; + } + } + } + std::vector<AudioTableEntry> entries; for (size_t i = 0; i < count; i++) { diff --git a/src/factories/naudio/v1/SampleFactory.cpp b/src/factories/naudio/v1/SampleFactory.cpp index 4616d3f..47f971f 100644 --- a/src/factories/naudio/v1/SampleFactory.cpp +++ b/src/factories/naudio/v1/SampleFactory.cpp @@ -194,6 +194,10 @@ std::optional<std::shared_ptr<IParsedData>> NSampleFactory::parse(std::vector<ui // Build dedup maps at parse time so GetPathByAddr() has full information // before any instrument/drum export runs. if (addr != 0) { + // Explicit YAML entries (autogen == false) are always canonical — they were + // pre-registered in sampleDedup by AudioTableFactory before the cascade. + // Only auto-generated entries should be suppressed as duplicates. + bool isAutogen = GetSafeNode<bool>(node, "autogen", false); uint64_t key = ((uint64_t)sampleBankId << 32) | (uint64_t)addr; auto it = AudioContext::sampleDedup.find(key); if (it == AudioContext::sampleDedup.end()) { @@ -202,12 +206,12 @@ std::optional<std::shared_ptr<IParsedData>> NSampleFactory::parse(std::vector<ui if (pathDec.has_value()) { AudioContext::sampleDedup[key] = std::get<0>(pathDec.value()); } - } else { - // Duplicate: map this ROM offset → canonical path for GetPathByAddr(), - // then return nullopt so the Companion produces no archive entry for it. + } else if (isAutogen) { + // Auto-generated duplicate: redirect to canonical, suppress export. AudioContext::sampleAddrRemap[offset] = it->second; return std::nullopt; } + // Explicit entries fall through — always exported with their declared name. } return sample; |
