Skip to content

Commit

Permalink
Fix mac
Browse files Browse the repository at this point in the history
  • Loading branch information
louist103 committed Sep 25, 2024
1 parent 5bc564b commit f52df0f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 30 deletions.
105 changes: 75 additions & 30 deletions OTRExporter/AudioExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ void OTRExporter_Audio::WriteSampleEntry(SampleEntry* entry, BinaryWriter* write
writer->Write((entry->book.books[i]));
}



void OTRExporter_Audio::WriteSoundFontEntry(ZAudio* audio, SoundFontEntry* entry, std::map<uint32_t, SampleEntry*> samples, BinaryWriter* writer)
{
writer->Write((uint8_t)(entry != nullptr ? 1 : 0));

if (entry != nullptr)
{
writer->Write((uint8_t)(entry != nullptr ? 1 : 0));

writer->Write(GetSampleEntryReference(audio, entry->sampleEntry, samples));
writer->Write(entry->tuning);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ void OTRExporter_Audio::WriteEnvData(std::vector<AdsrEnvelope*> envelopes, Binar

void OTRExporter_Audio::WriteEnvData(std::vector<AdsrEnvelope*> envelopes, tinyxml2::XMLElement* xmlDoc) {
tinyxml2::XMLElement* envs = xmlDoc->InsertNewChildElement("Envelopes");
envs->SetAttribute("Count", envelopes.size());
envs->SetAttribute("Count", (uint32_t)envelopes.size());

for (auto e : envelopes) {
tinyxml2::XMLElement* env = envs->InsertNewChildElement("Envelope");
Expand All @@ -142,7 +142,7 @@ void OTRExporter_Audio::WriteSoundFontTableXML(ZAudio* audio) {
tinyxml2::XMLDocument soundFont;
tinyxml2::XMLElement* root = soundFont.NewElement("SoundFont");
root->SetAttribute("Version", 0);
root->SetAttribute("Num", i);
root->SetAttribute("Num", (uint32_t)i);
root->SetAttribute("Medium", GetMediumStr(audio->soundFontTable[i].medium));
root->SetAttribute("CachePolicy", GetCachePolicyStr(audio->soundFontTable[i].cachePolicy));
root->SetAttribute("Data1", audio->soundFontTable[i].data1);
Expand All @@ -151,7 +151,7 @@ void OTRExporter_Audio::WriteSoundFontTableXML(ZAudio* audio) {
soundFont.InsertFirstChild(root);

tinyxml2::XMLElement* drums = root->InsertNewChildElement("Drums");
drums->SetAttribute("Count", audio->soundFontTable[i].drums.size());
drums->SetAttribute("Count", (uint32_t)audio->soundFontTable[i].drums.size());

for (const auto& d : audio->soundFontTable[i].drums) {
tinyxml2::XMLElement* drum = drums->InsertNewChildElement("Drum");
Expand All @@ -167,7 +167,7 @@ void OTRExporter_Audio::WriteSoundFontTableXML(ZAudio* audio) {
root->InsertEndChild(drums);

tinyxml2::XMLElement* instruments = root->InsertNewChildElement("Instruments");
instruments->SetAttribute("Count", audio->soundFontTable[i].instruments.size());
instruments->SetAttribute("Count", (uint32_t)audio->soundFontTable[i].instruments.size());

//for (size_t k = 0; k < audio->soundFontTable[i].instruments.size(); k++) {
for (const auto i : audio->soundFontTable[i].instruments) {
Expand All @@ -188,7 +188,7 @@ void OTRExporter_Audio::WriteSoundFontTableXML(ZAudio* audio) {
root->InsertEndChild(instruments);

tinyxml2::XMLElement* sfxTbl = root->InsertNewChildElement("SfxTable");
sfxTbl->SetAttribute("Count", audio->soundFontTable[i].soundEffects.size());
sfxTbl->SetAttribute("Count", (uint32_t)audio->soundFontTable[i].soundEffects.size());

for (const auto s : audio->soundFontTable[i].soundEffects) {
WriteSoundFontEntry(audio, s, audio->samples, sfxTbl, "Sfx");
Expand Down Expand Up @@ -265,6 +265,72 @@ void OTRExporter_Audio::WriteSoundFontTableBinary(ZAudio* audio) {
}
}

void OTRExporter_Audio::WriteSequenceXML(ZAudio* audio) {
for (size_t i = 0; i < audio->sequences.size(); i++) {
MemoryStream* seqStream = new MemoryStream();
BinaryWriter seqWriter = BinaryWriter(seqStream);
auto& seq = audio->sequences[i];

tinyxml2::XMLDocument sequence;
tinyxml2::XMLElement* root = sequence.NewElement("Sequence");
root->SetAttribute("Index", (uint32_t)i);
root->SetAttribute("Medium", GetMediumStr(audio->sequenceTable[i].medium));
root->SetAttribute("CachePolicy", GetCachePolicyStr(audio->sequenceTable[i].cachePolicy));
root->SetAttribute("Size", (uint32_t)seq.size());

std::string seqName = OTRExporter_DisplayList::GetPathToRes(
(ZResource*)(audio), StringHelper::Sprintf("sequencedata/%s_RAW", audio->seqNames[i].c_str()));
root->SetAttribute("Path", seqName.c_str());


tinyxml2::XMLElement* fontIndicies = root->InsertNewChildElement("FontIndicies");
for (size_t k = 0; k < audio->fontIndices[i].size(); k++) {
tinyxml2::XMLElement* fontIndex = fontIndicies->InsertNewChildElement("FontIndex");
fontIndex->SetAttribute("FontIdx", audio->fontIndices[i][k]);

}
root->InsertEndChild(fontIndicies);
root->InsertEndChild(root);
sequence.InsertEndChild(root);
seqWriter.Write(seq.data(), seq.size());
AddFile(seqName, seqStream->ToVector());

tinyxml2::XMLPrinter printer;
sequence.Accept(&printer);


std::string seqMetaName = OTRExporter_DisplayList::GetPathToRes(
(ZResource*)(audio), StringHelper::Sprintf("sequences/%s_META", audio->seqNames[i].c_str()));
std::vector<char> xmlData((printer.CStr()), printer.CStr() + printer.CStrSize());
AddFile(seqMetaName, xmlData);
}
}

void OTRExporter_Audio::WriteSequenceBinary(ZAudio* audio) {
for (size_t i = 0; i < audio->sequences.size(); i++) {
auto& seq = audio->sequences[i];

MemoryStream* seqStream = new MemoryStream();
BinaryWriter seqWriter = BinaryWriter(seqStream);

WriteHeader(nullptr, "", &seqWriter, static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 2);

seqWriter.Write((uint32_t)seq.size());
seqWriter.Write(seq.data(), seq.size());
seqWriter.Write((uint8_t)i);
seqWriter.Write((uint8_t)audio->sequenceTable[i].medium);
seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy);
seqWriter.Write((uint32_t)audio->fontIndices[i].size());

for (size_t k = 0; k < audio->fontIndices[i].size(); k++)
seqWriter.Write((uint8_t)audio->fontIndices[i][k]);

std::string fName = OTRExporter_DisplayList::GetPathToRes(
(ZResource*)(audio), StringHelper::Sprintf("sequences/%s", audio->seqNames[i].c_str()));
AddFile(fName, seqStream->ToVector());
}
}

void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWriter* writer)
{
ZAudio* audio = (ZAudio*)res;
Expand Down Expand Up @@ -298,28 +364,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit

// Write the soundfont table
WriteSoundFontTableXML(audio);

// Write Sequences
for (size_t i = 0; i < audio->sequences.size(); i++)
{
auto seq = audio->sequences[i];

MemoryStream* seqStream = new MemoryStream();
BinaryWriter seqWriter = BinaryWriter(seqStream);

WriteHeader(nullptr, "", &seqWriter, static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 2);

seqWriter.Write((uint32_t)seq.size());
seqWriter.Write(seq.data(), seq.size());
seqWriter.Write((uint8_t)i);
seqWriter.Write((uint8_t)audio->sequenceTable[i].medium);
seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy);
seqWriter.Write((uint32_t)audio->fontIndices[i].size());

for (size_t k = 0; k < audio->fontIndices[i].size(); k++)
seqWriter.Write((uint8_t)audio->fontIndices[i][k]);

std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("sequences/%s", audio->seqNames[i].c_str()));
AddFile(fName, seqStream->ToVector());
}
WriteSequenceXML(audio);
}
2 changes: 2 additions & 0 deletions OTRExporter/AudioExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class OTRExporter_Audio : public OTRExporter
private:
void WriteSoundFontTableBinary(ZAudio* audio);
void WriteSoundFontTableXML(ZAudio* audio);
void WriteSequenceBinary(ZAudio* audio);
void WriteSequenceXML(ZAudio* audio);
std::string GetSampleEntryReference(ZAudio* audio, SampleEntry* entry, std::map<uint32_t, SampleEntry*> samples);
void WriteEnvData(std::vector<AdsrEnvelope*> envelopes, BinaryWriter* writer);
void WriteEnvData(std::vector<AdsrEnvelope*> envelopes, tinyxml2::XMLElement* xmlDoc);
Expand Down

0 comments on commit f52df0f

Please sign in to comment.