Updated zapd_audio_support into zelda64

This commit is contained in:
Kevin Alexis Contreras 2022-06-15 09:42:37 -05:00
commit 5b43e4652f
24 changed files with 1884 additions and 218 deletions

View File

@ -45,14 +45,14 @@ void OTRExporter_Audio::WriteSampleEntry(SampleEntry* entry, BinaryWriter* write
writer->Write((uint32_t)(entry->loop.count));
writer->Write((uint32_t)entry->loop.states.size());
for (size_t i = 0; i < entry->loop.states.size(); i++)
for (int i = 0; i < entry->loop.states.size(); i++)
writer->Write((entry->loop.states[i]));
writer->Write((uint32_t)(entry->book.order));
writer->Write((uint32_t)(entry->book.npredictors));
writer->Write((uint32_t)entry->book.books.size());
for (size_t i = 0; i < entry->book.books.size(); i++)
for (int i = 0; i < entry->book.books.size(); i++)
writer->Write((entry->book.books[i]));
}
@ -128,7 +128,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
fntWriter.Write((uint32_t)audio->soundFontTable[i].instruments.size());
fntWriter.Write((uint32_t)audio->soundFontTable[i].soundEffects.size());
for (size_t k = 0; k < audio->soundFontTable[i].drums.size(); k++)
for (int k = 0; k < audio->soundFontTable[i].drums.size(); k++)
{
fntWriter.Write(audio->soundFontTable[i].drums[k].releaseRate);
fntWriter.Write(audio->soundFontTable[i].drums[k].pan);
@ -140,7 +140,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
fntWriter.Write(audio->soundFontTable[i].drums[k].tuning);
}
for (size_t k = 0; k < audio->soundFontTable[i].instruments.size(); k++)
for (int k = 0; k < audio->soundFontTable[i].instruments.size(); k++)
{
fntWriter.Write((uint8_t)audio->soundFontTable[i].instruments[k].isValidInstrument);
@ -156,17 +156,18 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
WriteSoundFontEntry(audio, audio->soundFontTable[i].instruments[k].highNotesSound, audio->samples, &fntWriter);
}
for (size_t k = 0; k < audio->soundFontTable[i].soundEffects.size(); k++)
for (int k = 0; k < audio->soundFontTable[i].soundEffects.size(); k++)
{
WriteSoundFontEntry(audio, audio->soundFontTable[i].soundEffects[k], audio->samples, &fntWriter);
}
std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/font_%02X", i));
//std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/font_%02X", i));
std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("fonts/%s", audio->soundFontNames[i].c_str()));
AddFile(fName, fntStream->ToVector());
}
// Write Sequences
for (size_t i = 0; i < audio->sequences.size(); i++)
for (int i = 0; i < audio->sequences.size(); i++)
{
auto seq = audio->sequences[i];
@ -179,7 +180,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit
seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy);
seqWriter.Write((uint8_t)audio->fontIndices[i].size());
for (size_t k = 0; k < audio->fontIndices[i].size(); k++)
for (int k = 0; k < audio->fontIndices[i].size(); k++)
seqWriter.Write((uint8_t)audio->fontIndices[i][k]);
seqWriter.Write(seq.data(), seq.size());

View File

