Audio loaded from OTR

This commit is contained in:
KiritoDv
2024-11-21 03:13:13 -03:00
committed by Alejandro Asenjo Nitti
parent 5dd3b06d03
commit bd7c4b6df6
46 changed files with 801 additions and 44 deletions
+29 -7
View File
@@ -1,8 +1,30 @@
audio_seq:
{ type: BLOB, offset: 0xDEA20, size: 0x3ACF0, symbol: gAudioSeq }
audio_bank:
{ type: BLOB, offset: 0x119710, size: 0x1E020, symbol: gAudioBank }
:config:
force: true
header:
code:
- '#include "sys.h"'
- '#include "sf64audio_provisional.h"'
audio_table:
{ type: BLOB, offset: 0x137730, size: 0x73C580, symbol: gAudioTable }
audio_setup:
type: NAUDIO:V1:AUDIO_SETUP
audio_seq:
size: 0x3ACF0
offset: 0xDEA20
audio_bank:
size: 0x1E020
offset: 0x119710
audio_table:
size: 0x73C580
offset: 0x137730
audio_sample_bank_table:
{ type: NAUDIO:V1:AUDIO_TABLE, format: SAMPLE, offset: 0xC4210, symbol: gSampleBankTableInit }
audio_seq_table:
{ type: NAUDIO:V1:AUDIO_TABLE, format: SEQUENCE, offset: 0xC4260, symbol: gSeqTableInit }
audio_soundfont_table:
{ type: NAUDIO:V1:AUDIO_TABLE, format: SOUNDFONT, offset: 0xC4690, symbol: gSoundFontTableInit }
audio_seq_font_table:
{ type: ARRAY, count: 283, array_type: u8, offset: 0xC48B0, symbol: gSeqFontTableInit }
+6 -6
View File
@@ -840,8 +840,8 @@ typedef struct {
typedef struct {
/* 0x00 */ AudioTableBase base;
/* 0x10 */ AudioTableEntry entries[]; // (dynamic size)
} AudioTable; // size >= 0x20
/* 0x10 */ AudioTableEntry* entries; // (dynamic size)
} AudioTable; // size >= 0x20
typedef struct SampleDma {
/* 0x00 */ u8* ramAddr;
@@ -1091,10 +1091,10 @@ bool AudioThread_ResetComplete(void);
void AudioThread_ResetAudioHeap(s32);
void AudioThread_Init(void);
extern AudioTable gSampleBankTableInit;
extern AudioTable gSeqTableInit;
extern AudioTable gSoundFontTableInit;
extern u8 gSeqFontTableInit[];
// extern AudioTable gSampleBankTableInit;
// extern AudioTable gSeqTableInit;
// extern AudioTable gSoundFontTableInit;
// extern u8 gSeqFontTableInit[];
extern AudioSpec gAudioSpecs[];
extern s16 gSeqTicksPerBeat;
+17 -19
View File
@@ -390,11 +390,11 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
s32 fontId;
s32 i;
seqId = AudioLoad_GetLoadTableIndex(SEQUENCE_TABLE, seqId);
// seqId = AudioLoad_GetLoadTableIndex(SEQUENCE_TABLE, seqId);
AudioSeq_SequencePlayerDisable(&gSeqPlayers[playerIdx]);
index = *((u16*) gSeqFontTable + seqId);
index = BSWAP16(*((u16*) gSeqFontTable + seqId));
numFonts = gSeqFontTable[index++];
fontId = 0xFF;
@@ -419,12 +419,12 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
void* AudioLoad_SyncLoadSeq(s32 seqId) {
AudioTable* table = AudioLoad_GetLoadTable(SEQUENCE_TABLE);
s32 seqIdx = AudioLoad_GetLoadTableIndex(SEQUENCE_TABLE, seqId);
return Audio_LoadBlob(gAudioSeq, table->entries[seqIdx].romAddr);
return ResourceGetDataByCrc((uint64_t) table->entries[seqId].romAddr);
}
void* AudioLoad_SyncLoadSampleBank(u32 sampleBankId, s32* outMedium) {
return NULL;
void* ramAddr;
AudioTable* sampleBankTable = AudioLoad_GetLoadTable(2);
s32 cachePolicy;
@@ -433,7 +433,7 @@ void* AudioLoad_SyncLoadSampleBank(u32 sampleBankId, s32* outMedium) {
sampleBankId = AudioLoad_GetLoadTableIndex(SAMPLE_TABLE, sampleBankId);
gSampleFontLoadStatus[sampleBankId] = 2;
return Audio_LoadBlob(gAudioTable, sampleBankTable->entries[sampleBankId].romAddr);
// return Audio_LoadBlob(gAudioTable, sampleBankTable->entries[sampleBankId].romAddr);
ramAddr = AudioLoad_SearchCaches(2, sampleBankId);
if (ramAddr != NULL) {
@@ -468,7 +468,7 @@ void* AudioLoad_SyncLoadFont(s32 fontId) {
s32 didAllocate;
SampleBankRelocInfo relocInfo;
fontId = AudioLoad_GetLoadTableIndex(FONT_TABLE, fontId);
// fontId = AudioLoad_GetLoadTableIndex(FONT_TABLE, fontId);
sampleBankId1 = gSoundFontList[fontId].sampleBankId1;
sampleBankId2 = gSoundFontList[fontId].sampleBankId2;
@@ -522,13 +522,11 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
switch (tableType) {
case SEQUENCE_TABLE:
gSeqLoadStatus[id] = LOAD_STATUS_COMPLETE;
//ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, id);
return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr);
return ResourceGetDataByCrc((uint64_t) table->entries[id].romAddr);
case FONT_TABLE:
gFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
//ramAddr = AudioHeap_AllocCached(tableType, size, CACHE_PERSISTENT, id);
return Audio_LoadFont(table->entries[id]);
return Audio_LoadFont(table->entries[id], id);
case SAMPLE_TABLE:
loadStatus = 0;
break;
@@ -613,7 +611,7 @@ void AudioLoad_RelocateFont(s32 fontId, uintptr_t fontBaseAddr, SampleBankRelocI
// }
AudioTable* table = AudioLoad_GetLoadTable(FONT_TABLE);
printf("fontId: %d\n", fontId);
SoundFont* font = Audio_LoadFont(table->entries[fontId]);
SoundFont* font = Audio_LoadFont(table->entries[fontId], fontId);
gSoundFontList[fontId] = *font;
}
@@ -713,16 +711,16 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
case SEQUENCE_TABLE:
gSeqLoadStatus[id] = LOAD_STATUS_COMPLETE;
osSendMesg(retQueue, OS_MESG_32(retData << 0x18), OS_MESG_NOBLOCK);
return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr);
return ResourceGetDataByCrc((uint64_t) table->entries[id].romAddr);
case FONT_TABLE:
gFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
printf("fontId: %d\n", id);
osSendMesg(retQueue, OS_MESG_32(retData << 0x18), OS_MESG_NOBLOCK);
return Audio_LoadFont(table->entries[id]);
return Audio_LoadFont(table->entries[id], id);
case SAMPLE_TABLE:
gSampleFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
// LTODO: Validate this
return Audio_LoadSample(table->entries[id].romAddr, table->entries[id], id);
// return Audio_LoadSample(table->entries[id].romAddr, table->entries[id], id);
return NULL;
}
@@ -873,10 +871,10 @@ void AudioLoad_Init(void) {
gAudioResetStep = 1;
AudioHeap_ResetStep();
gSequenceTable = &gSeqTableInit;
gSoundFontTable = &gSoundFontTableInit;
gSampleBankTable = &gSampleBankTableInit;
gSeqFontTable = gSeqFontTableInit;
gSequenceTable = SEGMENTED_TO_VIRTUAL(gSeqTableInit);
gSoundFontTable = SEGMENTED_TO_VIRTUAL(gSoundFontTableInit);
gSampleBankTable = SEGMENTED_TO_VIRTUAL(gSampleBankTableInit);
gSeqFontTable = SEGMENTED_TO_VIRTUAL(gSeqFontTableInit);
gNumSequences = gSequenceTable->base.numEntries;
// AudioLoad_InitTable(gSequenceTable, LOAD_ASSET(gAudioSeq), gSequenceMedium);
+2 -2
View File
@@ -175,7 +175,7 @@ Instrument* Audio_GetInstrument(s32 fontId, s32 instId) {
//fontId = 7;
if(gSoundFontList[fontId].instruments == NULL){
gSoundFontList[fontId] = *Audio_LoadFont(gSoundFontTable->entries[fontId]);
gSoundFontList[fontId] = *Audio_LoadFont(gSoundFontTable->entries[fontId], fontId);
}
if ((gFontLoadStatus[fontId] < 2) != 0) {
@@ -199,7 +199,7 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
// LTODO: Remove this
if(gSoundFontList[fontId].drums == NULL){
gSoundFontList[fontId] = *Audio_LoadFont(gSoundFontTable->entries[fontId]);
gSoundFontList[fontId] = *Audio_LoadFont(gSoundFontTable->entries[fontId], fontId);
}
if ((gFontLoadStatus[fontId] < 2) != 0) {
+2 -1
View File
@@ -1,5 +1,6 @@
#include "sys.h"
#include "sf64audio_provisional.h"
#include "endianness.h"
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
#define PORTAMENTO_MODE(x) ((x).mode & ~0x80)
@@ -1014,7 +1015,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xC6:
cmd = AudioSeq_ScriptReadU8(state);
sp52 = ((u16*) gSeqFontTable)[seqPlayer->seqId];
sp52 = BSWAP16(((u16*) gSeqFontTable)[seqPlayer->seqId]);
loBits = gSeqFontTable[sp52];
cmd = gSeqFontTable[sp52 + loBits - cmd];
+2 -3
View File
@@ -669,9 +669,8 @@ Acmd* AudioSynth_Update(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLe
//if (gAudioBufferParams.ticksPerUpdate > 3 && gGameState != GSTATE_PLAY) return;
aCmdPtr = aList;
for (i = gAudioBufferParams.ticksPerUpdate; i > 0; i--) {
AudioSeq_ProcessSequences(i - 1);
AudioSynth_SyncSampleStates(gAudioBufferParams.ticksPerUpdate - i);
AudioSeq_ProcessSequences(i - 1);
AudioSynth_SyncSampleStates(gAudioBufferParams.ticksPerUpdate - i);
}
aiBufPtr = aiBufStart;
+4 -1
View File
@@ -1,6 +1,7 @@
#include "sys.h"
#include "sf64audio_provisional.h"
#if 0
AudioTable gSampleBankTableInit = {
{ 4, 0, 0 },
{
@@ -98,7 +99,7 @@ AudioTable gSoundFontTableInit = {
// clang-format off
u8 gSeqFontTableInit[283] = {
u8 gSeqFontTableInitOriginal[283] = {
// Offset into this table for sequence sound font list
AS_BYTES(132), AS_BYTES(134), AS_BYTES(155), AS_BYTES(157), AS_BYTES(159), AS_BYTES(161), AS_BYTES(163),
AS_BYTES(165), AS_BYTES(167), AS_BYTES(169), AS_BYTES(171), AS_BYTES(173), AS_BYTES(175), AS_BYTES(177),
@@ -123,3 +124,5 @@ u8 gSeqFontTableInit[283] = {
};
// clang-format on
#endif
+36
View File
@@ -17,6 +17,16 @@
#include "resource/importers/SkeletonFactory.h"
#include "resource/importers/Vec3fFactory.h"
#include "resource/importers/Vec3sFactory.h"
#include "resource/importers/audio/AudioTableFactory.h"
#include "resource/importers/audio/BookFactory.h"
#include "resource/importers/audio/DrumFactory.h"
#include "resource/importers/audio/EnvelopeFactory.h"
#include "resource/importers/audio/InstrumentFactory.h"
#include "resource/importers/audio/LoopFactory.h"
#include "resource/importers/audio/SampleFactory.h"
#include "resource/importers/audio/SoundFontFactory.h"
#include "port/interpolation/FrameInterpolation.h"
#include <Fast3D/Fast3dWindow.h>
#include <DisplayListFactory.h>
@@ -25,6 +35,7 @@
#include <BlobFactory.h>
#include <VertexFactory.h>
#include "audio/GameAudio.h"
#include "port/patches/DisplayListPatch.h"
// #include "sf64audio_provisional.h"
#include <Fast3D/gfx_pc.h>
@@ -127,11 +138,36 @@ GameEngine::GameEngine() {
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY,
"Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAudioTableV0>(), RESOURCE_FORMAT_BINARY,
"AudioTable", static_cast<uint32_t>(SF64::ResourceType::AudioTable), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAdpcmBookV0>(), RESOURCE_FORMAT_BINARY,
"AdpcmBook", static_cast<uint32_t>(SF64::ResourceType::AdpcmBook), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryDrumV0>(), RESOURCE_FORMAT_BINARY,
"Drum", static_cast<uint32_t>(SF64::ResourceType::Drum), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryEnvelopeV0>(), RESOURCE_FORMAT_BINARY,
"Envelope", static_cast<uint32_t>(SF64::ResourceType::Envelope), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryInstrumentV0>(), RESOURCE_FORMAT_BINARY,
"Instrument", static_cast<uint32_t>(SF64::ResourceType::Instrument), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAdpcmLoopV0>(), RESOURCE_FORMAT_BINARY,
"AdpcmLoop", static_cast<uint32_t>(SF64::ResourceType::AdpcmLoop), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinarySampleV1>(), RESOURCE_FORMAT_BINARY,
"Sample", static_cast<uint32_t>(SF64::ResourceType::Sample), 1);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinarySoundFontV0>(), RESOURCE_FORMAT_BINARY,
"SoundFont", static_cast<uint32_t>(SF64::ResourceType::SoundFont), 0);
}
void GameEngine::Create() {
const auto instance = Instance = new GameEngine();
instance->AudioInit();
DisplayListPatch::Run();
GameUI::SetupGuiElements();
#if defined(__SWITCH__) || defined(__WIIU__)
CVarRegisterInteger("gControlNav", 1); // always enable controller nav on switch/wii u
+21
View File
@@ -0,0 +1,21 @@
#include "DisplayListPatch.h"
#include <libultraship.h>
std::unordered_map<const char*, std::vector<std::pair<uint32_t, Gfx>>> patches = {
// { ast_corneria_seg6_gfx_23420, {
// { 23, gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, 0x003C, 0x003C) }
// }}
};
void DisplayListPatch::Run() {
SPDLOG_INFO("Applying display list patches");
for(auto& entry : patches){
auto data = (Gfx*) ResourceGetDataByName(entry.first);
for(auto& patch : entry.second){
data[patch.first] = patch.second;
}
SPDLOG_INFO("{} patched successfully!", entry.first);
}
}
+5
View File
@@ -0,0 +1,5 @@
#pragma once
class DisplayListPatch {
public:
static void Run();
};
@@ -0,0 +1,38 @@
#include "AudioTableFactory.h"
#include "port/resource/type/audio/AudioTable.h"
#include "../ResourceUtil.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryAudioTableV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto table = std::make_shared<AudioTable>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
int16_t med = reader->ReadInt16();
uint32_t addr = reader->ReadUInt32();
uint32_t count = reader->ReadUInt32();
for(size_t i = 0; i < count; i++){
uint64_t crc = reader->ReadUInt64();
uint32_t size = reader->ReadUInt32();
int8_t medium = reader->ReadInt8();
int8_t policy = reader->ReadInt8();
int16_t sd1 = reader->ReadInt16();
int16_t sd2 = reader->ReadInt16();
int16_t sd3 = reader->ReadInt16();
table->mEntries.push_back({
(uintptr_t) crc,
size, medium, policy, sd1, sd2, sd3
});
}
table->mTable.base = { (int16_t)count, med, addr };
table->mTable.entries = table->mEntries.data();
return table;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryAudioTableV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,24 @@
#include "BookFactory.h"
#include "port/resource/type/audio/AdpcmBook.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryAdpcmBookV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto book = std::make_shared<AdpcmBook>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
book->mBook.order = reader->ReadUInt32();
book->mBook.numPredictors = reader->ReadUInt32();
uint32_t count = reader->ReadUInt32();
for(size_t i = 0; i < count; i++){
book->mPages.push_back(reader->ReadInt16());
}
book->mBook.book = book->mPages.data();
return book;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryAdpcmBookV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,24 @@
#include "DrumFactory.h"
#include "../ResourceUtil.h"
#include "port/resource/type/audio/Drum.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryDrumV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto drum = std::make_shared<Drum>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
drum->mDrum.adsrDecayIndex = reader->ReadUByte();
drum->mDrum.pan = reader->ReadUByte();
drum->mDrum.isRelocated = reader->ReadUByte();
drum->mDrum.tunedSample.sample = LoadChild<SampleData*>(reader->ReadUInt64());
drum->mDrum.tunedSample.tuning = reader->ReadFloat();
drum->mDrum.envelope = LoadChild<EnvelopePointData*>(reader->ReadUInt64());
drum->mDrum.isRelocated = 1;
return drum;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryDrumV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,20 @@
#include "EnvelopeFactory.h"
#include "port/resource/type/audio/Envelope.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryEnvelopeV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto envelope = std::make_shared<Envelope>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
uint32_t count = reader->ReadUInt32();
for(size_t i = 0; i < count; i++){
envelope->mPoints.push_back({ reader->ReadInt16(), reader->ReadInt16() });
}
return envelope;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryEnvelopeV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,29 @@
#include "InstrumentFactory.h"
#include "../ResourceUtil.h"
#include "port/resource/type/audio/Instrument.h"
namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryInstrumentV0::ReadResource(std::shared_ptr<Ship::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto instrument = std::make_shared<Instrument>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
instrument->mInstrument.isRelocated = reader->ReadUByte();
instrument->mInstrument.normalRangeLo = reader->ReadUByte();
instrument->mInstrument.normalRangeHi = reader->ReadUByte();
instrument->mInstrument.adsrDecayIndex = reader->ReadUByte();
instrument->mInstrument.envelope = LoadChild<EnvelopePointData*>(reader->ReadUInt64());
instrument->mInstrument.lowPitchTunedSample.sample = LoadChild<SampleData*>(reader->ReadUInt64());
instrument->mInstrument.lowPitchTunedSample.tuning = reader->ReadFloat();
instrument->mInstrument.normalPitchTunedSample.sample = LoadChild<SampleData*>(reader->ReadUInt64());
instrument->mInstrument.normalPitchTunedSample.tuning = reader->ReadFloat();
instrument->mInstrument.highPitchTunedSample.sample = LoadChild<SampleData*>(reader->ReadUInt64());
instrument->mInstrument.highPitchTunedSample.tuning = reader->ReadFloat();
instrument->mInstrument.isRelocated = 1;
return instrument;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryInstrumentV0 : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
};
}; // namespace LUS

Some files were not shown because too many files have changed in this diff Show More