Parse VAG header

This commit is contained in:
jaby 2024-08-06 12:58:31 -05:00
parent 10c394aeba
commit 0b340abb20
2 changed files with 52 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -1,9 +1,34 @@
#include <PSX/Auxiliary/big_endian.hpp>
#include <PSX/File/file_processor_helper.hpp>
#include <stdio.hpp>
#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,10 +36,16 @@ namespace JabyEngine {
};
static Progress parse_header(State::Configuration& config, VAGState& state) {
printf("What am I supposed to do?!\n");
if(config.data_bytes >= sizeof(VAGHeader)) {
const auto& header = *reinterpret_cast<const VAGHeader*>(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) {
return State::from(VAGState::create(), data_adr, parse_header);
}