@ -52,7 +52,7 @@ unsigned char AsciiToLowerTable[256] =
};
// Converts ASCII characters to uppercase
// Converts backslash (0x5C) to backslash (0x2F)
// Converts slash (0x2F) to backslash (0x5C)
unsigned char AsciiToUpperTable[256] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
@ -95,6 +95,49 @@ unsigned char AsciiToUpperTable_Slash[256] =
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
// 5C (\) -> 2F (/)
unsigned char AsciiToUpperTable_FS2BS[256] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x2F, 0x5D, 0x5E, 0x5F,
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
// 2F (/) -> 5C (\)
unsigned char AsciiToUpperTable_BS2FS[256] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x5C,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
//-----------------------------------------------------------------------------
// Safe string functions (for ANSI builds)
@ -303,8 +346,29 @@ DWORD HashStringSlash(const char * szFileName, DWORD dwHashType)
{
// Convert the input character to uppercase
// DON'T convert slash (0x2F) to backslash (0x5C)
//ch = AsciiToUpperTable_Slash[*pbKey++];
ch = AsciiToUpperTable[*pbKey++];
ch = AsciiToUpperTable_FS2BS[*pbKey++];
//ch = AsciiToUpperTable[*pbKey++];
dwSeed1 = StormBuffer[dwHashType + ch] ^ (dwSeed1 + dwSeed2);
dwSeed2 = ch + dwSeed1 + dwSeed2 + (dwSeed2 << 5) + 3;
}
return dwSeed1;
}
DWORD HashStringSlash2(const char* szFileName, DWORD dwHashType)
{
LPBYTE pbKey = (BYTE*)szFileName;
DWORD dwSeed1 = 0x7FED7FED;
DWORD dwSeed2 = 0xEEEEEEEE;
DWORD ch;
while (*pbKey != 0)
{
// Convert the input character to uppercase
// DON'T convert slash (0x2F) to backslash (0x5C)
//ch = AsciiToUpperTable_Slash[*pbKey++];
ch = AsciiToUpperTable_BS2FS[*pbKey++];
dwSeed1 = StormBuffer[dwHashType + ch] ^ (dwSeed1 + dwSeed2);
dwSeed2 = ch + dwSeed1 + dwSeed2 + (dwSeed2 << 5) + 3;
@ -783,9 +847,13 @@ TMPQHash * GetFirstHashEntry(TMPQArchive * ha, const char * szFileName)
{
DWORD dwHashIndexMask = HASH_INDEX_MASK(ha);
DWORD dwStartIndex = ha->pfnHashString(szFileName, MPQ_HASH_TABLE_INDEX);
DWORD dwStartIndex2 = HashStringSlash2(szFileName, MPQ_HASH_TABLE_INDEX);
DWORD dwName1 = ha->pfnHashString(szFileName, MPQ_HASH_NAME_A);
DWORD dwName2 = ha->pfnHashString(szFileName, MPQ_HASH_NAME_B);
DWORD dwName1B = HashStringSlash2(szFileName, MPQ_HASH_NAME_A);
DWORD dwName2B = HashStringSlash2(szFileName, MPQ_HASH_NAME_B);
DWORD dwIndex;
bool isSecondTry = false;
// Set the initial index
dwStartIndex = dwIndex = (dwStartIndex & dwHashIndexMask);
@ -796,12 +864,22 @@ TMPQHash * GetFirstHashEntry(TMPQArchive * ha, const char * szFileName)
TMPQHash * pHash = ha->pHashTable + dwIndex;
// If the entry matches, we found it.
if(pHash->dwName1 == dwName1 && pHash->dwName2 == dwName2 && MPQ_BLOCK_INDEX(pHash) < ha->dwFileTableSize)
if ((pHash->dwName1 == dwName1 && pHash->dwName2 == dwName2 || (pHash->dwName1 == dwName1B && pHash->dwName2 == dwName2B)) && MPQ_BLOCK_INDEX(pHash) < ha->dwFileTableSize)
return pHash;
// If that hash entry is a free entry, it means we haven't found the file
if(pHash->dwBlockIndex == HASH_ENTRY_FREE)
return NULL;
if (pHash->dwBlockIndex == HASH_ENTRY_FREE)
{
// We've tried back slashes, now let's try forward slashes
if (!isSecondTry)
{
dwStartIndex = dwIndex = (dwStartIndex2 & dwHashIndexMask);
isSecondTry = true;
continue;
}
else
return NULL;
}
// Move to the next hash entry. Stop searching
// if we got reached the original hash entry
@ -881,7 +959,7 @@ ULONGLONG FindFreeMpqSpace(TMPQArchive * ha)
//static TFileEntry* furthestFile = nullptr;
//TFileEntry* startEntry = furthestFile == nullptr ? ha->pFileTable : furthestFile;
TFileEntry* startEntry = (ha->useFreeSpaceOptimization && ha->lastFreeSpaceEntry != nullptr) ? ha->lastFreeSpaceEntry : ha->pFileTable;
// Parse the entire block table

View File

@ -340,8 +340,9 @@ static LPBYTE CreateListFile(TMPQArchive * ha, DWORD * pcbListFile)
{
for (int i = 0; i < strlen(pFileEntry->szFileName); i++)
{
if (pFileEntry->szFileName[i] == '/')
pFileEntry->szFileName[i] = '\\';
// OTRTODO
//if (pFileEntry->szFileName[i] == '/')
//pFileEntry->szFileName[i] = '\\';
}
SortTable[nFileNodes++] = pFileEntry->szFileName;
@ -683,4 +684,3 @@ bool WINAPI SListFileFindClose(HANDLE hFind)
return FreeListFileCache(pCache);
}

View File

@ -209,7 +209,8 @@ void StringCat(TCHAR * szTarget, size_t cchTargetMax, const TCHAR * szSource);
#define MPQ_HASH_KEY2_MIX 0x400
DWORD HashString(const char * szFileName, DWORD dwHashType);
DWORD HashStringSlash(const char * szFileName, DWORD dwHashType);
DWORD HashStringSlash(const char* szFileName, DWORD dwHashType);
DWORD HashStringSlash2(const char * szFileName, DWORD dwHashType);
DWORD HashStringLower(const char * szFileName, DWORD dwHashType);
void InitializeMpqCryptography();
@ -437,4 +438,3 @@ void DumpFileTable(TFileEntry * pFileTable, DWORD dwFileTableSize);
#endif
#endif // __STORMCOMMON_H__

View File

@ -11,9 +11,10 @@ REGISTER_ZFILENODE(Audio, ZAudio);
ZAudio::ZAudio(ZFile* nParent) : ZResource(nParent)
{
//RegisterRequiredAttribute("CodeOffset");
//RegisterOptionalAttribute("LangOffset", "0");
RegisterRequiredAttribute("SoundFontTableOffset");
RegisterRequiredAttribute("SequenceTableOffset");
RegisterRequiredAttribute("SampleBankTableOffset");
RegisterRequiredAttribute("SequenceFontTableOffset");
}
void ZAudio::ParseXML(tinyxml2::XMLElement* reader)
@ -68,6 +69,13 @@ void ZAudio::ParseXML(tinyxml2::XMLElement* reader)
}
}
if (std::string(child->Value()) == "Soundfont")
{
auto name = child->Attribute("Name");
auto index = child->IntAttribute("Index", 0);
soundFontNames[index] = name;
}
child = child->NextSiblingElement();
}
}
@ -149,19 +157,10 @@ SampleEntry* ZAudio::ParseSampleEntry(std::vector<uint8_t> audioBank,
sample->loop.end = BitConverter::ToInt32BE(audioBank, loopOffset + 4);
sample->loop.count = BitConverter::ToInt32BE(audioBank, loopOffset + 8);
if (sample->loop.start == 0x3ADB)
if (sample->loop.count != 0)
{
int bp = 0;
}
if (/* sample->loop.count != 0xFFFFFFFF && */ sample->loop.count != 0)
{
//for (int i = 0; i < sample->loop.count; i++)
for (int i = 0; i < 16; i++)
{
//if ((loopOffset + 16 + (i * 2)) >= audioBank.size())
//break;
int16_t state = BitConverter::ToInt16BE(audioBank, loopOffset + 16 + (i * 2));
sample->loop.states.push_back(state);
}
@ -189,7 +188,7 @@ SampleEntry* ZAudio::ParseSampleEntry(std::vector<uint8_t> audioBank,
}
else
{
return samples[sampleOffset];
return samples[sampleOffset];
}
}
@ -338,30 +337,24 @@ void ZAudio::ParseRawData()
audioSeqData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() +
"Audioseq");
//codeData = File::ReadAllBytes("baserom/code_ntsc");
//audioTableData = File::ReadAllBytes("baserom/Audiotable_ntsc");
//audioSeqData = File::ReadAllBytes("baserom/Audioseq_ntsc");
//audioBankData = File::ReadAllBytes("baserom/Audiobank_ntsc");
// TABLE PARSING
// GC PAL
//int gSoundFontTableOffset = 0x138270; // OTRTODO: Make this an XML Param
//int gSequenceTableOffset = 0x1386A0; // OTRTODO: Make this an XML Param
//int gSampleBankTableOffset = 0x138D90; // OTRTODO: Make this an XML Param
//int gSequenceFontTableOffset = 0x1384E0; // OTRTODO: Make this an XML Param
// NMQ DBG ROM
int gSoundFontTableOffset = 0x138290; // OTRTODO: Make this an XML Param
int gSequenceTableOffset = 0x1386C0; // OTRTODO: Make this an XML Param
int gSampleBankTableOffset = 0x138DB0; // OTRTODO: Make this an XML Param
int gSequenceFontTableOffset = 0x138500; // OTRTODO: Make this an XML Param
// MQ DBG ROM
//int gSoundFontTableOffset = 0x138270;
//int gSequenceTableOffset = 0x1386A0;
//int gSampleBankTableOffset = 0x138D90;
//int gSequenceFontTableOffset = 0x1384E0;
// NTSC 1.0
//int gSoundFontTableOffset = 0x1026A0; // OTRTODO: Make this an XML Param
//int gSequenceTableOffset = 0x102AD0; // OTRTODO: Make this an XML Param
//int gSampleBankTableOffset = 0x1031C0; // OTRTODO: Make this an XML Param
//int gSequenceFontTableOffset = 0x102910; // OTRTODO: Make this an XML Param
//int gSoundFontTableOffset = 0x1026A0;
//int gSequenceTableOffset = 0x102AD0;
//int gSampleBankTableOffset = 0x1031C0;
//int gSequenceFontTableOffset = 0x102910;
int gSoundFontTableOffset = StringHelper::StrToL(registeredAttributes.at("SoundFontTableOffset").value, 16);
int gSequenceTableOffset = StringHelper::StrToL(registeredAttributes.at("SequenceTableOffset").value, 16);
int gSampleBankTableOffset = StringHelper::StrToL(registeredAttributes.at("SampleBankTableOffset").value, 16);
int gSequenceFontTableOffset = StringHelper::StrToL(registeredAttributes.at("SequenceFontTableOffset").value, 16);
soundFontTable = ParseAudioTable(codeData, gSoundFontTableOffset);
sequenceTable = ParseAudioTable(codeData, gSequenceTableOffset);

