mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Finished the stupid audio extraction
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
std::unordered_map<AudioTableType, std::unordered_map<uint32_t, AudioTableEntry>> AudioContext::tables;
|
||||
std::unordered_map<AudioTableType, std::vector<uint8_t>> AudioContext::data;
|
||||
std::unordered_map<AudioTableType, std::shared_ptr<AudioTableData>> AudioContext::tableData;
|
||||
std::unordered_map<AudioTableType, uint32_t> AudioContext::tableOffsets;
|
||||
|
||||
std::optional<std::shared_ptr<IParsedData>> AudioContextFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
|
||||
auto seq = GetSafeNode<YAML::Node>(node, "audio_seq");
|
||||
@@ -23,6 +24,10 @@ std::optional<std::shared_ptr<IParsedData>> AudioContextFactory::parse(std::vect
|
||||
AudioContext::data[AudioTableType::FONT_TABLE] = std::vector<uint8_t>(buffer.begin() + bankOffset, buffer.begin() + bankOffset + bankSize);
|
||||
AudioContext::data[AudioTableType::SAMPLE_TABLE] = std::vector<uint8_t>(buffer.begin() + tableOffset, buffer.begin() + tableOffset + tableSize);
|
||||
|
||||
AudioContext::tableOffsets[AudioTableType::SEQ_TABLE] = seqOffset;
|
||||
AudioContext::tableOffsets[AudioTableType::FONT_TABLE] = bankOffset;
|
||||
AudioContext::tableOffsets[AudioTableType::SAMPLE_TABLE] = tableOffset;
|
||||
|
||||
SPDLOG_INFO("Sequence Table 0x{:X}", seqOffset);
|
||||
SPDLOG_INFO("Sound Font Table 0x{:X}", bankOffset);
|
||||
SPDLOG_INFO("Sample Bank Table 0x{:X}", tableOffset);
|
||||
@@ -73,6 +78,7 @@ uint64_t AudioContext::GetPathByAddr(uint32_t addr) {
|
||||
SPDLOG_INFO("Found path of 0x{:X} {}", addr, path);
|
||||
return hash;
|
||||
} else {
|
||||
SPDLOG_INFO("Failed to find path for 0x{:X}", addr);
|
||||
throw std::runtime_error("Failed to find node by addr");
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
static std::unordered_map<AudioTableType, std::unordered_map<uint32_t, AudioTableEntry>> tables;
|
||||
static std::unordered_map<AudioTableType, std::shared_ptr<AudioTableData>> tableData;
|
||||
static std::unordered_map<AudioTableType, std::vector<uint8_t>> data;
|
||||
static std::unordered_map<AudioTableType, uint32_t> tableOffsets;
|
||||
|
||||
static LUS::BinaryReader MakeReader(AudioTableType type, uint32_t offset);
|
||||
static TunedSample LoadTunedSample(LUS::BinaryReader& reader, uint32_t parent, uint32_t sampleBankId);
|
||||
|
||||
@@ -73,16 +73,19 @@ ExportResult AudioTableBinaryExporter::Export(std::ostream &write, std::shared_p
|
||||
auto data = std::static_pointer_cast<AudioTableData>(raw);
|
||||
|
||||
WriteHeader(writer, Torch::ResourceType::AudioTable, 0);
|
||||
writer.Write((uint8_t) data->type);
|
||||
writer.Write(data->medium);
|
||||
writer.Write(data->addr);
|
||||
writer.Write((uint32_t) data->entries.size());
|
||||
|
||||
for(auto& entry : data->entries){
|
||||
if(data->type != AudioTableType::SAMPLE_TABLE){
|
||||
writer.Write(AudioContext::GetPathByAddr(entry.addr));
|
||||
if(data->type == AudioTableType::FONT_TABLE && entry.crc == 0){
|
||||
throw std::runtime_error("Fuck this thing");
|
||||
}
|
||||
if(entry.size == 0){
|
||||
auto item = AudioContext::tableData[AudioTableType::SEQ_TABLE]->entries[entry.addr];
|
||||
writer.Write(item.crc);
|
||||
} else {
|
||||
writer.Write((uint64_t) entry.addr);
|
||||
writer.Write(entry.crc);
|
||||
}
|
||||
writer.Write(entry.size);
|
||||
writer.Write(entry.medium);
|
||||
@@ -121,6 +124,8 @@ std::optional<std::shared_ptr<IParsedData>> AudioTableFactory::parse(std::vector
|
||||
SPDLOG_INFO("addr: {}", baddr);
|
||||
|
||||
std::vector<AudioTableEntry> entries;
|
||||
auto parent = AudioContext::tableOffsets[AudioTableType::SEQ_TABLE];
|
||||
|
||||
for(size_t i = 0; i < count; i++){
|
||||
auto addr = reader.ReadUInt32();
|
||||
auto size = reader.ReadUInt32();
|
||||
@@ -129,8 +134,7 @@ std::optional<std::shared_ptr<IParsedData>> AudioTableFactory::parse(std::vector
|
||||
auto sd1 = reader.ReadInt16();
|
||||
auto sd2 = reader.ReadInt16();
|
||||
auto sd3 = reader.ReadInt16();
|
||||
auto entry = AudioTableEntry { addr, size, medium, policy, sd1, sd2, sd3 };
|
||||
entries.push_back(entry);
|
||||
uint64_t crc = 0;
|
||||
|
||||
switch (type) {
|
||||
case AudioTableType::FONT_TABLE: {
|
||||
@@ -138,17 +142,26 @@ std::optional<std::shared_ptr<IParsedData>> AudioTableFactory::parse(std::vector
|
||||
font["type"] = "NAUDIO:V1:SOUND_FONT";
|
||||
font["offset"] = addr;
|
||||
Companion::Instance->AddAsset(font);
|
||||
std::string path = font["vpath"].as<std::string>();
|
||||
crc = CRC64(path.c_str());
|
||||
break;
|
||||
}
|
||||
case AudioTableType::SEQ_TABLE: {
|
||||
YAML::Node seq;
|
||||
seq["type"] = "NAUDIO:V1:SEQUENCE";
|
||||
seq["offset"] = addr;
|
||||
Companion::Instance->AddAsset(seq);
|
||||
break;
|
||||
if(size != 0){
|
||||
YAML::Node seq;
|
||||
seq["type"] = "BLOB";
|
||||
seq["offset"] = parent + addr;
|
||||
seq["size"] = size;
|
||||
Companion::Instance->AddAsset(seq);
|
||||
std::string path = seq["vpath"].as<std::string>();
|
||||
crc = CRC64(path.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto entry = AudioTableEntry { addr, size, medium, policy, sd1, sd2, sd3, crc };
|
||||
entries.push_back(entry);
|
||||
AudioContext::tables[type][addr] = entry;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ struct AudioTableEntry {
|
||||
int16_t shortData1;
|
||||
int16_t shortData2;
|
||||
int16_t shortData3;
|
||||
uint64_t crc;
|
||||
};
|
||||
|
||||
enum class AudioTableType {
|
||||
|
||||
@@ -29,7 +29,7 @@ ExportResult ADPCMLoopBinaryExporter::Export(std::ostream &write, std::shared_pt
|
||||
writer.Write(data->count);
|
||||
if(data->count != 0){
|
||||
for(size_t i = 0; i < 16; i++){
|
||||
writer.Write(data->predictorState[i]);
|
||||
writer.Write(data->predictorState[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ ExportResult NSampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<
|
||||
auto entry = AudioContext::tableData[AudioTableType::SAMPLE_TABLE]->entries[data->sampleBankId];
|
||||
auto buffer = AudioContext::data[AudioTableType::SAMPLE_TABLE];
|
||||
|
||||
writer.Write((uint32_t) data->size);
|
||||
writer.Write((char*) buffer.data() + data->sampleAddr, data->size);
|
||||
writer.Write((char*) buffer.data() + entry.addr + data->sampleAddr, data->size);
|
||||
|
||||
writer.Finish(write);
|
||||
return std::nullopt;
|
||||
|
||||
@@ -47,19 +47,19 @@ ExportResult SoundFontCodeExporter::Export(std::ostream &write, std::shared_ptr<
|
||||
}
|
||||
|
||||
ExportResult SoundFontBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
auto writer = LUS::BinaryWriter();
|
||||
auto data = std::static_pointer_cast<SoundFontData>(raw);
|
||||
auto writer = LUS::BinaryWriter();
|
||||
auto data = std::static_pointer_cast<SoundFontData>(raw);
|
||||
|
||||
WriteHeader(writer, Torch::ResourceType::SoundFont, 0);
|
||||
writer.Write(data->numInstruments);
|
||||
writer.Write(data->numDrums);
|
||||
writer.Write(data->sampleBankId1);
|
||||
writer.Write(data->sampleBankId2);
|
||||
WriteHeader(writer, Torch::ResourceType::SoundFont, 0);
|
||||
writer.Write(data->numInstruments);
|
||||
writer.Write(data->numDrums);
|
||||
writer.Write(data->sampleBankId1);
|
||||
writer.Write(data->sampleBankId2);
|
||||
|
||||
for(auto& instrument : data->instruments){
|
||||
auto crc = AudioContext::GetPathByAddr(instrument);
|
||||
writer.Write(crc);
|
||||
}
|
||||
for(auto& instrument : data->instruments){
|
||||
auto crc = AudioContext::GetPathByAddr(instrument);
|
||||
writer.Write(crc);
|
||||
}
|
||||
|
||||
for(auto& drum : data->drums){
|
||||
auto crc = AudioContext::GetPathByAddr(drum);
|
||||
|
||||
Reference in New Issue
Block a user