mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
SoundBankWriter code
This commit is contained in:
@ -6,7 +6,7 @@ ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& ParsedCsvRow::GetValue(const std::string& header, bool required) const
|
||||
const std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
|
||||
{
|
||||
if (this->headers.find(header) == this->headers.end())
|
||||
{
|
||||
@ -14,19 +14,34 @@ const std::string& ParsedCsvRow::GetValue(const std::string& header, bool requir
|
||||
std::cerr << "ERROR: Required column \"" << header << "\" was not found";
|
||||
else
|
||||
std::cerr << "WARNING: Expected column \"" << header << "\" was not found";
|
||||
return nullptr;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
auto& value = this->values.at(this->headers[header]);
|
||||
if (required && value.empty())
|
||||
{
|
||||
std::cerr << "ERROR: Required column \"" << header << "\" does not have a value";
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
|
||||
{
|
||||
const auto& value = this->GetValue(header, required);
|
||||
if (!value.empty())
|
||||
{
|
||||
std::istringstream ss(value);
|
||||
float out;
|
||||
ss >> out;
|
||||
return out;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders)
|
||||
{
|
||||
std::vector<std::vector<std::string>> csvLines;
|
||||
|
@ -10,17 +10,18 @@ class ParsedCsvRow
|
||||
|
||||
public:
|
||||
explicit ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string>& row);
|
||||
const std::string& GetValue(const std::string& header, bool required = false) const;
|
||||
const std::string GetValue(const std::string& header, bool required = false) const;
|
||||
const float GetValueFloat(const std::string& header, bool required = false) const;
|
||||
|
||||
template<typename T> T GetValueAs(const std::string& header, bool required = false) const
|
||||
template<typename T> T GetValueInt(const std::string& header, bool required = false) const
|
||||
{
|
||||
const auto& value = this->GetValue(header, required);
|
||||
if (!value.empty())
|
||||
{
|
||||
std::istringstream ss(value);
|
||||
T out{};
|
||||
long long out;
|
||||
ss >> out;
|
||||
return out;
|
||||
return static_cast<T>(out);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
45
src/ObjCommon/ObjContainer/SoundBank/SoundBankTypes.h
Normal file
45
src/ObjCommon/ObjContainer/SoundBank/SoundBankTypes.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class SoundBankConsts
|
||||
{
|
||||
SoundBankConsts() = default;
|
||||
|
||||
public:
|
||||
static constexpr unsigned OFFSET_DATA_START = 0x800;
|
||||
};
|
||||
|
||||
struct SoundAssetBankChecksum
|
||||
{
|
||||
char checksumBytes[16];
|
||||
};
|
||||
|
||||
struct SoundAssetBankHeader
|
||||
{
|
||||
unsigned int magic; // + 0x0
|
||||
unsigned int version; // + 0x4
|
||||
unsigned int entrySize; // + 0x8
|
||||
unsigned int checksumSize; // + 0xC
|
||||
unsigned int dependencySize; // + 0x10
|
||||
unsigned int entryCount; // + 0x14
|
||||
unsigned int dependencyCount; // + 0x18
|
||||
unsigned int pad32; // + 0x1C
|
||||
int64_t fileSize; // + 0x20
|
||||
int64_t entryOffset; // + 0x28
|
||||
int64_t checksumOffset; // + 0x30
|
||||
SoundAssetBankChecksum checksumChecksum; // + 0x38
|
||||
char dependencies[512]; // + 0x48
|
||||
};
|
||||
|
||||
struct SoundAssetBankEntry
|
||||
{
|
||||
unsigned int id;
|
||||
unsigned int size;
|
||||
unsigned int offset;
|
||||
unsigned int frameCount;
|
||||
unsigned char frameRateIndex;
|
||||
unsigned char channelCount;
|
||||
unsigned char looping;
|
||||
unsigned char format;
|
||||
};
|
@ -28,3 +28,20 @@ struct WavFormatChunkPcm
|
||||
uint16_t nBlockAlign;
|
||||
uint16_t wBitsPerSample;
|
||||
};
|
||||
|
||||
struct WavMetaData
|
||||
{
|
||||
unsigned channelCount;
|
||||
unsigned samplesPerSec;
|
||||
unsigned bitsPerSample;
|
||||
};
|
||||
|
||||
struct WavHeader
|
||||
{
|
||||
unsigned int chunkIdRiff;
|
||||
unsigned int chunkIdSize;
|
||||
unsigned int format;
|
||||
WavChunkHeader chunkHeader;
|
||||
WavFormatChunkPcm formatChunk;
|
||||
WavChunkHeader subChunkHeader;
|
||||
};
|
Reference in New Issue
Block a user