mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Added full SM64 -> AIFF Decoding
This commit is contained in:
@@ -58,7 +58,6 @@ int16_t LUS::BinaryReader::ReadInt16() {
|
||||
if (mEndianness != Endianness::Native) {
|
||||
result = BSWAP16(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -192,6 +191,7 @@ std::string LUS::BinaryReader::ReadString() {
|
||||
for (int i = 0; i < numChars; i++) {
|
||||
res += ReadChar();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -211,6 +211,10 @@ std::string LUS::BinaryReader::ReadCString() {
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t LUS::BinaryReader::GetLength() {
|
||||
return mStream->GetLength();
|
||||
}
|
||||
|
||||
std::vector<char> LUS::BinaryReader::ToVector() {
|
||||
return mStream->ToVector();
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ class BinaryReader {
|
||||
|
||||
void Seek(int32_t offset, SeekOffsetType seekType);
|
||||
uint32_t GetBaseAddress();
|
||||
size_t GetLength();
|
||||
|
||||
void Read(int32_t length);
|
||||
void Read(char* buffer, int32_t length);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "BinaryWriter.h"
|
||||
|
||||
void write_aiff(std::vector<char> data, LUS::BinaryWriter& writer);
|
||||
@@ -1,48 +0,0 @@
|
||||
#include "AIFCWriter.h"
|
||||
|
||||
#include "hj/pyutils.h"
|
||||
|
||||
#define ALIGN(val, al) (size_t) ((val + (al - 1)) & -al)
|
||||
|
||||
std::vector<char> AIFCWriter::pack(const std::string& str) {
|
||||
std::vector<char> result;
|
||||
result.insert(result.end(), str.begin(), str.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<char> AIFCWriter::pstring(const std::vector<char>& data) {
|
||||
std::vector<char> result;
|
||||
result.insert(result.end(), data.begin(), data.end());
|
||||
if (data.size() % 2 == 0) {
|
||||
result.push_back('\0');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AIFCWriter::add_section(AIFC::MagicValues magic, const std::vector<char>& data) {
|
||||
sections.emplace_back(magic, data);
|
||||
total_size += ALIGN(data.size(), 2) + 8;
|
||||
}
|
||||
|
||||
void AIFCWriter::add_custom_section(const std::string& section, const std::vector<char>& data) {
|
||||
this->add_section(AIFC::MagicValues::AAPL, pack("stoc") + pstring(pack(section)) + data);
|
||||
}
|
||||
|
||||
void AIFCWriter::finish() {
|
||||
// total_size isn't used and is regularly wrong.
|
||||
// In particular, vadpcm_enc preserves the size of the input file...
|
||||
total_size += 4;
|
||||
|
||||
out.Write(BSWAP32(AIFC::MagicValues::FORM));
|
||||
out.Write((uint32_t) BSWAP32(total_size));
|
||||
out.Write(BSWAP32(AIFC::MagicValues::AIFC));
|
||||
|
||||
for (const auto& section : sections) {
|
||||
out.Write((uint32_t) BSWAP32(section.first));
|
||||
out.Write((uint32_t) BSWAP32(section.second.size()));
|
||||
out.Write((char*) section.second.data(), section.second.size());
|
||||
if(section.second.size() % 2) {
|
||||
out.Write('\0');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "binarytools/BinaryWriter.h"
|
||||
|
||||
namespace AIFC {
|
||||
enum MagicValues {
|
||||
FORM = 0x464f524d,
|
||||
AIFC = 0x41494643,
|
||||
COMM = 0x434f4d4d,
|
||||
INST = 0x494e5354,
|
||||
VAPC = 0x56415043,
|
||||
SSND = 0x53534e44,
|
||||
AAPL = 0x4150504c,
|
||||
stoc = 0x73746f63,
|
||||
};
|
||||
}
|
||||
|
||||
class AIFCWriter {
|
||||
public:
|
||||
AIFCWriter(LUS::BinaryWriter& out) : out(out), total_size(0) {}
|
||||
|
||||
static std::vector<char> pack(const std::string& str);
|
||||
static std::vector<char> pstring(const std::vector<char>& data);
|
||||
void add_section(AIFC::MagicValues, const std::vector<char>& data);
|
||||
void add_custom_section(const std::string& section, const std::vector<char>& data);
|
||||
void finish();
|
||||
|
||||
private:
|
||||
LUS::BinaryWriter& out;
|
||||
std::vector<std::pair<AIFC::MagicValues, std::vector<char>>> sections;
|
||||
std::size_t total_size;
|
||||
};
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "hj/pyutils.h"
|
||||
#include "binarytools/BinaryReader.h"
|
||||
#include "hj/zip.h"
|
||||
#include "AIFCWriter.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
std::unordered_map<std::string, uint32_t> name_table;
|
||||
@@ -435,7 +434,6 @@ void AudioManager::initialize(std::vector<uint8_t>& buffer) {
|
||||
|
||||
auto zipped = zip(PyUtils::range(0, ctl.size()), ctl, this->loaded_tbl.tbls);
|
||||
|
||||
// std::cout << "================================" << std::endl;
|
||||
for (const auto& item : zipped) {
|
||||
auto [index, ctrl, sample_bank_name] = item;
|
||||
auto sample_bank = this->loaded_tbl.map[sample_bank_name];
|
||||
@@ -444,8 +442,6 @@ void AudioManager::initialize(std::vector<uint8_t>& buffer) {
|
||||
auto header = parse_ctl_header(headerRaw);
|
||||
auto bank = parse_ctl(header, PyUtils::slice(entry, 16), sample_bank, index);
|
||||
banks.push_back(bank);
|
||||
// bank.print();
|
||||
// std::cout << "================================" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,19 @@
|
||||
#define NONE 0xFFFF
|
||||
#define ALIGN(val, al) (size_t) ((val + (al - 1)) & -al)
|
||||
|
||||
namespace AIFC {
|
||||
enum MagicValues {
|
||||
FORM = 0x464f524d,
|
||||
AIFC = 0x41494643,
|
||||
COMM = 0x434f4d4d,
|
||||
INST = 0x494e5354,
|
||||
VAPC = 0x56415043,
|
||||
SSND = 0x53534e44,
|
||||
AAPL = 0x4150504c,
|
||||
stoc = 0x73746f63,
|
||||
};
|
||||
}
|
||||
|
||||
struct Entry {
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "audio/AudioManager.h"
|
||||
#include "audio/AIFCDecode.h"
|
||||
#include "binarytools/BinaryReader.h"
|
||||
|
||||
bool AudioFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector<uint8_t>& buffer) {
|
||||
@@ -25,6 +26,12 @@ bool AudioFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std:
|
||||
return false;
|
||||
}
|
||||
|
||||
AudioManager::Instance->create_aifc(metadata[1]["us"][1], *writer);
|
||||
LUS::BinaryWriter aifcWriter;
|
||||
AudioManager::Instance->create_aifc(metadata[1]["us"][1], aifcWriter);
|
||||
std::vector<char> aifcData = aifcWriter.ToVector();
|
||||
aifcWriter.Close();
|
||||
|
||||
write_aiff(aifcData, *writer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user