View File

@ -95,6 +95,7 @@ public:
std::map<uint32_t, SampleEntry*> samples;
std::vector<std::vector<uint32_t>> fontIndices;
std::vector<std::string> seqNames;
std::map<uint32_t, std::string> soundFontNames;
// First Key = Bank ID, Sec Key = LoopDataOffset, Third Key = Sample Data Offset
std::map<uint32_t, std::map<uint32_t, std::map<uint32_t, std::string>>> sampleOffsets;

View File

@ -461,8 +461,8 @@ char* OldMain(char* infilename)
else
{
char comprType[5] = {
static_cast<char>(CommChunk.compressionTypeH >> 8), static_cast<char>(CommChunk.compressionTypeH & 0xFF),
static_cast<char>(CommChunk.compressionTypeL >> 8), static_cast<char>(CommChunk.compressionTypeL & 0xFF), 0};
CommChunk.compressionTypeH >> 8, CommChunk.compressionTypeH & 0xFF,
CommChunk.compressionTypeL >> 8, CommChunk.compressionTypeL & 0xFF, 0};
fail_parse("file is of the wrong compression type [got %s (%08x)]", &comprType,
cType);
}
@ -603,8 +603,8 @@ char* OldMain(char* infilename)
{
s32 startPos = aloops[0].start, endPos = aloops[0].end;
const char* markerNames[2] = {"start", "end"};
Marker markers[2] = {{1, static_cast<u16>(startPos >> 16), static_cast<u16>(startPos & 0xffff)},
{2, static_cast<u16>(endPos >> 16), static_cast<u16>(endPos & 0xffff)}};
Marker markers[2] = {{1, startPos >> 16, startPos & 0xffff},
{2, endPos >> 16, endPos & 0xffff}};
write_header(ofile, "MARK", 2 + 2 * sizeof(Marker) + 1 + 5 + 1 + 3);
s16 numMarkers = bswap16(2);
fwrite(&numMarkers, sizeof(s16), 1, ofile);

View File

@ -68,7 +68,7 @@ ZRom::ZRom(std::string romPath)
romData = File::ReadAllBytes(romPath);
version.crc = BitConverter::ToInt32BE(romData, 0x10);
switch (version.crc)
{
case OOT_NTSC_10:
@ -192,10 +192,8 @@ ZRom::ZRom(std::string romPath)
else
files[lines[i]] = outData;
//File::WriteAllBytes(StringHelper::Sprintf("baserom/%s", lines[i]), files[lines[i]]);
//File::WriteAllBytes(StringHelper::Sprintf("baserom/%s", lines[i].c_str()), files[lines[i]]);
}
int bp = 0;
}
std::vector<uint8_t> ZRom::GetFile(std::string fileName)

