diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2022-06-10 13:37:50 -0400 |
|---|---|---|
| committer | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2022-06-16 20:35:52 -0400 |
| commit | c49cee352111acc5f2a831ba2f7a46a627785eff (patch) | |
| tree | d1a39b7f0c7cbcb3910f33e7963db45a44e9d31a /ZAPDTR/ZAPD/ZAudio.cpp | |
| parent | b3e299dbdee829c12ada556a1c3aa1f109a0e05b (diff) | |
Audio support nearly complete.
Diffstat (limited to 'ZAPDTR/ZAPD/ZAudio.cpp')
| -rw-r--r-- | ZAPDTR/ZAPD/ZAudio.cpp | 125 |
1 files changed, 101 insertions, 24 deletions
diff --git a/ZAPDTR/ZAPD/ZAudio.cpp b/ZAPDTR/ZAPD/ZAudio.cpp index 1c24c824a..63443de34 100644 --- a/ZAPDTR/ZAPD/ZAudio.cpp +++ b/ZAPDTR/ZAPD/ZAudio.cpp @@ -13,6 +13,54 @@ ZAudio::ZAudio(ZFile* nParent) : ZResource(nParent) { //RegisterRequiredAttribute("CodeOffset"); //RegisterOptionalAttribute("LangOffset", "0"); + +} + +void ZAudio::ParseXML(tinyxml2::XMLElement* reader) +{ + ZResource::ParseXML(reader); + + auto t = reader->Name(); + + auto child = reader->FirstChildElement(); + + while (child != nullptr) + { + int bp = 0; + if (std::string(child->Value()) == "Sequences") + { + auto seqChild = child->FirstChildElement(); + + while (seqChild != nullptr) + { + if (std::string(seqChild->Value()) == "Sequence") + { + seqNames.push_back(seqChild->Attribute("Name")); + } + + seqChild = seqChild->NextSiblingElement(); + } + } + + if (std::string(child->Value()) == "Samples") + { + int bankId = child->IntAttribute("Bank", 0); + auto sampChild = child->FirstChildElement(); + + while (sampChild != nullptr) + { + if (std::string(sampChild->Value()) == "Sample") + { + auto atStr = sampChild->FirstChildElement()->Attribute("At"); + sampleOffsets[bankId][StringHelper::StrToL(atStr, 16)] = sampChild->Attribute("Name"); + } + + sampChild = sampChild->NextSiblingElement(); + } + } + + child = child->NextSiblingElement(); + } } void ZAudio::DecodeADPCMSample(SampleEntry* sample) @@ -26,9 +74,6 @@ std::vector<AdsrEnvelope*> ZAudio::ParseEnvelopeData(std::vector<uint8_t> audioB { std::vector<AdsrEnvelope*> result; - //bool process = true; - - //for (int i = 0; i < 4; i++) while (true) { AdsrEnvelope* env = new AdsrEnvelope(); @@ -49,13 +94,13 @@ std::vector<AdsrEnvelope*> ZAudio::ParseEnvelopeData(std::vector<uint8_t> audioB SoundFontEntry* ZAudio::ParseSoundFontEntry(std::vector<uint8_t> audioBank, std::vector<uint8_t> audioTable, - AudioTableEntry audioSampleBankEntry, + AudioTableEntry audioSampleBankEntry, int bankIndex, int soundFontOffset, int baseOffset) { SoundFontEntry* soundFont = new SoundFontEntry(); soundFont->sampleEntry = ParseSampleEntry( - audioBank, audioTable, audioSampleBankEntry, + audioBank, audioTable, audioSampleBankEntry, bankIndex, BitConverter::ToInt32BE(audioBank, soundFontOffset + 0) + baseOffset, baseOffset); soundFont->tuning = BitConverter::ToFloatBE(audioBank, soundFontOffset + 4); @@ -64,7 +109,7 @@ SoundFontEntry* ZAudio::ParseSoundFontEntry(std::vector<uint8_t> audioBank, SampleEntry* ZAudio::ParseSampleEntry(std::vector<uint8_t> audioBank, std::vector<uint8_t> audioTable, - AudioTableEntry audioSampleBankEntry, + AudioTableEntry audioSampleBankEntry, int bankIndex, int sampleOffset, int baseOffset) { @@ -74,6 +119,8 @@ SampleEntry* ZAudio::ParseSampleEntry(std::vector<uint8_t> audioBank, { SampleEntry* sample = new SampleEntry(); + sample->bankId = bankIndex; + int sampleSize = BitConverter::ToInt32BE(audioBank, sampleOffset + 0) & 0x00FFFFFF; int loopOffset = BitConverter::ToInt32BE(audioBank, sampleOffset + 8) + baseOffset; int bookOffset = BitConverter::ToInt32BE(audioBank, sampleOffset + 12) + baseOffset; @@ -111,6 +158,9 @@ SampleEntry* ZAudio::ParseSampleEntry(std::vector<uint8_t> audioBank, BitConverter::ToInt16BE(audioBank, bookOffset + 8 + (i * 2))); } + sample->sampleDataOffset = sampleDataOffset; + sample->fileName = StringHelper::Sprintf("audio/samples/sample_%08X", sampleOffset); + samples[sampleOffset] = sample; return sample; @@ -173,15 +223,13 @@ void ZAudio::ParseSoundFont(std::vector<uint8_t> codeData, std::vector<uint8_t> { samplePtr += ptr; - drum.sample = ParseSampleEntry(codeData, audioTable, audioSampleBank[sampleBankId1], + drum.sample = ParseSampleEntry(codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, BitConverter::ToInt32BE(codeData, samplePtr + 4) + ptr, ptr); drum.releaseRate = codeData[samplePtr + 0]; drum.pan = codeData[samplePtr + 1]; drum.loaded = codeData[samplePtr + 2]; drum.tuning = BitConverter::ToFloatBE(codeData, samplePtr + 8); - - //int sampleDefOffset = BitConverter::ToInt32BE(codeData, samplePtr + 4); drum.env = ParseEnvelopeData(codeData, audioTable, BitConverter::ToInt32BE(codeData, samplePtr + 12) + ptr, ptr); } @@ -194,7 +242,7 @@ void ZAudio::ParseSoundFont(std::vector<uint8_t> codeData, std::vector<uint8_t> for (int i = 0; i < numSfx; i++) { SoundFontEntry* sfx; - sfx = ParseSoundFontEntry(codeData, audioTable, audioSampleBank[sampleBankId1], + sfx = ParseSoundFontEntry(codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, currentOffset, ptr); entry.soundEffects.push_back(sfx); @@ -221,16 +269,16 @@ void ZAudio::ParseSoundFont(std::vector<uint8_t> codeData, std::vector<uint8_t> if (BitConverter::ToInt32BE(codeData, currentOffset + 8) != 0) instrument.lowNotesSound = ParseSoundFontEntry( - codeData, audioTable, audioSampleBank[sampleBankId1], currentOffset + 8, ptr); + codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, currentOffset + 8, ptr); if (BitConverter::ToInt32BE(codeData, currentOffset + 16) != 0) instrument.normalNotesSound = ParseSoundFontEntry( - codeData, audioTable, audioSampleBank[sampleBankId1], currentOffset + 16, ptr); + codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, currentOffset + 16, ptr); if (BitConverter::ToInt32BE(codeData, currentOffset + 24) != 0 && instrument.normalRangeHi != 0x7F) instrument.highNotesSound = ParseSoundFontEntry( - codeData, audioTable, audioSampleBank[sampleBankId1], currentOffset + 24, ptr); + codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, currentOffset + 24, ptr); } entry.instruments.push_back(instrument); @@ -251,33 +299,69 @@ void ZAudio::ParseRawData() else codeData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() + "code"); + codeData = File::ReadAllBytes("baserom/code_ntsc"); + if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory) audioTableData = Globals::Instance->GetBaseromFile("Audiotable"); else audioTableData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() + "Audiotable"); + audioTableData = File::ReadAllBytes("baserom/Audiotable_ntsc"); + if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory) audioBankData = Globals::Instance->GetBaseromFile("Audiobank"); else audioBankData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() + "Audiobank"); + audioBankData = File::ReadAllBytes("baserom/Audiobank_ntsc"); + if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory) audioSeqData = Globals::Instance->GetBaseromFile("Audioseq"); else audioSeqData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() + "Audioseq"); + audioSeqData = File::ReadAllBytes("baserom/Audioseq_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 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 = 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 + + // 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 + soundFontTable = ParseAudioTable(codeData, gSoundFontTableOffset); sequenceTable = ParseAudioTable(codeData, gSequenceTableOffset); sampleBankTable = ParseAudioTable(codeData, gSampleBankTableOffset); - // int gSequenceFontTableOffset = 0x1384E0; // OTRTODO: Make this an XML Param + + // SEQEUNCE FONT TABLE PARSING + for (int i = 0; i < sequenceTable.size(); i++) + { + uint16_t idx = BitConverter::ToUInt16BE(codeData, gSequenceFontTableOffset + (i * 2)); + uint8_t numFonts = codeData[gSequenceFontTableOffset + (idx++)]; + std::vector<uint32_t> fontIds; + + for (int j = 0; j < numFonts; j++) + { + uint8_t fontId = codeData[gSequenceFontTableOffset + (idx++)]; + fontIds.push_back(fontId); + } + + fontIndices.push_back(fontIds); + } // SAMPLE/FONT PARSING @@ -286,13 +370,6 @@ void ZAudio::ParseRawData() ParseSoundFont(audioBankData, audioTableData, sampleBankTable, soundFontTable[i]); } - - // SOUNDBANK PARSING - /*for (int i = 0; i < sampleBankTable.size(); i++) - { - - }*/ - // SEQUENCE PARSING for (int i = 0; i < sequenceTable.size(); i++) { |
