Test audio xmls

This commit is contained in:
KiritoDv
2024-11-27 21:25:49 -06:00
parent 714b555d13
commit ac3f20a78c
5 changed files with 74 additions and 7 deletions
+1 -4
View File
@@ -1230,9 +1230,7 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::RegisterAsset(cons
auto entry = std::make_tuple(output, node);
this->gAddrMap[this->gCurrentFile][node["offset"].as<uint32_t>()] = entry;
return entry;
}
@@ -1418,7 +1416,6 @@ std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) {
const auto symbol = GetSafeNode<std::string>(asset, "symbol", "");
const auto decl = this->GetNodeByAddr(offset);
if(decl.has_value()) {
return std::get<1>(decl.value());
}
+2 -1
View File
@@ -62,8 +62,9 @@ TunedSample AudioContext::LoadTunedSample(LUS::BinaryReader& reader, uint32_t pa
node["parent"] = parent;
node["offset"] = parent + sampleAddr;
node["tuning"] = tuning;
SPDLOG_INFO("Tuning {}", tuning);
node["sampleBankId"] = sampleBankId;
node["symbol"] = StringHelper::Sprintf("%d_Sample_P_%X_B_%d", parent + sampleAddr, parent, sampleBankId);
// node["symbol"] = StringHelper::Sprintf("%d_Sample_P_%X_B_%d", parent + sampleAddr, parent, sampleBankId);
Companion::Instance->AddAsset(node);
return { parent + sampleAddr, sampleBankId, tuning };
@@ -1,6 +1,9 @@
#include "InstrumentFactory.h"
#include "utils/Decompressor.h"
#include "Companion.h"
#include "EnvelopeFactory.h"
#include "SampleFactory.h"
#include <tinyxml2.h>
ExportResult InstrumentHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
const auto symbol = GetSafeNode(node, "symbol", entryName);
@@ -40,6 +43,67 @@ ExportResult InstrumentBinaryExporter::Export(std::ostream &write, std::shared_p
return std::nullopt;
}
ExportResult InstrumentXMLExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
auto instrument = std::static_pointer_cast<InstrumentData>(raw);
auto envelopeData = std::static_pointer_cast<EnvelopeData>(Companion::Instance->GetParseDataByAddr(instrument->envelope)->data.value());
auto path = fs::path(*replacement);
*replacement += ".meta";
tinyxml2::XMLDocument inst;
tinyxml2::XMLElement* root = inst.NewElement("Instrument");
root->SetAttribute("NormalRangeLo", instrument->normalRangeLo);
root->SetAttribute("NormalRangeHi", instrument->normalRangeLo);
root->SetAttribute("ReleaseRate", instrument->adsrDecayIndex);
tinyxml2::XMLElement* envelopes = inst.NewElement("Envelopes");
for(auto& point : envelopeData->points){
tinyxml2::XMLElement* pointEntry = envelopes->InsertNewChildElement("Point");
pointEntry->SetAttribute("Delay", point.delay);
pointEntry->SetAttribute("Arg", point.arg);
envelopes->InsertEndChild(pointEntry);
}
auto lowSample = instrument->lowPitchTunedSample;
auto normSample = instrument->normalPitchTunedSample;
auto highSample = instrument->highPitchTunedSample;
if(lowSample.sample != 0 && lowSample.tuning != 0.0f){
tinyxml2::XMLElement* low = inst.NewElement("LowPitchSample");
low->SetAttribute("Tuning", lowSample.tuning);
low->SetAttribute("Path", std::get<std::string>(Companion::Instance->GetNodeByAddr(lowSample.sample).value()).c_str());
root->InsertEndChild(low);
}
if(normSample.sample != 0 && normSample.tuning != 0.0f) {
tinyxml2::XMLElement* normal = inst.NewElement("NormalPitchSample");
normal->SetAttribute("Tuning", normSample.tuning);
normal->SetAttribute("Path", std::get<std::string>(Companion::Instance->GetNodeByAddr(normSample.sample).value()).c_str());
root->InsertEndChild(normal);
}
if(highSample.sample != 0 && highSample.tuning != 0.0f) {
tinyxml2::XMLElement* high = inst.NewElement("HighPitchSample");
high->SetAttribute("Tuning", highSample.tuning);
high->SetAttribute("Path", std::get<std::string>(Companion::Instance->GetNodeByAddr(highSample.sample).value()).c_str());
root->InsertEndChild(high);
}
inst.InsertEndChild(root);
tinyxml2::XMLPrinter printer;
inst.Accept(&printer);
write.write(printer.CStr(), printer.CStrSize() - 1);
return std::nullopt;
}
std::optional<std::shared_ptr<IParsedData>> InstrumentFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
auto offset = GetSafeNode<uint32_t>(node, "offset");
auto parent = GetSafeNode<uint32_t>(node, "parent");
@@ -27,6 +27,10 @@ class InstrumentCodeExporter : public BaseExporter {
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class InstrumentXMLExporter : public BaseExporter {
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class InstrumentFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
@@ -35,6 +39,7 @@ public:
REGISTER(Header, InstrumentHeaderExporter)
REGISTER(Binary, InstrumentBinaryExporter)
REGISTER(Code, InstrumentCodeExporter)
REGISTER(XML, InstrumentXMLExporter)
};
}
+2 -2
View File
@@ -76,7 +76,7 @@ ExportResult NSampleXMLExporter::Export(std::ostream &write, std::shared_ptr<IPa
root->SetAttribute("Codec", AudioContext::GetCodecStr(entry->codec));
root->SetAttribute("Medium", AudioContext::GetMediumStr(entry->medium));
root->SetAttribute("Unk", entry->unk);
// root->SetAttribute("Relocated", entry->isRelocated);
root->SetAttribute("Tuning", entry->tuning);
tinyxml2::XMLElement* adpcmLoop = sample.NewElement("ADPCMLoop");
adpcmLoop->SetAttribute("Start", loop->start);
@@ -119,7 +119,7 @@ ExportResult NSampleXMLExporter::Export(std::ostream &write, std::shared_ptr<IPa
std::optional<std::shared_ptr<IParsedData>> NSampleFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
auto offset = GetSafeNode<uint32_t>(node, "offset");
auto parent = GetSafeNode<uint32_t>(node, "parent");
auto tuning = GetSafeNode<float>(node, "tuning", 1.0f);
auto tuning = GetSafeNode<float>(node, "tuning", 0.0f);
auto sampleRate = GetSafeNode<uint32_t>(node, "sampleRate", 0);
auto sampleBankId = GetSafeNode<uint32_t>(node, "sampleBankId");