Removed legacy audio mode and fixed ganon sound bug (#657)

This commit is contained in:
Nicholas Estelami 2022-07-11 22:37:39 -04:00 committed by GitHub
parent eab3b5bd7f
commit 3aa93b9855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 141 additions and 2140 deletions

View File

@ -171,10 +171,6 @@ extern "C"
#define gTatumsPerBeat (D_8014A6C0[1])
extern const AudioContextInitSizes D_8014A6C4;
extern s16 gOcarinaSongItemMap[];
extern u8 gSoundFontTable[];
extern u8 gSequenceFontTable[];
extern u8 gSequenceTable[];
extern u8 gSampleBankTable[];
extern u8 D_80155F50[];
extern u8 D_80157580[];
extern u8 D_801579A0[];

View File

@ -20,7 +20,6 @@
#define CALC_RESAMPLE_FREQ(sampleRate) ((float)sampleRate / (s32)gAudioContext.audioBufferParameters.frequency)
extern bool gUseLegacySD;
extern char* fontMap[256];
typedef enum {

View File

@ -1351,57 +1351,6 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) {
return ((int)ceilf(OTRGetDimensionFromRightEdge(v)));
}
extern "C" void bswapSoundFontSound(SoundFontSound* swappable) {
swappable->sample = (SoundFontSample*)BOMSWAP32((u32)(uintptr_t(swappable->sample)));
swappable->tuningAsU32 = BOMSWAP32((u32)(swappable->tuningAsU32 & 0xFFFFFFFF));
}
extern "C" void bswapDrum(Drum* swappable) {
bswapSoundFontSound(&swappable->sound);
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope));
}
extern "C" void bswapInstrument(Instrument* swappable) {
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope));
bswapSoundFontSound(&swappable->lowNotesSound);
bswapSoundFontSound(&swappable->normalNotesSound);
bswapSoundFontSound(&swappable->highNotesSound);
}
extern "C" void bswapSoundFontSample(SoundFontSample* swappable) {
u32 origBitfield = BOMSWAP32(swappable->asU32);
swappable->codec = (origBitfield >> 28) & 0x0F;
swappable->medium = (origBitfield >> 24) & 0x03;
swappable->unk_bit26 = (origBitfield >> 22) & 0x01;
swappable->unk_bit25 = (origBitfield >> 21) & 0x01;
swappable->size = (origBitfield) & 0x00FFFFFF;
swappable->sampleAddr = (u8*)BOMSWAP32((u32)uintptr_t(swappable->sampleAddr));
swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)uintptr_t(swappable->loop));
swappable->book = (AdpcmBook*)BOMSWAP32((u32)uintptr_t(swappable->book));
}
extern "C" void bswapAdpcmLoop(AdpcmLoop* swappable) {
swappable->start = (u32)BOMSWAP32((u32)swappable->start);
swappable->end = (u32)BOMSWAP32((u32)swappable->end);
swappable->count = (u32)BOMSWAP32((u32)swappable->count);
if (swappable->count != 0) {
for (int i = 0; i < 16; i++) {
swappable->state[i] = (s16)BOMSWAP16(swappable->state[i]);
}
}
}
extern "C" void bswapAdpcmBook(AdpcmBook* swappable) {
swappable->order = (u32)BOMSWAP32((u32)swappable->order);
swappable->npredictors = (u32)BOMSWAP32((u32)swappable->npredictors);
for (int i = 0; i < swappable->npredictors * swappable->order * sizeof(s16) * 4; i++)
swappable->book[i] = (s16)BOMSWAP16(swappable->book[i]);
}
extern "C" bool AudioPlayer_Init(void) {
if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) {
return OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Init();

View File

@ -77,12 +77,6 @@ float OTRGetDimensionFromLeftEdge(float v);
float OTRGetDimensionFromRightEdge(float v);
int16_t OTRGetRectDimensionFromLeftEdge(float v);
int16_t OTRGetRectDimensionFromRightEdge(float v);
void bswapDrum(Drum* swappable);
void bswapInstrument(Instrument* swappable);
bool bswapSoundFontSound(SoundFontSound* swappable);
void bswapSoundFontSample(SoundFontSample* swappable);
void bswapAdpcmLoop(AdpcmLoop* swappable);
void bswapAdpcmBook(AdpcmBook* swappable);
char* ResourceMgr_LoadFileRaw(const char* resName);
bool AudioPlayer_Init(void);
int AudioPlayer_Buffered(void);

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,6 @@ void AudioHeap_DiscardSampleCaches(void);
void AudioHeap_DiscardSampleBank(s32 sampleBankId);
void AudioHeap_DiscardSampleBanks(void);
extern bool gUseLegacySD;
f32 func_800DDE20(f32 arg0) {
return 256.0f * gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled / arg0;
}
@ -1205,15 +1203,6 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) {
void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample)
{
if (!gUseLegacySD)
return;
if (sample != NULL) {
if (sample->sampleAddr == entry->allocatedAddr) {
sample->sampleAddr = entry->sampleAddr;
sample->medium = entry->origMedium;
}
}
}
SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(size_t size) {
@ -1248,6 +1237,8 @@ void AudioHeap_DiscardSampleCaches(void) {
s32 fontId;
s32 j;
return;
numFonts = gAudioContext.soundFontTable->numEntries;
for (fontId = 0; fontId < numFonts; fontId++) {
sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
@ -1317,6 +1308,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) {
u32* fakematch;
s32 pad[4];
return;
sampleBankTable = gAudioContext.sampleBankTable;
numFonts = gAudioContext.soundFontTable->numEntries;
change.oldAddr = AudioHeap_SearchCaches(SAMPLE_TABLE, CACHE_EITHER, sampleBankId);

View File

@ -82,8 +82,6 @@ char* fontMap[256];
uintptr_t fontStart;
uint32_t fontOffsets[8192];
bool gUseLegacySD = false;
void AudioLoad_DecreaseSampleDmaTtls(void) {
u32 i;
@ -483,26 +481,15 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret
u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
s32 index;
if (!gUseLegacySD)
{
if (seqId == 255)
return NULL;
if (seqId == 255)
return NULL;
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
if (sDat.numFonts == 0)
return NULL;
if (sDat.numFonts == 0)
return NULL;
return sDat.fonts;
} else {
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
*outNumFonts = gAudioContext.sequenceFontTable[index++];
if (*outNumFonts == 0) {
return NULL;
}
return &gAudioContext.sequenceFontTable[index];
}
return sDat.fonts;
}
void AudioLoad_DiscardSeqFonts(s32 seqId) {
@ -578,38 +565,19 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
s32 numFonts;
s32 fontId;
if (gUseLegacySD && seqId >= gAudioContext.numSequences) {
return 0;
}
AudioSeq_SequencePlayerDisable(seqPlayer);
fontId = 0xFF;
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
numFonts = gAudioContext.sequenceFontTable[index++];
//index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
//numFonts = gAudioContext.sequenceFontTable[index++];
if (gUseLegacySD) {
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
numFonts = gAudioContext.sequenceFontTable[index++];
SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
while (numFonts > 0) {
fontId = gAudioContext.sequenceFontTable[index++];
AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds...
numFonts--;
}
}
else
for (int i = 0; i < seqData2.numFonts; i++)
{
SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
for (int i = 0; i < seqData2.numFonts; i++)
{
fontId = seqData2.fonts[i];
AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds...
numFonts--;
}
fontId = seqData2.fonts[i];
AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds...
//numFonts--;
}
seqData = AudioLoad_SyncLoadSeq(seqId);
@ -620,10 +588,7 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
AudioSeq_ResetSequencePlayer(seqPlayer);
seqPlayer->seqId = seqId;
if (gUseLegacySD)
seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
else
seqPlayer->defaultFont = fontId;
seqPlayer->defaultFont = fontId;
seqPlayer->seqData = seqData;
seqPlayer->enabled = 1;
@ -667,8 +632,8 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32
return ret;
}
cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy;
if (cachePolicy == 4 || noLoad == true) {
//cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy;
if (/* cachePolicy == 4 || */ noLoad == true) {
*outMedium = sampleBankTable->entries[sampleBankId].medium;
return sampleBankTable->entries[realTableId].romAddr;
}
@ -695,31 +660,24 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) {
return NULL;
}
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont
(fontMap[fontId]);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
sampleBankId1 = sf->sampleBankId1;
sampleBankId2 = sf->sampleBankId2;
} else {
sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1;
sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2;
}
sampleBankId1 = sf->sampleBankId1;
sampleBankId2 = sf->sampleBankId2;
relocInfo.sampleBankId1 = sampleBankId1;
relocInfo.sampleBankId2 = sampleBankId2;
if (sampleBankId1 != 0xFF) {
relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false);
} else {
//if (sampleBankId1 != 0xFF) {
//relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false);
//} else {
relocInfo.baseAddr1 = 0;
}
//}
if (sampleBankId2 != 0xFF) {
relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false);
} else {
//if (sampleBankId2 != 0xFF) {
//relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false);
//} else {
relocInfo.baseAddr2 = 0;
}
//}
ret = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate);
if (ret == NULL) {
@ -752,7 +710,7 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
char* seqData = 0;
SoundFont* fnt;
if (!gUseLegacySD && tableType == SEQUENCE_TABLE)
if (tableType == SEQUENCE_TABLE)
{
SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]);
seqData = sData.seqData;
@ -761,7 +719,7 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
cachePolicy = sData.cachePolicy;
romAddr = 0;
}
else if (!gUseLegacySD && tableType == FONT_TABLE)
else if (tableType == FONT_TABLE)
{
fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]);
size = sizeof(SoundFont);
@ -771,12 +729,12 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
}
else
{
table = AudioLoad_GetLoadTable(tableType);
size = table->entries[realId].size;
//table = AudioLoad_GetLoadTable(tableType);
//size = table->entries[realId].size;
//size = ALIGN16(size);
medium = table->entries[id].medium;
cachePolicy = table->entries[id].cachePolicy;
romAddr = table->entries[realId].romAddr;
//medium = table->entries[id].medium;
//cachePolicy = table->entries[id].cachePolicy;
//romAddr = table->entries[realId].romAddr;
}
switch (cachePolicy) {
@ -811,13 +769,13 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
if (medium == MEDIUM_UNK) {
AudioLoad_SyncDmaUnkMedium(romAddr, ret, size, (s16)table->unkMediumParam);
} else {
if (!gUseLegacySD && tableType == SEQUENCE_TABLE && seqData != NULL) {
if (tableType == SEQUENCE_TABLE && seqData != NULL) {
AudioLoad_SyncDma(seqData, ret, size, medium);
} else if (!gUseLegacySD && tableType == FONT_TABLE) {
} else if (tableType == FONT_TABLE) {
AudioLoad_SyncDma(fnt, ret, size, medium);
}
else {
AudioLoad_SyncDma(romAddr, ret, size, medium);
//AudioLoad_SyncDma(romAddr, ret, size, medium);
}
}
@ -843,17 +801,17 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id)
{
if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE) && !gUseLegacySD) {
if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE)) {
return id;
}
AudioTable* table = AudioLoad_GetLoadTable(tableType);
//AudioTable* table = AudioLoad_GetLoadTable(tableType);
// If the size is 0, then this entry actually redirects to another entry.
// The rom address is actually an index into the same table where the "real" data is.
if (table->entries[id].size == 0) {
id = table->entries[id].romAddr;
}
//if (table->entries[id].size == 0) {
//id = table->entries[id].romAddr;
//}
return id;
}
@ -906,77 +864,37 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
s32 numInstruments = 0;
s32 numSfx = 0;
if (gUseLegacySD) {
numDrums = gAudioContext.soundFonts[fontId].numDrums;
numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
numSfx = gAudioContext.soundFonts[fontId].numSfx;
} else {
sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
numDrums = sf->numDrums;
numInstruments = sf->numInstruments;
numSfx = sf->numSfx;
}
sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
numDrums = sf->numDrums;
numInstruments = sf->numInstruments;
numSfx = sf->numSfx;
void** ptrs = (void**)mem;
#define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem))
reloc2 = ptrs[0];
if ((reloc2 != 0 || !gUseLegacySD) && (numDrums != 0))
if ((numDrums != 0))
{
ptrs[0] = BASE_OFFSET(reloc2);
for (i = 0; i < numDrums; i++)
{
if (gUseLegacySD)
reloc = ((Drum**)ptrs[0])[i];
drum = sf->drums[i];
if (reloc != 0 || !gUseLegacySD)
if (!drum->loaded)
{
if (gUseLegacySD)
{
reloc = BASE_OFFSET(reloc);
((Drum**)ptrs[0])[i] = drum = reloc;
}
if (!gUseLegacySD)
drum = sf->drums[i];
if (!drum->loaded)
{
if (!gUseLegacySD)
{
AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]);
//reloc = drum->envelope;
drum->loaded = 1;
}
else
{
AudioLoad_RelocateSample(&drum->sound, mem, relocInfo, fontOffsets[fontId]);
reloc = drum->envelope;
drum->envelope = BASE_OFFSET(reloc);
drum->loaded = 1;
}
}
AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]);
drum->loaded = 1;
}
}
}
reloc2 = ptrs[1];
if ((reloc2 != 0 || !gUseLegacySD) && (numSfx != 0)) {
if (numSfx != 0) {
ptrs[1] = BASE_OFFSET(reloc2);
for (i = 0; i < numSfx; i++) {
reloc = (SoundFontSound*)ptrs[1] + i;
if (reloc != 0 || !gUseLegacySD)
{
if (!gUseLegacySD) {
AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]);
} else {
sfx = reloc;
if (sfx->sample != NULL) {
AudioLoad_RelocateSample(sfx, mem, relocInfo, fontOffsets[fontId]);
}
}
}
AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]);
}
}
@ -984,46 +902,28 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
numInstruments = 0x7E;
}
int startI = gUseLegacySD ? 2 : 0;
int startEC = gUseLegacySD ? 2 + numInstruments - 1 : numInstruments - 1;
//for (i = 2; i <= 2 + numInstruments - 1; i++) {
int startI = 0;
int startEC = numInstruments - 1;
for (i = startI; i <= startEC; i++) {
if (!gUseLegacySD || ptrs[i] != NULL)
{
ptrs[i] = BASE_OFFSET(ptrs[i]);
ptrs[i] = BASE_OFFSET(ptrs[i]);
inst = sf->instruments[i];
if (gUseLegacySD)
inst = ptrs[i];
else
inst = sf->instruments[i];
if (inst != NULL && !inst->loaded) {
if (inst->normalRangeLo != 0)
{
AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]);
if (inst->normalRangeHi != 0x7F) {
AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
reloc = inst->envelope;
if (gUseLegacySD)
inst->envelope = BASE_OFFSET(reloc);
inst->loaded = 1;
if (inst != NULL && !inst->loaded) {
if (inst->normalRangeLo != 0)
{
AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]);
if (inst->normalRangeHi != 0x7F) {
AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]);
}
reloc = inst->envelope;
inst->loaded = 1;
}
}
#undef BASE_OFFSET
if (gUseLegacySD) {
gAudioContext.soundFonts[fontId].drums = ptrs[0];
gAudioContext.soundFonts[fontId].soundEffects = ptrs[1];
gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2);
}
}
void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) {
@ -1209,24 +1109,6 @@ s32 AudioLoad_AssertValidAddr(uintptr_t ramAddr, uintptr_t startAddr, size_t siz
#define BASE_ROM_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(romAddr))
void AudioLoad_InitSwapFontSampleHeaders(SoundFontSample* sample, uintptr_t romAddr) {
size_t maxSoundFontSize = 0x3AA0; // soundFont 0 is the largest size at 0x3AA0
AdpcmLoop* loop;
AdpcmBook* book;
if (((uintptr_t)sample->loop > maxSoundFontSize) || ((uintptr_t)sample->book > maxSoundFontSize) ) {
bswapSoundFontSample(sample);
loop = (AdpcmLoop*)BASE_ROM_OFFSET(sample->loop);
if ((uint32_t)loop->end > (uint32_t)0xFFFF) {
bswapAdpcmLoop(loop);
}
book = (AdpcmBook*)BASE_ROM_OFFSET(sample->book);
if (book->order > 0xFFFF) {
bswapAdpcmBook(book);
}
}
return;
}
void AudioLoad_InitSwapFont(void) {
@ -1273,7 +1155,6 @@ void AudioLoad_InitSwapFont(void) {
if (drumList[i] != NULL) {
drum = (Drum*)BASE_ROM_OFFSET(drumList[i]);
bswapDrum(drum);
sample = (SoundFontSample*)BASE_ROM_OFFSET(drum->sound.sample);
AudioLoad_InitSwapFontSampleHeaders(sample, romAddr);
@ -1289,7 +1170,6 @@ void AudioLoad_InitSwapFont(void) {
for (i = 0; i < numSfxs; i++) {
sfx = &sfxList[i];
bswapSoundFontSound(sfx);
if (sfx->sample != NULL) {
SoundFontSample* sample = (SoundFontSample*)BASE_ROM_OFFSET(sfx->sample);
@ -1309,7 +1189,6 @@ void AudioLoad_InitSwapFont(void) {
if (instList[i] != NULL) {
inst = BASE_ROM_OFFSET(instList[i]);
bswapInstrument(inst);
if (inst->normalRangeLo != 0) {
sample = (SoundFontSample*)BASE_ROM_OFFSET(inst->lowNotesSound.sample);
@ -1402,79 +1281,50 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16));
}
gAudioContext.sequenceTable = (AudioTable*)gSequenceTable;
gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable;
gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable;
gAudioContext.sequenceFontTable = gSequenceFontTable;
gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries;
//gAudioContext.sequenceTable = (AudioTable*)gSequenceTable;
//gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable;
//gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable;
//gAudioContext.sequenceFontTable = gSequenceFontTable;
//gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries;
gAudioContext.audioResetSpecIdToLoad = 0;
gAudioContext.resetStatus = 1;
AudioHeap_ResetStep();
uintptr_t seqStart = ResourceMgr_LoadFileRaw(_AudioseqSegmentRomStart);
uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart);
uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart);
int seqListSize = 0;
char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize);
// If we have the old audioseq files present (and this is a 32-bit build), use the legacy audio system
if (seqStart != NULL && bankStart != NULL && tableStart != NULL)
gUseLegacySD = true;
fontStart = bankStart;
AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0);
AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0);
AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0);
if (gUseLegacySD)
numFonts = gAudioContext.soundFontTable->numEntries;
if (gUseLegacySD)
for (size_t i = 0; i < seqListSize; i++)
{
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont));
SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]);
for (i = 0; i < numFonts; i++) {
AudioLoad_InitSoundFontMeta(i);
}
char* str = malloc(strlen(seqList[i]) + 1);
strcpy(str, seqList[i]);
AudioLoad_InitSwapFont();
} else {
int seqListSize = 0;
char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize);
sequenceMap[sDat.seqNumber] = str;
}
for (size_t i = 0; i < seqListSize; i++)
{
SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]);
free(seqList);
char* str = malloc(strlen(seqList[i]) + 1);
strcpy(str, seqList[i]);
int fntListSize = 0;
char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize);
sequenceMap[sDat.seqNumber] = str;
}
for (int i = 0; i < fntListSize; i++)
{
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]);
free(seqList);
char* str = malloc(strlen(fntList[i]) + 1);
strcpy(str, fntList[i]);
int fntListSize = 0;
char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize);
for (int i = 0; i < fntListSize; i++)
{
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]);
char* str = malloc(strlen(fntList[i]) + 1);
strcpy(str, fntList[i]);
fontMap[sf->fntIndex] = str;
}
fontMap[sf->fntIndex] = str;
}
numFonts = fntListSize;
free(fntList);
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont));
}
if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) {
// cast away const from D_8014A6C4
@ -1648,11 +1498,6 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) {
AudioTable* seqTable;
size_t size;
if (gUseLegacySD && seqId >= gAudioContext.numSequences) {
*isDone = 0;
return -1;
}
seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId);
seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE);
slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos];
@ -1663,19 +1508,11 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) {
slowLoad->sample.sampleAddr = NULL;
slowLoad->isDone = isDone;
if (!gUseLegacySD)
{
SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
char* seqData = sData.seqData;
size = sData.seqDataSize;
slowLoad->curDevAddr = seqData;
slowLoad->medium = sData.medium;
} else {
size = seqTable->entries[seqId].size;
size = ALIGN16(size);
slowLoad->curDevAddr = seqTable->entries[seqId].romAddr;
slowLoad->medium = seqTable->entries[seqId].medium;
}
SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
char* seqData = sData.seqData;
size = sData.seqDataSize;
slowLoad->curDevAddr = seqData;
slowLoad->medium = sData.medium;
slowLoad->curRamAddr = ramAddr;
slowLoad->status = LOAD_STATUS_START;
@ -1889,61 +1726,10 @@ void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, size_t size) {
void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, uintptr_t ramAddr, size_t size, s16 arg3) {
}
#define RELOC(v, base) (reloc = (uintptr_t)((uintptr_t)(v) + (uintptr_t)(base)))
void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) {
size_t maxSoundBankSize = 0x3EB2A0; // sample bank 0 is largest size at 0x3EB2A0
if (gUseLegacySD)
{
// NOTE: This is hack to detect whether or not the sample has been relocated.
if ((uintptr_t)mem <= maxSoundBankSize) {
assert("mem for sound font bank is too low.");
}
}
SoundFontSample* sample;
void* reloc;
// NOTE: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works.
if ((uintptr_t)sound->sample < maxSoundBankSize || !gUseLegacySD)
{
if (!gUseLegacySD) {
SoundFontSample* sample2 = sound;
} else {
sample = sound->sample = RELOC(sound->sample, mem);
if (sample->size != 0 && sample->unk_bit25 != 1) {
sample->loop = RELOC(sample->loop, mem);
sample->book = RELOC(sample->book, mem);
// Resolve the sample medium 2-bit bitfield into a real value based on relocInfo.
switch (sample->medium) {
case 0:
sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1);
sample->medium = relocInfo->medium1;
break;
case 1:
sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2);
sample->medium = relocInfo->medium2;
break;
case 2:
case 3:
// Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE
// respectively, and the sampleAddr unrelocated.
break;
}
sample->unk_bit25 = 1;
if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) {
gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample;
}
}
}
}
void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId)
{
}
#undef RELOC
void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 async) {
AudioPreloadReq* preload;
AudioPreloadReq* topPreload;
@ -2190,17 +1976,11 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo
gAudioContext.numUsedSamples = 0;
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
numDrums = sf->numDrums;
numInstruments = sf->numInstruments;
numSfx = sf->numSfx;
} else {
numDrums = gAudioContext.soundFonts[fontId].numDrums;
numInstruments = gAudioContext.soundFonts[fontId].numInstruments;
numSfx = gAudioContext.soundFonts[fontId].numSfx;
}
numDrums = sf->numDrums;
numInstruments = sf->numInstruments;
numSfx = sf->numSfx;
for (i = 0; i < numInstruments; i++) {
instrument = Audio_GetInstrumentInner(fontId, i);
@ -2326,15 +2106,11 @@ void AudioLoad_LoadPermanentSamples(void) {
fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id);
//fontId = gAudioContext.permanentCache[i].id;
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
relocInfo.sampleBankId1 = sf->sampleBankId1;
relocInfo.sampleBankId2 = sf->sampleBankId2;
} else {
relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2;
}
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
relocInfo.sampleBankId1 = sf->sampleBankId1;
relocInfo.sampleBankId2 = sf->sampleBankId2;
/*
if (relocInfo.sampleBankId1 != 0xFF) {
relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1);
relocInfo.medium1 = sampleBankTable->entries[relocInfo.sampleBankId1].medium;
@ -2344,6 +2120,8 @@ void AudioLoad_LoadPermanentSamples(void) {
relocInfo.sampleBankId2 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId2);
relocInfo.medium2 = sampleBankTable->entries[relocInfo.sampleBankId2].medium;
}
*/
AudioLoad_PreloadSamplesForFont(fontId, false, &relocInfo);
}
}

