mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-22 16:18:50 -05:00
Updated sequence file format and updated resource version to Rachael
This commit is contained in:
parent
960a29e513
commit
bb6f5abbbf
@ -30,7 +30,7 @@ void OTRExporter_Audio::WriteSampleEntryReference(ZAudio* audio, SampleEntry* en
|
||||
|
||||
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->medium);
|
||||
@ -82,7 +82,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
|
||||
{
|
||||
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
|
||||
for (auto pair : audio->samples)
|
||||
@ -115,7 +115,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
|
||||
MemoryStream* fntStream = new MemoryStream();
|
||||
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(audio->soundFontTable[i].medium);
|
||||
@ -174,17 +174,18 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
|
||||
MemoryStream* seqStream = new MemoryStream();
|
||||
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)audio->sequenceTable[i].medium);
|
||||
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++)
|
||||
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()));
|
||||
AddFile(fName, seqStream->ToVector());
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "Exporter.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)0); // 0x01
|
||||
@ -9,7 +9,8 @@ void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWri
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
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((uint32_t)resourceVersions[resType]); // 0x10
|
||||
writer->Write((uint64_t)0); // ROM CRC, 0x14
|
||||
|
@ -4,9 +4,10 @@
|
||||
//#include "OTRExporter.h"
|
||||
#include <Utils/BinaryWriter.h>
|
||||
#include <Resource.h>
|
||||
#include "VersionInfo.h"
|
||||
|
||||
class OTRExporter : public ZResourceExporter
|
||||
{
|
||||
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);
|
||||
};
|
@ -2,7 +2,30 @@
|
||||
|
||||
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;
|
||||
|
||||
@ -36,7 +59,7 @@ namespace Ship
|
||||
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;
|
||||
|
||||
@ -137,7 +160,7 @@ namespace Ship
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<AdsrEnvelope*> AudioSoundFontV1::ReadEnvelopeData(BinaryReader* reader)
|
||||
std::vector<AdsrEnvelope*> AudioSoundFontV2::ReadEnvelopeData(BinaryReader* reader)
|
||||
{
|
||||
std::vector<AdsrEnvelope*> envelopes;
|
||||
|
||||
@ -155,7 +178,7 @@ namespace Ship
|
||||
return envelopes;
|
||||
}
|
||||
|
||||
void AudioV1::ParseFileBinary(BinaryReader* reader, Resource* res)
|
||||
void AudioV2::ParseFileBinary(BinaryReader* reader, Resource* res)
|
||||
{
|
||||
Audio* audio = (Audio*)res;
|
||||
|
||||
|
@ -57,26 +57,43 @@ namespace Ship
|
||||
SoundFontEntry* highNotesSound = nullptr;
|
||||
};
|
||||
|
||||
class AudioSoundFontV1 : public ResourceFile
|
||||
class AudioSequenceV2 : public ResourceFile
|
||||
{
|
||||
public:
|
||||
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
|
||||
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:
|
||||
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
|
||||
};
|
||||
|
||||
class AudioV1 : public ResourceFile
|
||||
class AudioV2 : public ResourceFile
|
||||
{
|
||||
public:
|
||||
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:
|
||||
uint32_t ptr;
|
||||
@ -110,10 +127,5 @@ namespace Ship
|
||||
class Audio : public Resource
|
||||
{
|
||||
public:
|
||||
//std::vector<AudioTableEntry> soundFontTable;
|
||||
//std::vector<AudioTableEntry> sequenceTable;
|
||||
//std::vector<AudioTableEntry> sampleBankTable;
|
||||
//std::vector<char*> sequences;
|
||||
//std::vector<SampleEntry*> samples;
|
||||
};
|
||||
}
|
@ -9,9 +9,9 @@ namespace Ship
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case Version::Roy:
|
||||
case Version::Rachael:
|
||||
{
|
||||
AudioV1 audioFac = AudioV1();
|
||||
AudioV2 audioFac = AudioV2();
|
||||
audioFac.ParseFileBinary(reader, audio);
|
||||
}
|
||||
break;
|
||||
@ -30,10 +30,9 @@ namespace Ship
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor
|
||||
case Version::Roy:
|
||||
case Version::Rachael:
|
||||
{
|
||||
AudioSampleV1 audioSampleFac = AudioSampleV1();
|
||||
AudioSampleV2 audioSampleFac = AudioSampleV2();
|
||||
audioSampleFac.ParseFileBinary(reader, audioSample);
|
||||
}
|
||||
break;
|
||||
@ -52,10 +51,9 @@ namespace Ship
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor
|
||||
case Version::Roy:
|
||||
case Version::Rachael:
|
||||
{
|
||||
AudioSoundFontV1 audioSFFac = AudioSoundFontV1();
|
||||
AudioSoundFontV2 audioSFFac = AudioSoundFontV2();
|
||||
audioSFFac.ParseFileBinary(reader, audioSF);
|
||||
}
|
||||
break;
|
||||
@ -66,4 +64,25 @@ namespace Ship
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
@ -20,4 +20,10 @@ namespace Ship
|
||||
public:
|
||||
static AudioSoundFont* ReadAudioSoundFont(BinaryReader* reader);
|
||||
};
|
||||
|
||||
class AudioSequenceFactory
|
||||
{
|
||||
public:
|
||||
static AudioSequence* ReadAudioSequence(BinaryReader* reader);
|
||||
};
|
||||
}
|
@ -94,6 +94,9 @@ namespace Ship
|
||||
case ResourceType::AudioSoundFont:
|
||||
result = AudioSoundFontFactory::ReadAudioSoundFont(reader.get());
|
||||
break;
|
||||
case ResourceType::AudioSequence:
|
||||
result = AudioSequenceFactory::ReadAudioSequence(reader.get());
|
||||
break;
|
||||
default:
|
||||
// RESOURCE TYPE NOT SUPPORTED
|
||||
break;
|
||||
|
@ -33,6 +33,7 @@ namespace Ship
|
||||
Audio = 'OAUD',
|
||||
AudioSample = 'OSMP',
|
||||
AudioSoundFont = 'OSFT',
|
||||
AudioSequence = 'OSEQ',
|
||||
};
|
||||
|
||||
enum class DataType
|
||||
|
@ -569,21 +569,20 @@ extern "C" Vtx* ResourceMgr_LoadVtxByName(const char* path)
|
||||
|
||||
extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path)
|
||||
{
|
||||
auto file = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(path).get();
|
||||
|
||||
char* data = file->buffer.get();
|
||||
auto file = std::static_pointer_cast<Ship::AudioSequence>(OTRGlobals::Instance->context->GetResourceManager()
|
||||
->LoadResource(path));
|
||||
|
||||
SequenceData seqData;
|
||||
seqData.seqNumber = data[1];
|
||||
seqData.medium = data[2];
|
||||
seqData.cachePolicy = data[3];
|
||||
seqData.numFonts = data[4];
|
||||
seqData.seqNumber = file->seqNumber;
|
||||
seqData.medium = file->medium;
|
||||
seqData.cachePolicy = file->cachePolicy;
|
||||
seqData.numFonts = file->fonts.size();
|
||||
|
||||
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.seqDataSize = file->dwBufferSize - 5 - seqData.numFonts;
|
||||
seqData.seqData = file->seqData.data();
|
||||
seqData.seqDataSize = file->seqData.size();
|
||||
|
||||
return seqData;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user