View File

@ -61,11 +61,11 @@ namespace Ship {
bool attempt = SFileOpenFileEx(mainMPQ, filePath.c_str(), 0, &fileHandle);
/*if (!attempt)
{
std::string filePathAlt = StringHelper::Replace(filePath, "/", "\\");
attempt |= SFileOpenFileEx(mainMPQ, filePathAlt.c_str(), 0, &fileHandle);
}*/
//if (!attempt)
//{
//std::string filePathAlt = StringHelper::Replace(filePath, "/", "\\");
//attempt |= SFileOpenFileEx(mainMPQ, filePathAlt.c_str(), 0, &fileHandle);
//}
if (!attempt) {
printf("({%i}) Failed to open file {%s} from mpq archive {%s}", GetLastError(), filePath.c_str(), MainPath.c_str());

View File

@ -13,8 +13,8 @@ namespace Ship
entry->unk_bit26 = reader->ReadByte();
entry->unk_bit25 = reader->ReadByte();
uint32_t dataSize = reader->ReadInt32();
int dataSize = reader->ReadInt32();
for (uint32_t i = 0; i < dataSize; i++)
entry->data.push_back(reader->ReadUByte());
@ -22,7 +22,7 @@ namespace Ship
entry->loop.end = reader->ReadUInt32();
entry->loop.count = reader->ReadUInt32();
uint32_t loopStateCnt = reader->ReadUInt32();
int loopStateCnt = reader->ReadUInt32();
for (uint32_t i = 0; i < loopStateCnt; i++)
entry->loop.states.push_back(reader->ReadInt16());
@ -30,7 +30,7 @@ namespace Ship
entry->book.order = reader->ReadInt32();
entry->book.npredictors = reader->ReadInt32();
uint32_t bookSize = reader->ReadInt32();
int bookSize = reader->ReadInt32();
for (uint32_t i = 0; i < bookSize; i++)
entry->book.books.push_back(reader->ReadInt16());
@ -61,7 +61,7 @@ namespace Ship
drum.loaded = reader->ReadUByte();
drum.env = ReadEnvelopeData(reader);
bool hasSample = reader->ReadByte();
drum.sampleFileName = reader->ReadString();
drum.tuning = reader->ReadSingle();
@ -80,7 +80,7 @@ namespace Ship
entry.releaseRate = reader->ReadUByte();
entry.env = ReadEnvelopeData(reader);
{
bool hasSFEntry = reader->ReadByte();

View File

@ -149,8 +149,7 @@ namespace Ship
int PulseAudioPlayer::GetDesiredBuffered()
{
// return 1100;
return 1680;
return 2480;
}
void PulseAudioPlayer::Play(const uint8_t* buff, uint32_t len)

View File

@ -30,9 +30,9 @@ namespace Ship
Array = 0x4F415252, // OARR
Text = 0x4F545854, // OTXT
Blob = 0x4F424C42, // OBLB
Audio = 0x4F415544, // OAUD
AudioSample = 0x4F534D50, // OSMP
AudioSoundFont = 0x4F534654, // OSFT
Audio = 'OAUD',
AudioSample = 'OSMP',
AudioSoundFont = 'OSFT',
};
enum class DataType

View File

@ -29,7 +29,7 @@ namespace Ship {
}
int SDLAudioPlayer::GetDesiredBuffered(void) {
return 1680;
return 2480;
}
void SDLAudioPlayer::Play(const uint8_t* Buffer, uint32_t BufferLen) {

View File

@ -81,7 +81,7 @@ namespace Ship {
}
int WasapiAudioPlayer::GetDesiredBuffered(void) {
return 1680;
return 2480;
}
void WasapiAudioPlayer::Play(const uint8_t* Buffer, uint32_t BufferLen) {

View File

@ -1,7 +1,7 @@
<Root>
<File Name="code" OutName="audio" RangeStart="0x0" RangeEnd="0x12CBB0">
<Audio Name="audio" Offset="0x00">
<Sequences>
<Audio Name="audio" Offset="0x00" SoundFontTableOffset="0x138290" SequenceTableOffset="0x1386C0" SampleBankTableOffset="0x138DB0" SequenceFontTableOffset="0x138500">
<Sequences>
<Sequence Name="000_Sound_Effects"/>
<Sequence Name="001_Ambient_Effects"/>
<Sequence Name="002_Hyrule_Field_Program"/>
@ -113,8 +113,6 @@
<Sequence Name="108_Timed_Minigame"/>
<Sequence Name="109_Cutscene_Effects"/>
</Sequences>
<Samples Bank="0">
<Sample Name="Bird Chirp 1">
<Offset Version="MQDebug" At="0"/>
@ -1171,7 +1169,7 @@
</Sample>
</Samples>
<Samples Bank="1">
<Sample Name="Ocarina">
<Sample Name="Ocarina_Bank1">
<Offset Version="MQDebug" At="0xFAD40"/>
</Sample>
<Sample Name="Accordion">
@ -1433,7 +1431,7 @@
<Offset Version="MQDebug" At="0"/>
</Sample>
</Samples>
<Samples Bank="3">
<Sample Name="Low Rumbling">
<Offset Version="MQDebug" At="0"/>
@ -1450,72 +1448,107 @@
<Sample Name="Organic Gurgling">
<Offset Version="MQDebug" At="0x16480"/>
</Sample>
</Samples>
<Samples Bank="4">
<Sample Name="Vocal Ohs">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Flute and Voice">
<Offset Version="MQDebug" At="0x6410"/>
</Sample>
<Sample Name="Off-Kilter Flute">
<Offset Version="MQDebug" At="0x72D0"/>
</Sample>
<Sample Name="Voice">
<Offset Version="MQDebug" At="0x8230"/>
</Sample>
<Sample Name="Melodic Wooden Clacking">
<Offset Version="MQDebug" At="0x9030"/>
</Sample>
</Samples>
</Samples>
<Samples Bank="4">
<Sample Name="Vocal Ohs">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Flute and Voice">
<Offset Version="MQDebug" At="0x6410"/>
</Sample>
<Sample Name="Off-Kilter Flute">
<Offset Version="MQDebug" At="0x72D0"/>
</Sample>
<Sample Name="Voice">
<Offset Version="MQDebug" At="0x8230"/>
</Sample>
<Sample Name="Melodic Wooden Clacking">
<Offset Version="MQDebug" At="0x9030"/>
</Sample>
</Samples>
<Samples Bank="5">
<Sample Name="Goron Drum">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Bass Slap">
<Offset Version="MQDebug" At="0x2540"/>
</Sample>
<Sample Name="Goron Ooh">
<Offset Version="MQDebug" At="0x4800"/>
</Sample>
<Sample Name="Goron Ooh (High)">
<Offset Version="MQDebug" At="0x72D0"/>
</Sample>
<Sample Name="Tom Drum">
<Offset Version="MQDebug" At="0x7B70"/>
</Sample>
<Sample Name="Resonant Bass Marimba">
<Offset Version="MQDebug" At="0x8630"/>
</Sample>
</Samples>
<Samples Bank="5">
<Sample Name="Goron Drum">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Bass Slap">
<Offset Version="MQDebug" At="0x2540"/>
</Sample>
<Sample Name="Goron Ooh">
<Offset Version="MQDebug" At="0x4800"/>
</Sample>
<Sample Name="Goron Ooh (High)">
<Offset Version="MQDebug" At="0x72D0"/>
</Sample>
<Sample Name="Tom Drum">
<Offset Version="MQDebug" At="0x7B70"/>
</Sample>
<Sample Name="Resonant Bass Marimba">
<Offset Version="MQDebug" At="0x8630"/>
</Sample>
</Samples>
<Samples Bank="6">
<Sample Name="Warm Synth Pad">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Egyptian Flute">
<Offset Version="MQDebug" At="0xB0D0"/>
</Sample>
<Sample Name="Tom Drum">
<Offset Version="MQDebug" At="0xE120"/>
</Sample>
<Sample Name="Vocal Synth">
<Offset Version="MQDebug" At="0x103E0"/>
</Sample>
<Sample Name="Gong">
<Offset Version="MQDebug" At="0x12EB0"/>
</Sample>
<Sample Name="Bass Slap">
<Offset Version="MQDebug" At="0x1D3E0"/>
</Sample>
<Sample Name="Windchimes">
<Offset Version="MQDebug" At="0x22EE0"/>
</Sample>
</Samples>
<Samples Bank="6">
<Sample Name="Warm Synth Pad">
<Offset Version="MQDebug" At="0"/>
</Sample>
<Sample Name="Egyptian Flute">
<Offset Version="MQDebug" At="0xB0D0"/>
</Sample>
<Sample Name="Tom Drum">
<Offset Version="MQDebug" At="0xE120"/>
</Sample>
<Sample Name="Vocal Synth">
<Offset Version="MQDebug" At="0x103E0"/>
</Sample>
<Sample Name="Gong">
<Offset Version="MQDebug" At="0x12EB0"/>
</Sample>
<Sample Name="Bass Slap">
<Offset Version="MQDebug" At="0x1D3E0"/>
</Sample>
<Sample Name="Windchimes">
<Offset Version="MQDebug" At="0x22EE0"/>
</Sample>
</Samples>
<Soundfont Name="02_Ambient_Sounds" Index="2"/>
<Soundfont Name="37_Unused_Deku_Tree" Index="37" OverrideSampleBank="2"/>
<Soundfont Name="04_Deku_Tree" Index="4"/>
<Soundfont Name="11_Dodongos_Cavern" Index="11"/>
<Soundfont Name="33_Ending_1" Index="33"/>
<Soundfont Name="34_Ending_2" Index="34"/>
<Soundfont Name="09_Fairy_Fountain" Index="9"/>
<Soundfont Name="10_Fire_Temple" Index="10"/>
<Soundfont Name="12_Forest_Temple" Index="12"/>
<Soundfont Name="35_Game_Over" Index="35"/>
<Soundfont Name="30_Ganons_Castle_Organ" Index="30"/>
<Soundfont Name="31_Ganons_Castle" Index="31"/>
<Soundfont Name="32_Ganondorfs_Battle" Index="32"/>
<Soundfont Name="27_Gerudo_Valley" Index="27"/>
<Soundfont Name="14_Goron_City" Index="14"/>
<Soundfont Name="17_Horse_Race" Index="17"/>
<Soundfont Name="23_Ice_Cavern" Index="23"/>
<Soundfont Name="07_Jabu_Jabu" Index="7"/>
<Soundfont Name="36_Kaepora_Gaeboras_Theme" Index="36"/>
<Soundfont Name="08_Child_Kakariko_Village" Index="8"/>
<Soundfont Name="15_Kokiri_Forest" Index="15"/>
<Soundfont Name="29_Kotake_and_Koumes_Theme" Index="29"/>
<Soundfont Name="28_Lakeside_Laboratory" Index="28"/>
<Soundfont Name="19_Legends_of_Hyrule" Index="19"/>
<Soundfont Name="13_Lon_Lon_Ranch" Index="13"/>
<Soundfont Name="05_Market" Index="5"/>
<Soundfont Name="20_Minigames" Index="20"/>
<Soundfont Name="03_Orchestra" Index="3"/>
<Soundfont Name="24_Shadow_Temple" Index="24"/>
<Soundfont Name="22_Shops" Index="22"/>
<Soundfont Name="00_Sound_Effects_1" Index="0" Symbol="gSoundEffectsFont1"/>
<Soundfont Name="01_Sound_Effects_2" Index="1" Symbol="gSoundEffectsFont2"/>
<Soundfont Name="16_Spirit_Temple" Index="16"/>
<Soundfont Name="06_Title_Theme" Index="6"/>
<Soundfont Name="26_Unused" Index="26"/>
<Soundfont Name="18_Warp_Songs" Index="18"/>
<Soundfont Name="25_Water_Temple" Index="25"/>
<Soundfont Name="21_Zoras_Domain" Index="21"/>
</Audio>
</File>
</Root>
</Root>

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
#if defined(_WIN64) || defined(__x86_64__) || defined(__arm64__)
#define _SOH64
#define AUDIO_HEAP_SIZE 0xF0000
#define AUDIO_HEAP_SIZE 0x3800000
#else
#define AUDIO_HEAP_SIZE 0x38000
#define AUDIO_HEAP_SIZE 0x3800000
#endif
#define SYSTEM_HEAP_SIZE (1024 * 1024 * 4)

View File

@ -21,6 +21,7 @@
#define CALC_RESAMPLE_FREQ(sampleRate) ((float)sampleRate / (s32)gAudioContext.audioBufferParameters.frequency)
extern bool gUseLegacySD;
extern char* fontMap[256];
typedef enum {
/* 0 */ ADSR_STATE_DISABLED,
@ -124,8 +125,7 @@ typedef struct {
/* 0x08 */ s16 book[1]; // size 8 * order * npredictors. 8-byte aligned
} AdpcmBook; // size >= 0x8
typedef struct
{
typedef struct {
union {
struct {
/* 0x00 */ u32 codec : 4;
@ -233,6 +233,7 @@ typedef struct {
/* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums;
/* 0x10 */ SoundFontSound* soundEffects;
s32 fntIndex;
} SoundFont; // size = 0x14
typedef struct {

View File

@ -338,7 +338,6 @@ extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize)
str[lst.get()[0][i].size()] = '\0';
result[i] = str;
}
*resultSize = lst->size();
return result;
@ -567,20 +566,8 @@ extern "C" Vtx* ResourceMgr_LoadVtxByName(const char* path)
return (Vtx*)res->vertices.data();
}
extern "C" SequenceData ResourceMgr_LoadSeqByID(int seqID) {
if (seqID == 0xFF) {
SequenceData sDat;
sDat.numFonts = 0;
return sDat;
}
std::string fmtStr = "audio/sequences/seq_%02X";
return ResourceMgr_LoadSeqByName(StringHelper::Sprintf(fmtStr.c_str(), seqID).c_str());
}
extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) {
extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path)
{
auto file = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(path).get();
char* data = file->buffer.get();
@ -602,9 +589,8 @@ extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) {
std::map<std::string, SoundFontSample*> cachedCustomSFs;
extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) {
//auto str = StringHelper::Sprintf("audio/samples/sample_%08X", romOffset);
extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path)
{
if (std::string(path) == "")
return nullptr;
@ -618,7 +604,7 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) {
if (strem2[0] == 'R' && strem2[1] == 'I' && strem2[2] == 'F' && strem2[3] == 'F')
{
SoundFontSample* sampleC = new SoundFontSample;
SoundFontSample* sampleC = (SoundFontSample*)malloc(sizeof(SoundFontSample));
*strem++; // RIFF
*strem++; // size
@ -653,10 +639,13 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) {
if (sample == nullptr)
return NULL;
if (sample->cachedGameAsset != nullptr) {
if (sample->cachedGameAsset != nullptr)
{
SoundFontSample* sampleC = (SoundFontSample*)sample->cachedGameAsset;
return (SoundFontSample*)sample->cachedGameAsset;
} else {
}
else
{
SoundFontSample* sampleC = (SoundFontSample*)malloc(sizeof(SoundFontSample));
sampleC->sampleAddr = sample->data.data();
@ -690,10 +679,9 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) {
}
}
extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex) {
extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(const char* path) {
auto soundFont =
std::static_pointer_cast<Ship::AudioSoundFont>(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(
StringHelper::Sprintf("audio/fonts/font_%02X", fontIndex)));
std::static_pointer_cast<Ship::AudioSoundFont>(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path));
if (soundFont == nullptr)
return NULL;
@ -706,6 +694,7 @@ extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex) {
{
SoundFont* soundFontC = (SoundFont*)malloc(sizeof(SoundFont));
soundFontC->fntIndex = soundFont->id;
soundFontC->numDrums = soundFont->drums.size();
soundFontC->numInstruments = soundFont->instruments.size();
soundFontC->numSfx = soundFont->soundEffects.size();
@ -796,8 +785,7 @@ extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex) {
}
soundFontC->instruments[i] = inst;
} else
{
} else {
soundFontC->instruments[i] = nullptr;
}
}

View File

@ -50,8 +50,7 @@ Gfx* ResourceMgr_PatchGfxByName(const char* path, int size);
char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path);
Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc);
Vtx* ResourceMgr_LoadVtxByName(const char* path);
SoundFont* ResourceMgr_LoadAudioSoundFont(int fontIndex);
SequenceData ResourceMgr_LoadSeqByID(int seqID);
SoundFont* ResourceMgr_LoadAudioSoundFont(const char* path);
SequenceData ResourceMgr_LoadSeqByName(const char* path);
SoundFontSample* ResourceMgr_LoadAudioSample(const char* path);
CollisionHeader* ResourceMgr_LoadColByName(const char* path);

View File

@ -10,10 +10,10 @@ const s16 D_8014A6C0[] = {
0x0030, // gTatumsPerBeat
};
#ifdef _SOH64
const AudioContextInitSizes D_8014A6C4 = { 0x57F00, 0x2E0E0, 0xFCE0 };
#ifdef _SOH64 // OTRTODO: This might be overkill...
const AudioContextInitSizes D_8014A6C4 = { 0x37F000, 0xE0E00, 0xBCE00 };
#else
const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 };
const AudioContextInitSizes D_8014A6C4 = { 0x37F000, 0xE0E00, 0xBCE00 };
#endif
ReverbSettings D_80133420[][3] = {

View File

@ -288,7 +288,6 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) {
s32 AudioLoad_IsFontLoadComplete(s32 fontId) {
return true;
if (fontId == 0xFF) {
return true;
@ -390,7 +389,6 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) {
while (numFonts > 0) {
fontId = gAudioContext.sequenceFontTable[index++];
font = AudioLoad_SyncLoadFont(fontId);
numFonts--;
}
@ -597,7 +595,9 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
numFonts--;
}
} else {
}
else
{
SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
for (int i = 0; i < seqData2.numFonts; i++)
@ -609,14 +609,12 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
}
seqData = AudioLoad_SyncLoadSeq(seqId);
if (seqData == NULL) {
return 0;
}
AudioSeq_ResetSequencePlayer(seqPlayer);
seqPlayer->seqId = seqId;
if (gUseLegacySD)
seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId);
else
@ -693,7 +691,8 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) {
}
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont
(fontMap[fontId]);
sampleBankId1 = sf->sampleBankId1;
sampleBankId2 = sf->sampleBankId2;
@ -748,20 +747,25 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
char* seqData = 0;
SoundFont* fnt;
if (!gUseLegacySD && tableType == SEQUENCE_TABLE) {
if (!gUseLegacySD && tableType == SEQUENCE_TABLE)
{
SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]);
seqData = sData.seqData;
size = sData.seqDataSize;
medium = sData.medium;
cachePolicy = sData.cachePolicy;
romAddr = 0;
} else if (!gUseLegacySD && tableType == FONT_TABLE) {
fnt = ResourceMgr_LoadAudioSoundFont(id);
}
else if (!gUseLegacySD && tableType == FONT_TABLE)
{
fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]);
size = sizeof(SoundFont);
medium = 2;
cachePolicy = 0;
romAddr = 0;
} else {
}
else
{
table = AudioLoad_GetLoadTable(tableType);
size = table->entries[realId].size;
size = ALIGN16(size);
@ -832,7 +836,8 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
return ret;
}
u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) {
u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id)
{
if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE) && !gUseLegacySD) {
return id;
}
@ -891,7 +896,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
Drum* drum;
SoundFontSound* sfx;
s32 i;
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = NULL;
s32 numDrums = 0;
s32 numInstruments = 0;
@ -902,6 +907,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
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;
@ -909,7 +915,8 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo
void** ptrs = (void**)mem;
#define BASE_OFFSET(x) (void*)((uintptr_t)(x) + (uintptr_t)(mem))
#define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem))
reloc2 = ptrs[0];
if (1) {}
@ -1421,12 +1428,11 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
if (gUseLegacySD)
numFonts = gAudioContext.soundFontTable->numEntries;
else
numFonts = 0x26; // OTRTODO: Count the number of soundfonts that are inside the OTR(s)
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont));
if (gUseLegacySD)
{
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont));
if (gUseLegacySD) {
for (i = 0; i < numFonts; i++) {
AudioLoad_InitSoundFontMeta(i);
}
@ -1448,9 +1454,27 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
free(seqList);
int bp = 0;
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;
}
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
// *((u32*)&D_8014A6C4.permanentPoolSize) = 0;
@ -1884,7 +1908,8 @@ void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocIn
void* reloc;
// NOTE: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works.
if ((uintptr_t)sound->sample < maxSoundBankSize || !gUseLegacySD) {
if ((uintptr_t)sound->sample < maxSoundBankSize || !gUseLegacySD)
{
if (!gUseLegacySD) {
SoundFontSample* sample2 = sound;
} else {
@ -2170,7 +2195,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo
gAudioContext.numUsedSamples = 0;
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
numDrums = sf->numDrums;
numInstruments = sf->numInstruments;
@ -2307,7 +2332,7 @@ void AudioLoad_LoadPermanentSamples(void) {
//fontId = gAudioContext.permanentCache[i].id;
if (!gUseLegacySD) {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
relocInfo.sampleBankId1 = sf->sampleBankId1;
relocInfo.sampleBankId2 = sf->sampleBankId2;
} else {

View File

@ -286,11 +286,11 @@ void Audio_ProcessNotes(void) {
}
subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
f32 resampRate = gAudioContext.audioBufferParameters.resampleRate;
if (!gUseLegacySD && !noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL &&
noteSubEu2->sound.soundFontSound->sample != NULL &&
noteSubEu2->sound.soundFontSound->sample != NULL &&
noteSubEu2->sound.soundFontSound->sample->sampleRateMagicValue == 'RIFF') {
resampRate = CALC_RESAMPLE_FREQ(noteSubEu2->sound.soundFontSound->sample->sampleRate);
}
@ -320,7 +320,7 @@ SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) {
Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
Instrument* inst;
if (fontId == 0xFF) {
return NULL;
}
@ -342,7 +342,7 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
return NULL;
}
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
if (instId >= sf->numInstruments)
return NULL;
@ -354,7 +354,7 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
return inst;
}
return inst;
}
@ -379,7 +379,7 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
drum = gAudioContext.soundFonts[fontId].drums[drumId];
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
drum = sf->drums[drumId];
}
@ -410,7 +410,7 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId];
} else {
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontId);
SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]);
sfx = &sf->soundEffects[sfxId];
}

View File

@ -4,7 +4,8 @@
#include "global.h"
extern bool gUseLegacySD;
extern char* sequenceMap[512];
extern char* sequenceMap[256];
char* fontMap[256];
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
#define PORTAMENTO_MODE(x) ((x).mode & ~0x80)