Files
Shiip-of-Hakinian-Espanol/soh/soh/resource/importer/AudioSampleFactory.cpp
briaguya 2308ab8823 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

142 lines
4.8 KiB
C++

#include "soh/resource/importer/AudioSampleFactory.h"
#include "soh/resource/type/AudioSample.h"
#include "spdlog/spdlog.h"
namespace LUS {
std::shared_ptr<IResource>
AudioSampleFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, std::shared_ptr<BinaryReader> reader) {
auto resource = std::make_shared<AudioSample>(initData);
std::shared_ptr<ResourceVersionFactory> factory = nullptr;
switch (resource->GetInitData()->ResourceVersion) {
case 2:
factory = std::make_shared<AudioSampleFactoryV0>();
break;
}
if (factory == nullptr) {
SPDLOG_ERROR("Failed to load AudioSample with version {}", resource->GetInitData()->ResourceVersion);
return nullptr;
}
factory->ParseFileBinary(reader, resource);
return resource;
}
void LUS::AudioSampleFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader,
std::shared_ptr<IResource> resource)
{
std::shared_ptr<AudioSample> audioSample = std::static_pointer_cast<AudioSample>(resource);
ResourceVersionFactory::ParseFileBinary(reader, audioSample);
audioSample->sample.codec = reader->ReadUByte();
audioSample->sample.medium = reader->ReadUByte();
audioSample->sample.unk_bit26 = reader->ReadUByte();
audioSample->sample.unk_bit25 = reader->ReadUByte();
audioSample->sample.size = reader->ReadUInt32();
audioSample->audioSampleData.reserve(audioSample->sample.size);
for (uint32_t i = 0; i < audioSample->sample.size; i++) {
audioSample->audioSampleData.push_back(reader->ReadUByte());
}
audioSample->sample.sampleAddr = audioSample->audioSampleData.data();
audioSample->loop.start = reader->ReadUInt32();
audioSample->loop.end = reader->ReadUInt32();
audioSample->loop.count = reader->ReadUInt32();
audioSample->loopStateCount = reader->ReadUInt32();
for (int i = 0; i < 16; i++) {
audioSample->loop.state[i] = 0;
}
for (uint32_t i = 0; i < audioSample->loopStateCount; i++) {
audioSample->loop.state[i] = reader->ReadInt16();
}
audioSample->sample.loop = &audioSample->loop;
audioSample->book.order = reader->ReadInt32();
audioSample->book.npredictors = reader->ReadInt32();
audioSample->bookDataCount = reader->ReadUInt32();
audioSample->bookData.reserve(audioSample->bookDataCount);
for (uint32_t i = 0; i < audioSample->bookDataCount; i++) {
audioSample->bookData.push_back(reader->ReadInt16());
}
audioSample->book.book = audioSample->bookData.data();
audioSample->sample.book = &audioSample->book;
}
} // namespace LUS
/*
in ResourceMgr_LoadAudioSample we used to have
--------------
if (cachedCustomSFs.find(path) != cachedCustomSFs.end())
return cachedCustomSFs[path];
SoundFontSample* cSample = ReadCustomSample(path);
if (cSample != nullptr)
return cSample;
--------------
before the rest of the standard sample reading, this is the ReadCustomSample code we used to have
extern "C" SoundFontSample* ReadCustomSample(const char* path) {
if (!ExtensionCache.contains(path))
return nullptr;
ExtensionEntry entry = ExtensionCache[path];
auto sampleRaw = LUS::Context::GetInstance()->GetResourceManager()->LoadFile(entry.path);
uint32_t* strem = (uint32_t*)sampleRaw->Buffer.get();
uint8_t* strem2 = (uint8_t*)strem;
SoundFontSample* sampleC = new SoundFontSample;
if (entry.ext == "wav") {
drwav_uint32 channels;
drwav_uint32 sampleRate;
drwav_uint64 totalPcm;
drmp3_int16* pcmData =
drwav_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &channels, &sampleRate, &totalPcm, NULL);
sampleC->size = totalPcm;
sampleC->sampleAddr = (uint8_t*)pcmData;
sampleC->codec = CODEC_S16;
sampleC->loop = new AdpcmLoop;
sampleC->loop->start = 0;
sampleC->loop->end = sampleC->size - 1;
sampleC->loop->count = 0;
sampleC->sampleRateMagicValue = 'RIFF';
sampleC->sampleRate = sampleRate;
cachedCustomSFs[path] = sampleC;
return sampleC;
} else if (entry.ext == "mp3") {
drmp3_config mp3Info;
drmp3_uint64 totalPcm;
drmp3_int16* pcmData =
drmp3_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &mp3Info, &totalPcm, NULL);
sampleC->size = totalPcm * mp3Info.channels * sizeof(short);
sampleC->sampleAddr = (uint8_t*)pcmData;
sampleC->codec = CODEC_S16;
sampleC->loop = new AdpcmLoop;
sampleC->loop->start = 0;
sampleC->loop->end = sampleC->size;
sampleC->loop->count = 0;
sampleC->sampleRateMagicValue = 'RIFF';
sampleC->sampleRate = mp3Info.sampleRate;
cachedCustomSFs[path] = sampleC;
return sampleC;
}
return nullptr;
}
*/