summaryrefslogtreecommitdiff
path: root/src/factories/SampleFactory.cpp
diff options
context:
space:
mode:
authorLywx <kiritodev01@gmail.com>2023-11-15 15:11:15 -0600
committerGitHub <noreply@github.com>2023-11-15 15:11:15 -0600
commiteaddecd0b402c12a780831e3139d7a35e78322e6 (patch)
tree0c961e1ba2339f52892b54f44b8ff0018b77c382 /src/factories/SampleFactory.cpp
parenta66b259d7c10c3367a04819c6b55d47fb9a99f5e (diff)
Torch v0.1 (#12)
* Splitted version yamls and implemented wip geo and dlist extraction * Fixed linux compilation * Added PoC WSL 2 detection * Add undefined behaviour * Added gfxdis as submodule * update * Removed gfxdis as a submodule * Code works * Replace ByteSwap with BSWAP * Cleanup vertice factory * readability * readability 2 * Cleanup gfxfactory * last one * Rename name to symbol * More implementation * Implemented first PoC of C file generation * Added output formatting on factories * changes * Moved generated dlists onto their respective folder * Migrated more factories onto the new extractor system * Fully ported all factories and added header generation * Some updates * Added Lights factory * fix * Fixed vtx extraction * Lights work now * delete old startup_logo yaml * Generate all sections in single file * Added support to generate header and code for textures * Added O3 for release builds * Added WIP dlist extraction and moved to use f3dold microcode * Added segment support, autogeneration and fixed C generation * Added symbol names on display list extraction * Removed warnings * Moved back to transform and replace * Removed unnecesary macros * Added extraction order and reversed vtx order * Implemented true backwards sort * [WIP] Implemented runtime gbi, more headers and a few config features * Fix CLI11 on WSL and variety of fixes * Fixes * Update DisplayListFactory.h * Update TextureFactory.cpp * wip lights * fix * Correct callback * Added waypoints * Update ceremony_data.yml * Changes * Update TextureFactory.cpp * Update commandline args * Update comment * Remove printf * Update couple commands * Renamed cubeos to torch * Removed unused stuff and added an example config file --------- Co-authored-by: KiritoDv <kiritodev01@gmail.com> Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/factories/SampleFactory.cpp')
-rw-r--r--src/factories/SampleFactory.cpp66
1 files changed, 28 insertions, 38 deletions
diff --git a/src/factories/SampleFactory.cpp b/src/factories/SampleFactory.cpp
index 7e2d1a1..9b7c48f 100644
--- a/src/factories/SampleFactory.cpp
+++ b/src/factories/SampleFactory.cpp
@@ -1,46 +1,36 @@
#include "SampleFactory.h"
-
-#include <vector>
-#include "audio/AudioManager.h"
-
-bool SampleFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::vector<uint8_t>& buffer) {
- WRITE_HEADER(LUS::ResourceType::Sample, 0);
-
- auto id = data["id"].as<int32_t>();
- AudioBankSample entry = AudioManager::Instance->get_aifc(id);
-
- // Write AdpcmLoop
- WRITE_U32(entry.loop.start);
- WRITE_U32(entry.loop.end);
- WRITE_I32(entry.loop.count);
- WRITE_U32(entry.loop.pad);
-
- if(entry.loop.state.has_value()){
- std::vector<int16_t> state = entry.loop.state.value();
- WRITE_U32(state.size());
- for(auto &value : state){
- writer->Write(value);
- }
+#include "utils/MIODecoder.h"
+
+void 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;
+
+ WriteHeader(writer, LUS::ResourceType::Sample, 0);
+ writer.Write((uint32_t) sample.loop.start);
+ writer.Write((uint32_t) sample.loop.end);
+ writer.Write((uint32_t) sample.loop.count);
+ writer.Write((uint32_t) sample.loop.pad);
+
+ if(sample.loop.state.has_value()){
+ auto state = sample.loop.state.value();
+ writer.Write((uint32_t) state.size());
+ writer.Write((char*) state.data(), state.size() * sizeof(int16_t));
} else {
- WRITE_U32(0);
+ writer.Write((uint32_t) 0);
}
- // Write AdpcmBook
- WRITE_I32(entry.book.order);
- WRITE_I32(entry.book.npredictors);
-
- WRITE_U32(entry.book.table.size());
- for(auto &value : entry.book.table){
- writer->Write(value);
- }
+ writer.Write((uint32_t) sample.book.order);
+ writer.Write((uint32_t) sample.book.npredictors);
- // Write sample
- WRITE_I32(entry.data.size());
- for(auto &value : entry.data){
- WRITE_U8(value);
- }
+ writer.Write((uint32_t) sample.book.table.size());
+ writer.Write((char*) sample.book.table.data(), sample.book.table.size() * sizeof(int16_t));
+ writer.Write(sample.name);
- writer->Write(entry.name);
+ writer.Finish(write);
+}
- return true;
+std::optional<std::shared_ptr<IParsedData>> SampleFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) {
+ auto id = data["id"].as<int32_t>();
+ AudioBankSample entry = AudioManager::Instance->get_aifc(id);
+ return std::make_shared<SampleData>(entry);
} \ No newline at end of file