Shipwright/soh/soh/resource/importer/AudioSoundFontFactory.cpp

174 lines
7.6 KiB
C++
Raw Normal View History

#include "soh/resource/importer/AudioSoundFontFactory.h"
#include "soh/resource/type/AudioSoundFont.h"
#include "spdlog/spdlog.h"
#include "libultraship/libultraship.h"
namespace SOH {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryAudioSoundFontV2::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto audioSoundFont = std::make_shared<AudioSoundFont>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
audioSoundFont->soundFont.fntIndex = reader->ReadInt32();
audioSoundFont->medium = reader->ReadInt8();
audioSoundFont->cachePolicy = reader->ReadInt8();
audioSoundFont->data1 = reader->ReadUInt16();
audioSoundFont->soundFont.sampleBankId1 = audioSoundFont->data1 >> 8;
audioSoundFont->soundFont.sampleBankId2 = audioSoundFont->data1 & 0xFF;
audioSoundFont->data2 = reader->ReadUInt16();
audioSoundFont->data3 = reader->ReadUInt16();
uint32_t drumCount = reader->ReadUInt32();
audioSoundFont->soundFont.numDrums = drumCount;
uint32_t instrumentCount = reader->ReadUInt32();
audioSoundFont->soundFont.numInstruments = instrumentCount;
uint32_t soundEffectCount = reader->ReadUInt32();
audioSoundFont->soundFont.numSfx = soundEffectCount;
// 🥁 DRUMS 🥁
audioSoundFont->drums.reserve(audioSoundFont->soundFont.numDrums);
audioSoundFont->drumAddresses.reserve(audioSoundFont->soundFont.numDrums);
for (uint32_t i = 0; i < audioSoundFont->soundFont.numDrums; i++) {
Drum drum;
drum.releaseRate = reader->ReadUByte();
drum.pan = reader->ReadUByte();
drum.loaded = reader->ReadUByte();
drum.loaded = 0; // this was always getting set to zero in ResourceMgr_LoadAudioSoundFont
uint32_t envelopeCount = reader->ReadUInt32();
audioSoundFont->drumEnvelopeCounts.push_back(envelopeCount);
std::vector<AdsrEnvelope> drumEnvelopes;
drumEnvelopes.reserve(audioSoundFont->drumEnvelopeCounts[i]);
for (uint32_t j = 0; j < audioSoundFont->drumEnvelopeCounts.back(); j++) {
AdsrEnvelope env;
int16_t delay = reader->ReadInt16();
int16_t arg = reader->ReadInt16();
env.delay = BE16SWAP(delay);
env.arg = BE16SWAP(arg);
drumEnvelopes.push_back(env);
}
audioSoundFont->drumEnvelopeArrays.push_back(drumEnvelopes);
drum.envelope = audioSoundFont->drumEnvelopeArrays.back().data();
bool hasSample = reader->ReadInt8();
std::string sampleFileName = reader->ReadString();
drum.sound.tuning = reader->ReadFloat();
if (sampleFileName.empty()) {
drum.sound.sample = nullptr;
} else {
auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str());
build soh with LUS 1.0.0 (#2881) * Bump LUS * Ship -> LUS namespace change * z_scene_otr Ship -> LUS namespace * Starting to get SoH to build with LUS imgui changes. * start stuff * gamecontroleditor build issues resolved maybe * cosmetics editor and what not * console * actor viewer * more stuff * more stuff * on to errors that make sense * putting this down for a bit * no idea what these errors mean now * some kind of progress maybe * latest lus main * more * back to linker errors and being lost * Fixes command function signature. * More fixes * Even more fixes * Bump LUS * More Fixes. * Fixes even more errors. * lus bump * input editor as var * audio editor working * it builds with this * bump lus * it opens * bump lus to latest main again * make sure to do all the command registering in debugconsole * lus and what not * switch type stuff plz * undo * do the thing that fixes the thing * fix mac? * correctly show/hide menubar on boot * bump lus * input blocking updates * bump lus * Bump LUS * Press F1 to open enhancement menus moved to SoH * lus and rendering backend stuff * audio backend and lus * Bump LUS * Fixes WindowBackend dropdown * Bump LUS * misc -> utils and moves binarytools to utils. * Window refactor * bump lus * make it work * Fixes for moved files again * Bump LUS * Mercury -> Config * Bump LUS * Reacts to removed LUS hooks and bump LUS * Remove Hook: GfxInit * Removes debug audio_setgamevolume to 1 * use non-crashing branch of lus * fix: make audio init work without hooks * game icon stuff * multifix bmp * use input viewer class branch for now * just "Ship" it's cleaner * Bump LUS * Removed ExitGame hook. * Bump LUS * Hook system removed from LUS. * More LUS updates * Changes to make window position saving. * Bump LUS * Bump LUS (for real) * LUS resources now return a specialized pointer. * Bump LUS * Fixes issue in SetPathways::GetPointerSize * Bump LUS to 1.0.0 * builds but crashes * fix crash * better macro names in debug console * remove commeted out line * remove redundant check tracker settings window logic * remove commented out line * move the * * remove extra seqplayers enum def * this sneaky little guy was hiding behind a wii u ifdef * remove extra check tracker header --------- Co-authored-by: Kenix <kenixwhisperwind@gmail.com> Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00
drum.sound.sample = static_cast<Sample*>(res ? res->GetRawPointer() : nullptr);
}
audioSoundFont->drums.push_back(drum);
audioSoundFont->drumAddresses.push_back(&audioSoundFont->drums.back());
}
audioSoundFont->soundFont.drums = audioSoundFont->drumAddresses.data();
// 🎺🎻🎷🎸🎹 INSTRUMENTS 🎹🎸🎷🎻🎺
audioSoundFont->instruments.reserve(audioSoundFont->soundFont.numInstruments);
for (uint32_t i = 0; i < audioSoundFont->soundFont.numInstruments; i++) {
Instrument instrument;
uint8_t isValidEntry = reader->ReadUByte();
instrument.loaded = reader->ReadUByte();
instrument.loaded = 0; // this was always getting set to zero in ResourceMgr_LoadAudioSoundFont
instrument.normalRangeLo = reader->ReadUByte();
instrument.normalRangeHi = reader->ReadUByte();
instrument.releaseRate = reader->ReadUByte();
uint32_t envelopeCount = reader->ReadInt32();
audioSoundFont->instrumentEnvelopeCounts.push_back(envelopeCount);
std::vector<AdsrEnvelope> instrumentEnvelopes;
for (uint32_t j = 0; j < audioSoundFont->instrumentEnvelopeCounts.back(); j++) {
AdsrEnvelope env;
int16_t delay = reader->ReadInt16();
int16_t arg = reader->ReadInt16();
env.delay = BE16SWAP(delay);
env.arg = BE16SWAP(arg);
instrumentEnvelopes.push_back(env);
}
audioSoundFont->instrumentEnvelopeArrays.push_back(instrumentEnvelopes);
instrument.envelope = audioSoundFont->instrumentEnvelopeArrays.back().data();
bool hasLowNoteSoundFontEntry = reader->ReadInt8();
if (hasLowNoteSoundFontEntry) {
bool hasSampleRef = reader->ReadInt8();
std::string sampleFileName = reader->ReadString();
instrument.lowNotesSound.tuning = reader->ReadFloat();
auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str());
build soh with LUS 1.0.0 (#2881) * Bump LUS * Ship -> LUS namespace change * z_scene_otr Ship -> LUS namespace * Starting to get SoH to build with LUS imgui changes. * start stuff * gamecontroleditor build issues resolved maybe * cosmetics editor and what not * console * actor viewer * more stuff * more stuff * on to errors that make sense * putting this down for a bit * no idea what these errors mean now * some kind of progress maybe * latest lus main * more * back to linker errors and being lost * Fixes command function signature. * More fixes * Even more fixes * Bump LUS * More Fixes. * Fixes even more errors. * lus bump * input editor as var * audio editor working * it builds with this * bump lus * it opens * bump lus to latest main again * make sure to do all the command registering in debugconsole * lus and what not * switch type stuff plz * undo * do the thing that fixes the thing * fix mac? * correctly show/hide menubar on boot * bump lus * input blocking updates * bump lus * Bump LUS * Press F1 to open enhancement menus moved to SoH * lus and rendering backend stuff * audio backend and lus * Bump LUS * Fixes WindowBackend dropdown * Bump LUS * misc -> utils and moves binarytools to utils. * Window refactor * bump lus * make it work * Fixes for moved files again * Bump LUS * Mercury -> Config * Bump LUS * Reacts to removed LUS hooks and bump LUS * Remove Hook: GfxInit * Removes debug audio_setgamevolume to 1 * use non-crashing branch of lus * fix: make audio init work without hooks * game icon stuff * multifix bmp * use input viewer class branch for now * just "Ship" it's cleaner * Bump LUS * Removed ExitGame hook. * Bump LUS * Hook system removed from LUS. * More LUS updates * Changes to make window position saving. * Bump LUS * Bump LUS (for real) * LUS resources now return a specialized pointer. * Bump LUS * Fixes issue in SetPathways::GetPointerSize * Bump LUS to 1.0.0 * builds but crashes * fix crash * better macro names in debug console * remove commeted out line * remove redundant check tracker settings window logic * remove commented out line * move the * * remove extra seqplayers enum def * this sneaky little guy was hiding behind a wii u ifdef * remove extra check tracker header --------- Co-authored-by: Kenix <kenixwhisperwind@gmail.com> Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00
instrument.lowNotesSound.sample = static_cast<Sample*>(res ? res->GetRawPointer() : nullptr);
} else {
instrument.lowNotesSound.sample = nullptr;
instrument.lowNotesSound.tuning = 0;
}
bool hasNormalNoteSoundFontEntry = reader->ReadInt8();
if (hasNormalNoteSoundFontEntry) {
bool hasSampleRef = reader->ReadInt8();
std::string sampleFileName = reader->ReadString();
instrument.normalNotesSound.tuning = reader->ReadFloat();
auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str());
build soh with LUS 1.0.0 (#2881) * Bump LUS * Ship -> LUS namespace change * z_scene_otr Ship -> LUS namespace * Starting to get SoH to build with LUS imgui changes. * start stuff * gamecontroleditor build issues resolved maybe * cosmetics editor and what not * console * actor viewer * more stuff * more stuff * on to errors that make sense * putting this down for a bit * no idea what these errors mean now * some kind of progress maybe * latest lus main * more * back to linker errors and being lost * Fixes command function signature. * More fixes * Even more fixes * Bump LUS * More Fixes. * Fixes even more errors. * lus bump * input editor as var * audio editor working * it builds with this * bump lus * it opens * bump lus to latest main again * make sure to do all the command registering in debugconsole * lus and what not * switch type stuff plz * undo * do the thing that fixes the thing * fix mac? * correctly show/hide menubar on boot * bump lus * input blocking updates * bump lus * Bump LUS * Press F1 to open enhancement menus moved to SoH * lus and rendering backend stuff * audio backend and lus * Bump LUS * Fixes WindowBackend dropdown * Bump LUS * misc -> utils and moves binarytools to utils. * Window refactor * bump lus * make it work * Fixes for moved files again * Bump LUS * Mercury -> Config * Bump LUS * Reacts to removed LUS hooks and bump LUS * Remove Hook: GfxInit * Removes debug audio_setgamevolume to 1 * use non-crashing branch of lus * fix: make audio init work without hooks * game icon stuff * multifix bmp * use input viewer class branch for now * just "Ship" it's cleaner * Bump LUS * Removed ExitGame hook. * Bump LUS * Hook system removed from LUS. * More LUS updates * Changes to make window position saving. * Bump LUS * Bump LUS (for real) * LUS resources now return a specialized pointer. * Bump LUS * Fixes issue in SetPathways::GetPointerSize * Bump LUS to 1.0.0 * builds but crashes * fix crash * better macro names in debug console * remove commeted out line * remove redundant check tracker settings window logic * remove commented out line * move the * * remove extra seqplayers enum def * this sneaky little guy was hiding behind a wii u ifdef * remove extra check tracker header --------- Co-authored-by: Kenix <kenixwhisperwind@gmail.com> Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00
instrument.normalNotesSound.sample = static_cast<Sample*>(res ? res->GetRawPointer() : nullptr);
} else {
instrument.normalNotesSound.sample = nullptr;
instrument.normalNotesSound.tuning = 0;
}
bool hasHighNoteSoundFontEntry = reader->ReadInt8();
if (hasHighNoteSoundFontEntry) {
bool hasSampleRef = reader->ReadInt8();
std::string sampleFileName = reader->ReadString();
instrument.highNotesSound.tuning = reader->ReadFloat();
auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str());
build soh with LUS 1.0.0 (#2881) * Bump LUS * Ship -> LUS namespace change * z_scene_otr Ship -> LUS namespace * Starting to get SoH to build with LUS imgui changes. * start stuff * gamecontroleditor build issues resolved maybe * cosmetics editor and what not * console * actor viewer * more stuff * more stuff * on to errors that make sense * putting this down for a bit * no idea what these errors mean now * some kind of progress maybe * latest lus main * more * back to linker errors and being lost * Fixes command function signature. * More fixes * Even more fixes * Bump LUS * More Fixes. * Fixes even more errors. * lus bump * input editor as var * audio editor working * it builds with this * bump lus * it opens * bump lus to latest main again * make sure to do all the command registering in debugconsole * lus and what not * switch type stuff plz * undo * do the thing that fixes the thing * fix mac? * correctly show/hide menubar on boot * bump lus * input blocking updates * bump lus * Bump LUS * Press F1 to open enhancement menus moved to SoH * lus and rendering backend stuff * audio backend and lus * Bump LUS * Fixes WindowBackend dropdown * Bump LUS * misc -> utils and moves binarytools to utils. * Window refactor * bump lus * make it work * Fixes for moved files again * Bump LUS * Mercury -> Config * Bump LUS * Reacts to removed LUS hooks and bump LUS * Remove Hook: GfxInit * Removes debug audio_setgamevolume to 1 * use non-crashing branch of lus * fix: make audio init work without hooks * game icon stuff * multifix bmp * use input viewer class branch for now * just "Ship" it's cleaner * Bump LUS * Removed ExitGame hook. * Bump LUS * Hook system removed from LUS. * More LUS updates * Changes to make window position saving. * Bump LUS * Bump LUS (for real) * LUS resources now return a specialized pointer. * Bump LUS * Fixes issue in SetPathways::GetPointerSize * Bump LUS to 1.0.0 * builds but crashes * fix crash * better macro names in debug console * remove commeted out line * remove redundant check tracker settings window logic * remove commented out line * move the * * remove extra seqplayers enum def * this sneaky little guy was hiding behind a wii u ifdef * remove extra check tracker header --------- Co-authored-by: Kenix <kenixwhisperwind@gmail.com> Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00
instrument.highNotesSound.sample = static_cast<Sample*>(res ? res->GetRawPointer() : nullptr);
} else {
instrument.highNotesSound.sample = nullptr;
instrument.highNotesSound.tuning = 0;
}
audioSoundFont->instruments.push_back(instrument);
audioSoundFont->instrumentAddresses.push_back(isValidEntry ?
&audioSoundFont->instruments.back() :
nullptr);
}
audioSoundFont->soundFont.instruments = audioSoundFont->instrumentAddresses.data();
// 🔊 SOUND EFFECTS 🔊
audioSoundFont->soundEffects.reserve(audioSoundFont->soundFont.numSfx);
for (uint32_t i = 0; i < audioSoundFont->soundFont.numSfx; i++) {
SoundFontSound soundEffect;
bool hasSFEntry = reader->ReadInt8();
if (hasSFEntry) {
bool hasSampleRef = reader->ReadInt8();
std::string sampleFileName = reader->ReadString();
soundEffect.tuning = reader->ReadFloat();
auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str());
build soh with LUS 1.0.0 (#2881) * Bump LUS * Ship -> LUS namespace change * z_scene_otr Ship -> LUS namespace * Starting to get SoH to build with LUS imgui changes. * start stuff * gamecontroleditor build issues resolved maybe * cosmetics editor and what not * console * actor viewer * more stuff * more stuff * on to errors that make sense * putting this down for a bit * no idea what these errors mean now * some kind of progress maybe * latest lus main * more * back to linker errors and being lost * Fixes command function signature. * More fixes * Even more fixes * Bump LUS * More Fixes. * Fixes even more errors. * lus bump * input editor as var * audio editor working * it builds with this * bump lus * it opens * bump lus to latest main again * make sure to do all the command registering in debugconsole * lus and what not * switch type stuff plz * undo * do the thing that fixes the thing * fix mac? * correctly show/hide menubar on boot * bump lus * input blocking updates * bump lus * Bump LUS * Press F1 to open enhancement menus moved to SoH * lus and rendering backend stuff * audio backend and lus * Bump LUS * Fixes WindowBackend dropdown * Bump LUS * misc -> utils and moves binarytools to utils. * Window refactor * bump lus * make it work * Fixes for moved files again * Bump LUS * Mercury -> Config * Bump LUS * Reacts to removed LUS hooks and bump LUS * Remove Hook: GfxInit * Removes debug audio_setgamevolume to 1 * use non-crashing branch of lus * fix: make audio init work without hooks * game icon stuff * multifix bmp * use input viewer class branch for now * just "Ship" it's cleaner * Bump LUS * Removed ExitGame hook. * Bump LUS * Hook system removed from LUS. * More LUS updates * Changes to make window position saving. * Bump LUS * Bump LUS (for real) * LUS resources now return a specialized pointer. * Bump LUS * Fixes issue in SetPathways::GetPointerSize * Bump LUS to 1.0.0 * builds but crashes * fix crash * better macro names in debug console * remove commeted out line * remove redundant check tracker settings window logic * remove commented out line * move the * * remove extra seqplayers enum def * this sneaky little guy was hiding behind a wii u ifdef * remove extra check tracker header --------- Co-authored-by: Kenix <kenixwhisperwind@gmail.com> Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00
soundEffect.sample = static_cast<Sample*>(res ? res->GetRawPointer() : nullptr);
}
audioSoundFont->soundEffects.push_back(soundEffect);
}
audioSoundFont->soundFont.soundEffects = audioSoundFont->soundEffects.data();
return audioSoundFont;
}
} // namespace SOH