Skip to content

Commit

Permalink
Fixed aiff sample extraction and sample name
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Nov 30, 2024
1 parent 1d485d7 commit e466f58
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/Companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/factories/naudio/v0/AudioHeaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/factories/naudio/v0/AudioHeaderFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,11 +24,11 @@ class AudioHeaderFactory : public BaseFactory {
}
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 changes: 4 additions & 0 deletions src/factories/naudio/v0/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 1 addition & 0 deletions src/factories/naudio/v0/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class AudioManager {
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:
Expand Down
20 changes: 20 additions & 0 deletions src/factories/naudio/v0/SampleFactory.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/factories/naudio/v0/SampleFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +26,10 @@ class SampleFactory : public BaseFactory {
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; }
};

0 comments on commit e466f58

Please sign in to comment.