Updated sequence file format and updated resource version to Rachael

This commit is contained in:
Nicholas Estelami 2022-06-15 12:22:21 -04:00
parent 510a38a6bc
commit dcb1b59c1b
10 changed files with 107 additions and 41 deletions

View File

@ -30,7 +30,7 @@ void OTRExporter_Audio::WriteSampleEntryReference(ZAudio* audio, SampleEntry* en
void OTRExporter_Audio::WriteSampleEntry(SampleEntry* entry, BinaryWriter* writer) void OTRExporter_Audio::WriteSampleEntry(SampleEntry* entry, BinaryWriter* writer)
{ {
WriteHeader(nullptr, "", writer, Ship::ResourceType::AudioSample); WriteHeader(nullptr, "", writer, Ship::ResourceType::AudioSample, Ship::Version::Rachael);
writer->Write(entry->codec); writer->Write(entry->codec);
writer->Write(entry->medium); writer->Write(entry->medium);
@ -82,7 +82,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
{ {
ZAudio* audio = (ZAudio*)res; ZAudio* audio = (ZAudio*)res;
WriteHeader(res, outPath, writer, Ship::ResourceType::Audio); WriteHeader(res, outPath, writer, Ship::ResourceType::Audio, Ship::Version::Rachael);
// Write Samples as individual files // Write Samples as individual files
for (auto pair : audio->samples) for (auto pair : audio->samples)
@ -115,7 +115,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
MemoryStream* fntStream = new MemoryStream(); MemoryStream* fntStream = new MemoryStream();
BinaryWriter fntWriter = BinaryWriter(fntStream); BinaryWriter fntWriter = BinaryWriter(fntStream);
WriteHeader(nullptr, "", &fntWriter, Ship::ResourceType::AudioSoundFont); WriteHeader(nullptr, "", &fntWriter, Ship::ResourceType::AudioSoundFont, Ship::Version::Rachael);
fntWriter.Write((uint32_t)i); fntWriter.Write((uint32_t)i);
fntWriter.Write(audio->soundFontTable[i].medium); fntWriter.Write(audio->soundFontTable[i].medium);
@ -174,17 +174,18 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
MemoryStream* seqStream = new MemoryStream(); MemoryStream* seqStream = new MemoryStream();
BinaryWriter seqWriter = BinaryWriter(seqStream); BinaryWriter seqWriter = BinaryWriter(seqStream);
seqWriter.Write((uint8_t)0); // Version 0 of format... WriteHeader(nullptr, "", &seqWriter, Ship::ResourceType::AudioSequence, Ship::Version::Rachael);
seqWriter.Write((uint32_t)seq.size());
seqWriter.Write(seq.data(), seq.size());
seqWriter.Write((uint8_t)i); seqWriter.Write((uint8_t)i);
seqWriter.Write((uint8_t)audio->sequenceTable[i].medium); seqWriter.Write((uint8_t)audio->sequenceTable[i].medium);
seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy); seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy);
seqWriter.Write((uint8_t)audio->fontIndices[i].size()); seqWriter.Write((uint32_t)audio->fontIndices[i].size());
for (int k = 0; k < audio->fontIndices[i].size(); k++) for (int k = 0; k < audio->fontIndices[i].size(); k++)
seqWriter.Write((uint8_t)audio->fontIndices[i][k]); seqWriter.Write((uint8_t)audio->fontIndices[i][k]);
seqWriter.Write(seq.data(), seq.size());
std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("sequences/%s", audio->seqNames[i].c_str())); std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("sequences/%s", audio->seqNames[i].c_str()));
AddFile(fName, seqStream->ToVector()); AddFile(fName, seqStream->ToVector());
} }

View File

