Shipwright/libultraship/libultraship/Audio.cpp
Christopher Leggett 7b08f98b8c
Dual OTR MQ and Vanilla Support (#1694)
* Changes OTR Extraction to have specific mq and nonmq paths.

Also updates the game to load resources according to whether or not
Master Quest or Vanilla is loaded.

* Removes unneeded code from the last commit.

* Fixes some weird formatting in ZRom.c

* Loads oot-mq.otr and patches oot.otr on top, if both are present.

If only one or the other are present, it becomes the only and main OTR.

* Adds ImGui Logic for whether or an MQ Checkbox.

Checkbox checked only specifies whether new saves should be MQ or not.
Checkbox is disabled or force-enabled according to which OTRs are loaded.
Also as a necessity includes tracking what game versions have been loaded
from the OTRs.

* Adds MQ settings logic for Randomizer's ImGui menu.

* Writes Master Quest dungeons to the spoiler log

* Loads MQ Dungeons from spoiler, persists in save, and loads when appropriate.

* Adds logic to prevent loading or creating incompatible rando saves.

* Fixdes some linux build issues and new rando save issues

* Makes appimage create both vanilla and mq otrs

If either rom is present, it makes the corresponding OTR. If both are present,
it will make both. If one OTR is present but both roms are present, it will
create the missing OTR.

* Makes it so a randomized save file will not be marked as MQ.

* Refactors to load all OTRs from MainPath or a specific list.

Also adds the ability to take a std::unordered_set of hashes to
validate each OTR's version file against.

* Fixes a syntax error

* Makes ExtractAssets output Vanilla and MQ OTRs if both roms are present

* Fixes asset generation bug.

* Partially working fix for dual OTR extract_assets

Currently the cmake ExtractAssets target will return with a 1 if you
only end up exporting one type of OTR isntead of both. Haven't found
a great way to only attempt to copy a file if it exists from within
cmake. It does actually correctly copy the OTR that is generated,
despite the error from copying the other one.

Pushing as is for now but will keep investigating.

* Adds oot-mq.otr to the gitignore.

* Makes ExtractAssets not fail on only one rom/OTR.

* Removes PatchesPath from the constructors requiring OTRFiles vector.

* Renames OOT_UNKNOWN to just UNKNOWN to remove OOT specific reference.

* Removes randomizing MQ Dungeons and re-disables MQ rando.

Doing this so the PR can get merged quicker with just the Dual OTR
support and won't need to wait on rando logic to be updated. That
will happen in another PR directly after the merge.

* Update mac startup script for dual otr

* Update soh/macosx/soh-macos.sh

* Update soh/macosx/soh-macos.sh

* Update soh/macosx/soh-macos.sh

* Implements new BinaryReader to fix Linux build issue.

BinaryReader itself comes from https://github.com/Moneyl/BinaryTools
I added a wrapper to adapt it to the ABI from ZAPD's Binary Reader and
add Endianness checking. I also had to copy a handful of other bits and
pieces from ZAPD to make it all function as expected.

* A few edits to the updatream BinaryReader to compile it on Linux.

* Adds the Endianness to the first byte of the version file.

* Fixes Jenkins

* Addresses some of Kenix's comments

* Renames `ReadNullTerminatedString` to `ReadCString`

* Refactors Archive::LoadFile into a private method with more arguments.

* Removes BitConverter and extends existing endianness.h instead.

* Fixes an endianness issue with the version file.

Co-authored-by: Garrett Cox <garrettjcox@gmail.com>
2022-10-16 23:07:35 -04:00

188 lines
4.7 KiB
C++

#include "Audio.h"
namespace Ship
{
void AudioSequenceV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{
AudioSequence* seq = (AudioSequence*)res;
ResourceFile::ParseFileBinary(reader, res);
uint32_t seqDataSize = reader->ReadInt32();
seq->seqData.reserve(seqDataSize);
for (uint32_t i = 0; i < seqDataSize; i++)
seq->seqData.push_back(reader->ReadUByte());
seq->seqNumber = reader->ReadUByte();
seq->medium = reader->ReadUByte();
seq->cachePolicy = reader->ReadUByte();
uint32_t numFonts = reader->ReadInt32();
for (uint32_t i = 0; i < numFonts; i++)
seq->fonts.push_back(reader->ReadUByte());
}
void AudioSampleV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{
AudioSample* entry = (AudioSample*)res;
ResourceFile::ParseFileBinary(reader, res);
entry->codec = reader->ReadInt8();
entry->medium = reader->ReadInt8();
entry->unk_bit26 = reader->ReadInt8();
entry->unk_bit25 = reader->ReadInt8();
uint32_t dataSize = reader->ReadInt32();
for (uint32_t i = 0; i < dataSize; i++)
entry->data.push_back(reader->ReadUByte());
entry->loop.start = reader->ReadUInt32();
entry->loop.end = reader->ReadUInt32();
entry->loop.count = reader->ReadUInt32();
uint32_t loopStateCnt = reader->ReadUInt32();
for (uint32_t i = 0; i < loopStateCnt; i++)
entry->loop.states.push_back(reader->ReadInt16());
entry->book.order = reader->ReadInt32();
entry->book.npredictors = reader->ReadInt32();
uint32_t bookSize = reader->ReadInt32();
for (uint32_t i = 0; i < bookSize; i++)
entry->book.books.push_back(reader->ReadInt16());
}
void AudioSoundFontV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{
AudioSoundFont* soundFont = (AudioSoundFont*)res;
ResourceFile::ParseFileBinary(reader, res);
soundFont->id = reader->ReadInt32();
soundFont->medium = reader->ReadInt8();
soundFont->cachePolicy = reader->ReadInt8();
soundFont->data1 = reader->ReadInt16();
soundFont->data2 = reader->ReadInt16();
soundFont->data3 = reader->ReadInt16();
uint32_t drumCnt = reader->ReadInt32();
uint32_t instrumentCnt = reader->ReadInt32();
uint32_t sfxCnt = reader->ReadInt32();
for (uint32_t i = 0; i < drumCnt; i++)
{
DrumEntry drum;
drum.releaseRate = reader->ReadUByte();
drum.pan = reader->ReadUByte();
drum.loaded = reader->ReadUByte();
drum.env = ReadEnvelopeData(reader);
bool hasSample = reader->ReadInt8();
drum.sampleFileName = reader->ReadString();
drum.tuning = reader->ReadFloat();
soundFont->drums.push_back(drum);
}
for (uint32_t i = 0; i < instrumentCnt; i++)
{
InstrumentEntry entry;
entry.isValidEntry = reader->ReadUByte();
entry.loaded = reader->ReadUByte();
entry.normalRangeLo = reader->ReadUByte();
entry.normalRangeHi = reader->ReadUByte();
entry.releaseRate = reader->ReadUByte();
entry.env = ReadEnvelopeData(reader);
{
bool hasSFEntry = reader->ReadInt8();
if (hasSFEntry)
{
entry.lowNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadInt8();
entry.lowNotesSound->sampleFileName = reader->ReadString();
entry.lowNotesSound->tuning = reader->ReadFloat();
}
}
{
bool hasSFEntry = reader->ReadInt8();
if (hasSFEntry)
{
entry.normalNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadInt8();
entry.normalNotesSound->sampleFileName = reader->ReadString();
entry.normalNotesSound->tuning = reader->ReadFloat();
}
}
{
bool hasSFEntry = reader->ReadInt8();
if (hasSFEntry)
{
entry.highNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadInt8();
entry.highNotesSound->sampleFileName = reader->ReadString();
entry.highNotesSound->tuning = reader->ReadFloat();
}
}
soundFont->instruments.push_back(entry);
}
for (uint32_t i = 0; i < sfxCnt; i++)
{
SoundFontEntry* entry = new SoundFontEntry();
bool hasSFEntry = reader->ReadInt8();
if (hasSFEntry)
{
bool hasSampleRef = reader->ReadInt8();
entry->sampleFileName = reader->ReadString();
entry->tuning = reader->ReadFloat();
}
soundFont->soundEffects.push_back(entry);
}
}
std::vector<AdsrEnvelope*> AudioSoundFontV2::ReadEnvelopeData(BinaryReader* reader)
{
std::vector<AdsrEnvelope*> envelopes;
uint32_t envelopeCnt = reader->ReadInt32();
for (uint32_t i = 0; i < envelopeCnt; i++)
{
AdsrEnvelope* env = new AdsrEnvelope();
env->delay = reader->ReadInt16();
env->arg = reader->ReadInt16();
envelopes.push_back(env);
}
return envelopes;
}
void AudioV2::ParseFileBinary(BinaryReader* reader, Resource* res)
{
Audio* audio = (Audio*)res;
ResourceFile::ParseFileBinary(reader, res);
}
}