View File

@ -288,7 +288,8 @@ void Audio_ProcessNotes(void) {
f32 resampRate = gAudioContext.audioBufferParameters.resampleRate;
if (!gUseLegacySD && !noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL &&
// CUSTOM SAMPLE CHECK
if (!noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL &&
noteSubEu2->sound.soundFontSound->sample != NULL &&
noteSubEu2->sound.soundFontSound->sample->sampleRateMagicValue == 'RIFF') {
resampRate = CALC_RESAMPLE_FREQ(noteSubEu2->sound.soundFontSound->sample->sampleRate);
@ -330,24 +331,12 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
}
int instCnt = 0;
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
if (gUseLegacySD) {
instCnt = gAudioContext.soundFonts[fontId].numInstruments;
inst = gAudioContext.soundFonts[fontId].instruments[instId];
if (instId >= sf->numInstruments)
return NULL;
if (instId >= gAudioContext.soundFonts[fontId].numInstruments)
if (instId >= instCnt) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000;
return NULL;
}
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
if (instId >= sf->numInstruments)
return NULL;
inst = sf->instruments[instId];
}
inst = sf->instruments[instId];
if (inst == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
@ -369,18 +358,10 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
return NULL;
}
if (gUseLegacySD) {
if (drumId >= gAudioContext.soundFonts[fontId].numDrums) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000;
return NULL;
}
drum = gAudioContext.soundFonts[fontId].drums[drumId];
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
drum = sf->drums[drumId];
}
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
drum = sf->drums[drumId];
if (drum == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000;
}
@ -400,17 +381,8 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
return NULL;
}
if (gUseLegacySD) {
if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000;
return NULL;
}
sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId];
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
sfx = &sf->soundEffects[sfxId];
}
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
sfx = &sf->soundEffects[sfxId];
if (sfx == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000;

View File

@ -3,7 +3,6 @@
#include "ultra64.h"
#include "global.h"
extern bool gUseLegacySD;
extern char* sequenceMap[256];
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
@ -1062,18 +1061,14 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
result = (u8)parameters[0];
command = (u8)parameters[0];
if (seqPlayer->defaultFont != 0xFF) {
if (gUseLegacySD) {
offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId];
lowBits = gAudioContext.sequenceFontTable[offset];
command = gAudioContext.sequenceFontTable[offset + lowBits - result];
} else {
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]);
command = sDat.fonts[sDat.numFonts - result - 1];
}
if (seqPlayer->defaultFont != 0xFF)
{
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]);
command = sDat.fonts[sDat.numFonts - result - 1];
}
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) {
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command))
{
channel->fontId = command;
}
@ -1178,18 +1173,16 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
result = (u8)parameters[0];
command = (u8)parameters[0];
if (seqPlayer->defaultFont != 0xFF) {
if (gUseLegacySD) {
offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId];
lowBits = gAudioContext.sequenceFontTable[offset];
command = gAudioContext.sequenceFontTable[offset + lowBits - result];
} else {
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]);
command = sDat.fonts[sDat.numFonts - result - 1];
}
if (seqPlayer->defaultFont != 0xFF)
{
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]);
int8_t idx = (sDat.numFonts - result - 1);
command = sDat.fonts[abs(idx)];
}
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) {
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command))
{
channel->fontId = command;
}

View File

@ -2095,10 +2095,8 @@ void func_80075B44(GlobalContext* globalCtx) {
{
// OTRTODO: This is where corrupt audio happens. Commenting this out seems to not introduce any side effects?
// Further investigation is needed...
if (gUseLegacySD)
Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5,
CHANNEL_IO_PORT_1, 1);
//Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5,
//CHANNEL_IO_PORT_1, 1);
}
globalCtx->envCtx.unk_E0++;
break;