@ -1,7 +1,7 @@
#include "Exporter.h" #include "Exporter.h"
#include "VersionInfo.h" #include "VersionInfo.h"
void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType) void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType, Ship::Version resVersion)
{ {
writer->Write((uint8_t)Endianess::Little); // 0x00 writer->Write((uint8_t)Endianess::Little); // 0x00
writer->Write((uint8_t)0); // 0x01 writer->Write((uint8_t)0); // 0x01
@ -9,7 +9,8 @@ void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWri
writer->Write((uint8_t)0); // 0x03 writer->Write((uint8_t)0); // 0x03
writer->Write((uint32_t)resType); // 0x04 writer->Write((uint32_t)resType); // 0x04
writer->Write((uint32_t)MAJOR_VERSION); // 0x08 //writer->Write((uint32_t)MAJOR_VERSION); // 0x08
writer->Write((uint32_t)resVersion); // 0x08
writer->Write((uint64_t)0xDEADBEEFDEADBEEF); // id, 0x0C writer->Write((uint64_t)0xDEADBEEFDEADBEEF); // id, 0x0C
writer->Write((uint32_t)resourceVersions[resType]); // 0x10 writer->Write((uint32_t)resourceVersions[resType]); // 0x10
writer->Write((uint64_t)0); // ROM CRC, 0x14 writer->Write((uint64_t)0); // ROM CRC, 0x14

View File

@ -4,9 +4,10 @@
//#include "OTRExporter.h" //#include "OTRExporter.h"
#include <Utils/BinaryWriter.h> #include <Utils/BinaryWriter.h>
#include <Resource.h> #include <Resource.h>
#include "VersionInfo.h"
class OTRExporter : public ZResourceExporter class OTRExporter : public ZResourceExporter
{ {
protected: protected:
static void WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType); static void WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType, Ship::Version resVersion = MAJOR_VERSION);
}; };

View File

@ -2,7 +2,30 @@
namespace Ship namespace Ship
{ {
void AudioSampleV1::ParseFileBinary(BinaryReader* reader, Resource* res) void AudioSequenceV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{
AudioSequence* seq = (AudioSequence*)res;
ResourceFile::ParseFileBinary(reader, res);
int seqDataSize = reader->ReadInt32();
seq->seqData.reserve(seqDataSize);
for (int i = 0; i < seqDataSize; i++)
seq->seqData.push_back(reader->ReadUByte());
seq->seqNumber = reader->ReadUByte();
seq->medium = reader->ReadUByte();
seq->cachePolicy = reader->ReadUByte();
int numFonts = reader->ReadInt32();
for (int i = 0; i < numFonts; i++)
seq->fonts.push_back(reader->ReadUByte());
}
void AudioSampleV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{ {
AudioSample* entry = (AudioSample*)res; AudioSample* entry = (AudioSample*)res;
@ -36,7 +59,7 @@ namespace Ship
entry->book.books.push_back(reader->ReadInt16()); entry->book.books.push_back(reader->ReadInt16());
} }
void AudioSoundFontV1::ParseFileBinary(BinaryReader* reader, Resource* res) void AudioSoundFontV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{ {
AudioSoundFont* soundFont = (AudioSoundFont*)res; AudioSoundFont* soundFont = (AudioSoundFont*)res;
@ -137,7 +160,7 @@ namespace Ship
} }
} }
std::vector<AdsrEnvelope*> AudioSoundFontV1::ReadEnvelopeData(BinaryReader* reader) std::vector<AdsrEnvelope*> AudioSoundFontV2::ReadEnvelopeData(BinaryReader* reader)
{ {
std::vector<AdsrEnvelope*> envelopes; std::vector<AdsrEnvelope*> envelopes;
@ -155,7 +178,7 @@ namespace Ship
return envelopes; return envelopes;
} }
void AudioV1::ParseFileBinary(BinaryReader* reader, Resource* res) void AudioV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{ {
Audio* audio = (Audio*)res; Audio* audio = (Audio*)res;

View File

@ -57,26 +57,43 @@ namespace Ship
SoundFontEntry* highNotesSound = nullptr; SoundFontEntry* highNotesSound = nullptr;
}; };
class AudioSoundFontV1 : public ResourceFile class AudioSequenceV2 : public ResourceFile
{ {
public: public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override; void ParseFileBinary(BinaryReader* reader, Resource* res) override;
static std::vector<AdsrEnvelope*> ReadEnvelopeData(BinaryReader* reader); static std::vector<AdsrEnvelope*> ReadEnvelopeData(BinaryReader* reader);
}; };
class AudioSampleV1 : public ResourceFile class AudioSoundFontV2 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
static std::vector<AdsrEnvelope*> ReadEnvelopeData(BinaryReader* reader);
};
class AudioSampleV2 : public ResourceFile
{ {
public: public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override; void ParseFileBinary(BinaryReader* reader, Resource* res) override;
}; };
class AudioV1 : public ResourceFile class AudioV2 : public ResourceFile
{ {
public: public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override; void ParseFileBinary(BinaryReader* reader, Resource* res) override;
}; };
struct AudioSoundFont : public Resource class AudioSequence : public Resource
{
public:
std::vector<char> seqData;
uint8_t seqNumber;
uint8_t medium;
uint8_t cachePolicy;
std::vector<uint8_t> fonts;
};
class AudioSoundFont : public Resource
{ {
public: public:
uint32_t ptr; uint32_t ptr;
@ -110,10 +127,5 @@ namespace Ship
class Audio : public Resource class Audio : public Resource
{ {
public: public:
//std::vector<AudioTableEntry> soundFontTable;
//std::vector<AudioTableEntry> sequenceTable;
//std::vector<AudioTableEntry> sampleBankTable;
//std::vector<char*> sequences;
//std::vector<SampleEntry*> samples;
}; };
} }

