From 0b340abb20a6cbc2016c9760d24bbb63d28f45f2 Mon Sep 17 00:00:00 2001 From: jaby Date: Tue, 6 Aug 2024 12:58:31 -0500 Subject: [PATCH] Parse VAG header --- include/PSX/Auxiliary/big_endian.hpp | 19 ++++++++++ .../src/File/Processor/vag_processor.cpp | 35 +++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 include/PSX/Auxiliary/big_endian.hpp diff --git a/include/PSX/Auxiliary/big_endian.hpp b/include/PSX/Auxiliary/big_endian.hpp new file mode 100644 index 00000000..4e24c32b --- /dev/null +++ b/include/PSX/Auxiliary/big_endian.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "../jabyengine_defines.hpp" + +namespace JabyEngine { + // Taken from boost endian + + static constexpr uint8_t read_be(uint8_t x) { + return x; + } + + static constexpr uint16_t read_be(uint16_t x) { + return (x << 8) | (x >> 8); + } + + static constexpr uint32_t read_be(uint32_t x) { + const uint32_t step16 = x << 16 | x >> 16; + return ((step16 << 8) & 0xff00ff00) | ((step16 >> 8) & 0x00ff00ff); + } +} \ No newline at end of file diff --git a/src/Library/src/File/Processor/vag_processor.cpp b/src/Library/src/File/Processor/vag_processor.cpp index 55330468..2966a4f2 100644 --- a/src/Library/src/File/Processor/vag_processor.cpp +++ b/src/Library/src/File/Processor/vag_processor.cpp @@ -1,9 +1,34 @@ +#include #include #include #ifdef __SUPPORT_VAG__ namespace JabyEngine { namespace FileProcessor { + #pragma pack(push, 1) + struct VAGHeader { + char id[4]; + uint32_t version; + uint32_t reserved; + uint32_t sample_size; + uint32_t sample_frequency; + uint8_t reserved_2[12]; + char name[16]; + + constexpr uint32_t get_version() const { + return read_be(this->version); + } + + constexpr uint32_t get_sample_size() const { + return read_be(this->sample_size); + } + + constexpr uint32_t get_sample_frequency() const { + return read_be(this->sample_frequency); + } + }; + #pragma pack(pop) + struct VAGState { static constexpr VAGState create() { return VAGState{}; @@ -11,8 +36,14 @@ namespace JabyEngine { }; static Progress parse_header(State::Configuration& config, VAGState& state) { - printf("What am I supposed to do?!\n"); - return Progress::Error; + if(config.data_bytes >= sizeof(VAGHeader)) { + const auto& header = *reinterpret_cast(config.data_adr); + + printf("VAG-ID: %s\nName: %s\nSample size: %i\nSample rate: %i\n", header.id, header.name, header.get_sample_size(), header.get_sample_frequency()); + return Progress::Error; + } + + return Progress::InProgress; } State create(const uint32_t* data_adr, const VAG& file) {