Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
945941ef5c
|
|||
|
a6d5ff56d9
|
|||
|
f6b81d701a
|
|||
|
7197ecff02
|
|||
|
43c735b0b2
|
|||
|
f1d4884d99
|
|||
| 8f175aebe1 |
@@ -14,7 +14,6 @@ class CTRFF_API BCSTM {
|
||||
void CleanUp();
|
||||
void ReadGotoBeginning(bool use_loop_beg = false);
|
||||
void ReadBlock(PD::u32 block, PD::u8* ref);
|
||||
PD::u32 LeseZeiger() { return pFile.tellg(); }
|
||||
|
||||
/** Some useful Getters */
|
||||
PD::u8 GetNumChannels() const { return pInfoBlock.StreamInfo.ChannelCount; }
|
||||
@@ -29,13 +28,13 @@ class CTRFF_API BCSTM {
|
||||
}
|
||||
bool IsLooping() const { return pInfoBlock.StreamInfo.Loop; }
|
||||
PD::u32 GetLoopStart() const {
|
||||
return pInfoBlock.StreamInfo.LoopStartFrame / GetNumBlocks();
|
||||
return pInfoBlock.StreamInfo.LoopStartFrame / GetBlockSamples();
|
||||
}
|
||||
PD::u32 GetLoopEnd() const {
|
||||
/** Get temp references for better readability */
|
||||
const PD::u32& loop_end = pInfoBlock.StreamInfo.LoopEndFrame;
|
||||
const PD::u32& block_samples = GetNumBlocks();
|
||||
return (loop_end % block_samples ? block_samples
|
||||
const PD::u32& block_samples = GetBlockSamples();
|
||||
return (loop_end % block_samples ? GetNumBlocks()
|
||||
: loop_end / block_samples);
|
||||
}
|
||||
|
||||
@@ -68,22 +67,28 @@ class CTRFF_API BCSTM {
|
||||
};
|
||||
|
||||
struct Reference {
|
||||
Reference() : TypeID(0), Padding(0), Offset(0) {}
|
||||
Reference(PD::u16 t, PD::u16 p, PD::u32 o)
|
||||
: TypeID(t), Padding(p), Offset(o) {}
|
||||
PD::u16 TypeID;
|
||||
PD::u16 Padding;
|
||||
PD::u32 Offset; /** null -> uint32_max */
|
||||
};
|
||||
|
||||
struct ReferenceTable {
|
||||
ReferenceTable() : Count(0) {}
|
||||
PD::u32 Count;
|
||||
PD::Vec<Reference> Refs;
|
||||
std::vector<Reference> Refs;
|
||||
};
|
||||
|
||||
struct SizedReference {
|
||||
SizedReference() : Size(0) {}
|
||||
Reference Ref;
|
||||
PD::u32 Size;
|
||||
};
|
||||
|
||||
struct StreamInfo {
|
||||
StreamInfo();
|
||||
PD::u8 Encoding;
|
||||
PD::u8 Loop;
|
||||
PD::u8 ChannelCount;
|
||||
@@ -103,11 +108,14 @@ class CTRFF_API BCSTM {
|
||||
};
|
||||
|
||||
struct BlockHeader {
|
||||
BlockHeader() : Magic(0), Size(0) {}
|
||||
BlockHeader(PD::u32 m, PD::u32 s) : Magic(m), Size(s) {}
|
||||
PD::u32 Magic;
|
||||
PD::u32 Size;
|
||||
};
|
||||
|
||||
struct InfoBlock {
|
||||
InfoBlock() = default;
|
||||
BlockHeader Header;
|
||||
Reference StreamInfoRef;
|
||||
Reference TrackInfoTabRef;
|
||||
@@ -115,19 +123,27 @@ class CTRFF_API BCSTM {
|
||||
BCSTM::StreamInfo StreamInfo;
|
||||
ReferenceTable TrackInfoTab;
|
||||
ReferenceTable ChannelInfoTab;
|
||||
PD::Vec<Reference> ChannelInfoRefs; /** The refs of the refs ?? */
|
||||
std::vector<Reference> ChannelInfoRefs; /** The refs of the refs ?? */
|
||||
};
|
||||
|
||||
/** SeekDataBlock cause they are the same struct */
|
||||
struct SD_Block {
|
||||
SD_Block() {}
|
||||
BlockHeader Header;
|
||||
PD::Vec<PD::u8> Data;
|
||||
std::vector<PD::u8> Data;
|
||||
};
|
||||
|
||||
struct DSP_ADPCM_Param {
|
||||
// Lets keep this not clean here :/
|
||||
DSP_ADPCM_Param() {}
|
||||
PD::u16 Coefficients[0x10];
|
||||
};
|
||||
struct DSP_ADPCM_Context {
|
||||
DSP_ADPCM_Context()
|
||||
: PredictorScale(0),
|
||||
Reserved(0),
|
||||
PreviousSample(0),
|
||||
SecondPreviousSample(0) {}
|
||||
PD::u8 PredictorScale;
|
||||
PD::u8 Reserved;
|
||||
PD::u16 PreviousSample;
|
||||
@@ -135,6 +151,7 @@ class CTRFF_API BCSTM {
|
||||
};
|
||||
|
||||
struct DSP_ADPCM_Info {
|
||||
DSP_ADPCM_Info() : Padding(0) {}
|
||||
DSP_ADPCM_Param Param;
|
||||
DSP_ADPCM_Context Context;
|
||||
DSP_ADPCM_Context LoopContext;
|
||||
@@ -142,11 +159,13 @@ class CTRFF_API BCSTM {
|
||||
};
|
||||
|
||||
struct ByteTable {
|
||||
ByteTable(PD::u32 size = 0) : Size(size) {}
|
||||
PD::u32 Size;
|
||||
PD::Vec<PD::u8> Table;
|
||||
std::vector<PD::u8> Table;
|
||||
};
|
||||
|
||||
struct TrackInfo {
|
||||
TrackInfo() : Volume(0), Pan(0), Padding(0) {}
|
||||
PD::u8 Volume;
|
||||
PD::u8 Pan;
|
||||
PD::u16 Padding;
|
||||
@@ -155,6 +174,15 @@ class CTRFF_API BCSTM {
|
||||
};
|
||||
|
||||
struct Header {
|
||||
// Warum sieht dass so ~~nicht~~ gut aus...
|
||||
Header()
|
||||
: Magic(0),
|
||||
Endianness(Little),
|
||||
HeaderSize(0),
|
||||
Version(0),
|
||||
FileSize(0),
|
||||
NumBlocks(0),
|
||||
Reserved(0) {}
|
||||
PD::u32 Magic; /** CSTM */
|
||||
PD::u16 Endianness = Little; /** Default */
|
||||
PD::u16 HeaderSize; /** Header Size probably */
|
||||
@@ -171,7 +199,7 @@ class CTRFF_API BCSTM {
|
||||
InfoBlock pInfoBlock;
|
||||
SD_Block pSeekBlock;
|
||||
SD_Block pDataBlock;
|
||||
PD::Vec<DSP_ADPCM_Info> pDSP_ADPCM_Info;
|
||||
std::vector<DSP_ADPCM_Info> pDSP_ADPCM_Info;
|
||||
/** File Stream */
|
||||
std::fstream pFile;
|
||||
/** Endianness based reader */
|
||||
|
||||
@@ -46,7 +46,7 @@ class CTRFF_API BCWAV {
|
||||
|
||||
struct ReferenceTable {
|
||||
PD::u32 Count;
|
||||
PD::Vec<Reference> Refs;
|
||||
std::vector<Reference> Refs;
|
||||
};
|
||||
|
||||
struct SizedReference {
|
||||
@@ -88,13 +88,13 @@ class CTRFF_API BCWAV {
|
||||
PD::u32 LoopEndFrame;
|
||||
PD::u32 Reserved;
|
||||
ReferenceTable ChannelInfoTab;
|
||||
PD::Vec<Reference> ChannelInfoRefs; /** The refs of the refs ?? */
|
||||
std::vector<Reference> ChannelInfoRefs; /** The refs of the refs ?? */
|
||||
};
|
||||
|
||||
struct DataBlock {
|
||||
BlockHeader Header;
|
||||
PD::u32 Padding[3];
|
||||
PD::Vec<PD::u8> Data;
|
||||
std::vector<PD::u8> Data;
|
||||
};
|
||||
|
||||
struct DSP_ADPCM_Param {
|
||||
@@ -129,7 +129,7 @@ class CTRFF_API BCWAV {
|
||||
SizedReference pDataBlockRef;
|
||||
InfoBlock pInfoBlock;
|
||||
DataBlock pDataBlock;
|
||||
PD::Vec<DSP_ADPCM_Info> pDSP_ADPCM_Info;
|
||||
std::vector<DSP_ADPCM_Info> pDSP_ADPCM_Info;
|
||||
/** File Stream */
|
||||
std::fstream pFile;
|
||||
/** Endianness based reader */
|
||||
|
||||
@@ -97,9 +97,9 @@ CTRFF_API void BCSTM::ReadInfoBlock(InfoBlock& block) {
|
||||
std::ios::beg);
|
||||
Reference r;
|
||||
ReadReference(r);
|
||||
block.ChannelInfoRefs.Add(r);
|
||||
block.ChannelInfoRefs.push_back(r);
|
||||
}
|
||||
for (size_t i = 0; i < block.ChannelInfoRefs.Size(); i++) {
|
||||
for (size_t i = 0; i < block.ChannelInfoRefs.size(); i++) {
|
||||
size_t off = pInfoBlockRef.Ref.Offset;
|
||||
off += sizeof(BlockHeader);
|
||||
off += block.ChannelInfoTabRef.Offset;
|
||||
@@ -108,7 +108,7 @@ CTRFF_API void BCSTM::ReadInfoBlock(InfoBlock& block) {
|
||||
pFile.seekg(off, std::ios::beg);
|
||||
DSP_ADPCM_Info t; /** temp */
|
||||
pReader.ReadEx(t); /** This Section gets read normally */
|
||||
pDSP_ADPCM_Info.Add(t);
|
||||
pDSP_ADPCM_Info.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,23 +119,23 @@ CTRFF_API void BCSTM::ReadSeekBlock(SD_Block& block) {
|
||||
throw std::runtime_error("BCSTM: SeekBlock Size is not 0x20 aligned!");
|
||||
}
|
||||
|
||||
pSeekBlock.Data.Reserve(pSeekBlock.Header.Size + 1);
|
||||
pSeekBlock.Data.reserve(pSeekBlock.Header.Size + 1);
|
||||
for (PD::u32 i = 0; i < pSeekBlock.Header.Size; i++) {
|
||||
PD::u8 v;
|
||||
pReader.Read(v);
|
||||
pSeekBlock.Data.Add(v);
|
||||
pSeekBlock.Data.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
CTRFF_API void BCSTM::ReadReferenceTab(ReferenceTable& tab) {
|
||||
pReader.Read(tab.Count);
|
||||
tab.Refs.Reserve(tab.Count + 1);
|
||||
tab.Refs.reserve(tab.Count + 1);
|
||||
for (PD::u32 i = 0; i < tab.Count; i++) {
|
||||
Reference r;
|
||||
pReader.Read(r.TypeID);
|
||||
pReader.Read(r.Padding);
|
||||
pReader.Read(r.Offset);
|
||||
tab.Refs.Add(r);
|
||||
tab.Refs.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +162,12 @@ CTRFF_API void BCSTM::ReadGotoBeginning(bool use_loop_beg) {
|
||||
}
|
||||
|
||||
CTRFF_API void BCSTM::ReadBlock(PD::u32 block, PD::u8* ref) {
|
||||
if (!ref) {
|
||||
throw std::runtime_error("BCSTM: pointer ref is nullptr!");
|
||||
}
|
||||
if (pFile.tellg() > pHeader.FileSize || block >= GetNumBlocks()) {
|
||||
throw std::runtime_error("BCSTM: Decode block Out of range!");
|
||||
throw std::runtime_error(std::format(
|
||||
"BCSTM: Decode block out of range! ({}/{})", block, GetNumBlocks()));
|
||||
}
|
||||
pFile.read(
|
||||
reinterpret_cast<char*>(ref),
|
||||
@@ -179,11 +183,32 @@ CTRFF_API void BCSTM::CleanUp() {
|
||||
throw std::runtime_error(e.what());
|
||||
}
|
||||
}
|
||||
pInfoBlock.ChannelInfoRefs.Clear();
|
||||
pInfoBlock.ChannelInfoTab.Refs.Clear();
|
||||
pInfoBlock.ChannelInfoTab.Count = 0;
|
||||
pInfoBlock.TrackInfoTab.Refs.Clear();
|
||||
pInfoBlock.TrackInfoTab.Count = 0;
|
||||
pDSP_ADPCM_Info.Clear();
|
||||
pInfoBlock = InfoBlock();
|
||||
pHeader = Header();
|
||||
pInfoBlockRef = SizedReference();
|
||||
pSeekBlockRef = SizedReference();
|
||||
pDataBlockRef = SizedReference();
|
||||
pInfoBlock = InfoBlock();
|
||||
pSeekBlock = SD_Block();
|
||||
pDataBlock = SD_Block();
|
||||
pDSP_ADPCM_Info.clear();
|
||||
}
|
||||
|
||||
CTRFF_API BCSTM::StreamInfo::StreamInfo() {
|
||||
ChannelCount = 0;
|
||||
Encoding = 0;
|
||||
LastSampleBlockPaddedSize = 0;
|
||||
LastSampleBlockSampleNum = 0;
|
||||
LastSampleBlockSize = 0;
|
||||
Loop = 0;
|
||||
LoopEndFrame = 0;
|
||||
LoopStartFrame = 0;
|
||||
Padding = 0;
|
||||
SampleBlockNum = 0;
|
||||
SampleBlockSampleNum = 0;
|
||||
SampleBlockSize = 0;
|
||||
SampleRate = 0;
|
||||
SeekDataSize = 0;
|
||||
SeekIntervalSampleNum = 0;
|
||||
}
|
||||
} // namespace ctrff
|
||||
|
||||
@@ -67,9 +67,9 @@ CTRFF_API void BCWAV::ReadInfoBlock(InfoBlock& block) {
|
||||
std::ios::beg);
|
||||
Reference r;
|
||||
ReadReference(r);
|
||||
block.ChannelInfoRefs.Add(r);
|
||||
block.ChannelInfoRefs.push_back(r);
|
||||
}
|
||||
for (size_t i = 0; i < block.ChannelInfoRefs.Size(); i++) {
|
||||
for (size_t i = 0; i < block.ChannelInfoRefs.size(); i++) {
|
||||
size_t off = pInfoBlockRef.Ref.Offset;
|
||||
off += sizeof(BlockHeader);
|
||||
off += block.ChannelInfoTab.Refs[i].Offset;
|
||||
@@ -77,19 +77,19 @@ CTRFF_API void BCWAV::ReadInfoBlock(InfoBlock& block) {
|
||||
pFile.seekg(off, std::ios::beg);
|
||||
DSP_ADPCM_Info t; /** temp */
|
||||
pReader.ReadEx(t); /** This Section gets read normally */
|
||||
pDSP_ADPCM_Info.Add(t);
|
||||
pDSP_ADPCM_Info.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
CTRFF_API void BCWAV::ReadReferenceTab(ReferenceTable& tab) {
|
||||
pReader.Read(tab.Count);
|
||||
tab.Refs.Reserve(tab.Count + 1);
|
||||
tab.Refs.reserve(tab.Count + 1);
|
||||
for (PD::u32 i = 0; i < tab.Count; i++) {
|
||||
Reference r;
|
||||
pReader.Read(r.TypeID);
|
||||
pReader.Read(r.Padding);
|
||||
pReader.Read(r.Offset);
|
||||
tab.Refs.Add(r);
|
||||
tab.Refs.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +134,9 @@ CTRFF_API void BCWAV::CleanUp() {
|
||||
throw std::runtime_error(e.what());
|
||||
}
|
||||
}
|
||||
pInfoBlock.ChannelInfoRefs.Clear();
|
||||
pInfoBlock.ChannelInfoTab.Refs.Clear();
|
||||
pInfoBlock.ChannelInfoRefs.clear();
|
||||
pInfoBlock.ChannelInfoTab.Refs.clear();
|
||||
pInfoBlock.ChannelInfoTab.Count = 0;
|
||||
pDSP_ADPCM_Info.Clear();
|
||||
pDSP_ADPCM_Info.clear();
|
||||
}
|
||||
} // namespace ctrff
|
||||
|
||||
@@ -21,7 +21,7 @@ void BinUtil::Read(T& v) {
|
||||
// Read data into buffer
|
||||
m_file.read(reinterpret_cast<char*>(buf.data()), sizeof(T));
|
||||
// Loop or in be reverse loop and chift the values
|
||||
for (int i = 0; i < sizeof(T); i++) {
|
||||
for (size_t i = 0; i < sizeof(T); i++) {
|
||||
v |= static_cast<T>(buf[m_big ? sizeof(T) - 1 - i : i]) << (8 * i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ CTRFF_API void ctrff::RGB565toRGBA(std::vector<PD::u8> &img, PD::u16 *icon,
|
||||
img.resize(48 * 48 * 4);
|
||||
img.clear();
|
||||
}
|
||||
for (PD::u32 y = 0; y < h; y++) {
|
||||
for (PD::u32 x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
auto idx = TileIndex(x, y, w);
|
||||
PD::u32 pos = (y * w + x) * 4;
|
||||
MakePixelRGBA(img[pos + 0], img[pos + 1], img[pos + 2], img[pos + 3],
|
||||
@@ -45,8 +45,8 @@ CTRFF_API void ctrff::RGBA2RGB565(PD::u16 *out, const std::vector<PD::u8> &img,
|
||||
const int &w, const int &h) {
|
||||
if (img.size() != size_t(w * h * 4)) return;
|
||||
std::vector<PD::u8> px8 = img;
|
||||
for (PD::u32 y = 0; y < h; y++) {
|
||||
for (PD::u32 x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
auto idx = TileIndex(x, y, w);
|
||||
PD::u32 pos = (y * w + x) * 4;
|
||||
out[idx] = MakePixel565(img[pos], img[pos + 1], img[pos + 2]);
|
||||
|
||||
2
vendor/palladium
vendored
2
vendor/palladium
vendored
Submodule vendor/palladium updated: ea76a304d4...a0960bd717
Reference in New Issue
Block a user