View File

@ -9,9 +9,9 @@ namespace Ship
switch (version) switch (version)
{ {
case Version::Roy: case Version::Rachael:
{ {
AudioV1 audioFac = AudioV1(); AudioV2 audioFac = AudioV2();
audioFac.ParseFileBinary(reader, audio); audioFac.ParseFileBinary(reader, audio);
} }
break; break;
@ -30,10 +30,9 @@ namespace Ship
switch (version) switch (version)
{ {
case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor case Version::Rachael:
case Version::Roy:
{ {
AudioSampleV1 audioSampleFac = AudioSampleV1(); AudioSampleV2 audioSampleFac = AudioSampleV2();
audioSampleFac.ParseFileBinary(reader, audioSample); audioSampleFac.ParseFileBinary(reader, audioSample);
} }
break; break;
@ -52,10 +51,9 @@ namespace Ship
switch (version) switch (version)
{ {
case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor case Version::Rachael:
case Version::Roy:
{ {
AudioSoundFontV1 audioSFFac = AudioSoundFontV1(); AudioSoundFontV2 audioSFFac = AudioSoundFontV2();
audioSFFac.ParseFileBinary(reader, audioSF); audioSFFac.ParseFileBinary(reader, audioSF);
} }
break; break;
@ -66,4 +64,25 @@ namespace Ship
return audioSF; return audioSF;
} }
AudioSequence* AudioSequenceFactory::ReadAudioSequence(BinaryReader* reader)
{
AudioSequence* audioSeq = new AudioSequence();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Rachael:
{
AudioSequenceV2 audioSeqFac = AudioSequenceV2();
audioSeqFac.ParseFileBinary(reader, audioSeq);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return audioSeq;
}
}; };

View File

@ -20,4 +20,10 @@ namespace Ship
public: public:
static AudioSoundFont* ReadAudioSoundFont(BinaryReader* reader); static AudioSoundFont* ReadAudioSoundFont(BinaryReader* reader);
}; };
class AudioSequenceFactory
{
public:
static AudioSequence* ReadAudioSequence(BinaryReader* reader);
};
} }

View File

@ -94,6 +94,9 @@ namespace Ship
case ResourceType::AudioSoundFont: case ResourceType::AudioSoundFont:
result = AudioSoundFontFactory::ReadAudioSoundFont(reader.get()); result = AudioSoundFontFactory::ReadAudioSoundFont(reader.get());
break; break;
case ResourceType::AudioSequence:
result = AudioSequenceFactory::ReadAudioSequence(reader.get());
break;
default: default:
// RESOURCE TYPE NOT SUPPORTED // RESOURCE TYPE NOT SUPPORTED
break; break;

View File

@ -33,6 +33,7 @@ namespace Ship
Audio = 'OAUD', Audio = 'OAUD',
AudioSample = 'OSMP', AudioSample = 'OSMP',
AudioSoundFont = 'OSFT', AudioSoundFont = 'OSFT',
AudioSequence = 'OSEQ',
}; };
enum class DataType enum class DataType

View File

@ -569,21 +569,20 @@ extern "C" Vtx* ResourceMgr_LoadVtxByName(const char* path)
extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path)
{ {
auto file = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(path).get(); auto file = std::static_pointer_cast<Ship::AudioSequence>(OTRGlobals::Instance->context->GetResourceManager()
->LoadResource(path));
char* data = file->buffer.get();
SequenceData seqData; SequenceData seqData;
seqData.seqNumber = data[1]; seqData.seqNumber = file->seqNumber;
seqData.medium = data[2]; seqData.medium = file->medium;
seqData.cachePolicy = data[3]; seqData.cachePolicy = file->cachePolicy;
seqData.numFonts = data[4]; seqData.numFonts = file->fonts.size();
for (int i = 0; i < seqData.numFonts; i++) for (int i = 0; i < seqData.numFonts; i++)
seqData.fonts[i] = data[5 + i]; seqData.fonts[i] = file->fonts[i];
seqData.seqData = &data[5 + seqData.numFonts]; seqData.seqData = file->seqData.data();
seqData.seqDataSize = file->dwBufferSize - 5 - seqData.numFonts; seqData.seqDataSize = file->seqData.size();
return seqData; return seqData;
} }