Fixed aiff sample extraction and sample name

This commit is contained in:
KiritoDv
2024-11-29 22:11:39 -06:00
parent 1d485d7695
commit e466f58b2c
7 changed files with 46 additions and 6 deletions
+2 -3
View File
@@ -573,7 +573,7 @@ void Companion::ProcessFile(YAML::Node root) {
if(assetNode["type"]){
const auto type = GetSafeNode<std::string>(assetNode, "type");
if(type == "SAMPLE"){
if(type == "NAUDIO:V0:SAMPLE"){
AudioManager::Instance->bind_sample(assetNode, output);
}
}
@@ -597,10 +597,9 @@ void Companion::ProcessFile(YAML::Node root) {
auto output = (this->gCurrentDirectory / entryName).string();
std::replace(output.begin(), output.end(), '\\', '/');
if(node["type"]){
const auto type = GetSafeNode<std::string>(node, "type");
if(type == "SAMPLE"){
if(type == "NAUDIO:V0:SAMPLE"){
AudioManager::Instance->bind_sample(node, output);
}
}
@@ -6,6 +6,7 @@
#include "spdlog/spdlog.h"
#include <factories/naudio/v1/AudioConverter.h>
/*
ExportResult AudioAIFCExporter::Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) {
auto samples = AudioManager::Instance->get_samples();
@@ -26,11 +27,16 @@ ExportResult AudioAIFCExporter::Export(std::ostream& write, std::shared_ptr<IPar
aifc.Close();
aiff.Finish(file);
file.close();
SPDLOG_INFO("Exported {}", dpath + "_bank_" + std::to_string(temp) + ".aiff");
// SPDLOG_INFO("Exported {}", dpath + "_bank_" + std::to_string(temp) + ".aiff");
SPDLOG_INFO("sample_{}:", temp);
SPDLOG_INFO(" type: NAUDIO:V0:SAMPLE");
SPDLOG_INFO(" id: {}\n", temp);
}
return std::nullopt;
}
*/
std::optional<std::shared_ptr<IParsedData>> AudioHeaderFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) {
AudioManager::Instance->initialize(buffer, data);
+4 -2
View File
@@ -2,10 +2,12 @@
#include <factories/BaseFactory.h>
/*
class AudioAIFCExporter : public BaseExporter {
public:
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement);
};
*/
class AudioDummyExporter : public BaseExporter {
public:
@@ -22,11 +24,11 @@ public:
}
std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Modding, AudioAIFCExporter)
// REGISTER(Modding, AudioGenericAIFCExporter)
REGISTER(Header, AudioDummyExporter)
REGISTER(Binary, AudioDummyExporter)
REGISTER(Code, AudioDummyExporter)
};
}
bool SupportModdedAssets() override { return true; }
bool HasModdedDependencies() override { return true; }
};
+4
View File
@@ -545,6 +545,10 @@ std::map<uint32_t, Bank> AudioManager::get_banks() {
return this->banks;
}
std::vector<SampleBank*> AudioManager::get_loaded_banks() {
return this->loaded_tbl.banks;
}
std::vector<AudioBankSample*> AudioManager::get_samples() {
std::vector<AudioBankSample*> samples;
for(auto &bank : this->loaded_tbl.banks){
+1
View File
@@ -129,6 +129,7 @@ public:
std::string& get_sample(uint32_t id);
AudioBankSample get_aifc(int32_t index);
std::map<uint32_t, Bank> get_banks();
std::vector<SampleBank*> get_loaded_banks();
std::vector<AudioBankSample*> get_samples();
uint32_t get_index(AudioBankSample* bank);
private:
+20
View File
@@ -1,5 +1,25 @@
#include "SampleFactory.h"
#include <vector>
#include "Companion.h"
#include "AIFCDecode.h"
#include "spdlog/spdlog.h"
#include <factories/naudio/v1/AudioConverter.h>
ExportResult SampleModdingExporter::Export(std::ostream& writer, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node& node, std::string* replacement) {
auto sample = std::static_pointer_cast<SampleData>(raw);
*replacement += ".aiff";
LUS::BinaryWriter aifc = LUS::BinaryWriter();
AudioConverter::SampleV0ToAIFC(&sample->mSample, aifc);
LUS::BinaryWriter aiff = LUS::BinaryWriter();
write_aiff(aifc.ToVector(), aiff);
aifc.Close();
aiff.Finish(writer);
return std::nullopt;
}
ExportResult SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
auto sample = std::static_pointer_cast<SampleData>(raw)->mSample;
+8
View File
@@ -5,6 +5,11 @@
#include <factories/BaseFactory.h>
#include "AudioManager.h"
class SampleModdingExporter : public BaseExporter {
public:
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement);
};
class SampleData : public IParsedData {
public:
AudioBankSample mSample;
@@ -21,7 +26,10 @@ public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Modding, SampleModdingExporter)
REGISTER(Binary, SampleBinaryExporter)
};
}
bool SupportModdedAssets() override { return true; }
};