diff --git a/include/PSX/System/IOPorts/spu_io.hpp b/include/PSX/System/IOPorts/spu_io.hpp index 801d4314..bc7cac38 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -41,10 +41,14 @@ namespace JabyEngine { }; __declare_io_value(SampleRate, uint16_t) { + static constexpr SampleRate from_HZ(uint32_t freq) { + constexpr uint32_t Base1024Hz = static_cast((4096.0/44100.0)*1024.0); + return {static_cast((freq >> 10)*Base1024Hz)}; + } + static constexpr SampleRate from_HZ(double freq) { //4096 == 44100Hz constexpr double Base = (4096.0 / 44100.0); - return {static_cast((freq*Base))}; } }; diff --git a/src/Library/src/File/Processor/vag_processor.cpp b/src/Library/src/File/Processor/vag_processor.cpp index 4dbe7291..2a5a023c 100644 --- a/src/Library/src/File/Processor/vag_processor.cpp +++ b/src/Library/src/File/Processor/vag_processor.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #ifdef __SUPPORT_VAG__ @@ -28,8 +29,12 @@ namespace JabyEngine { }; struct VAGState { - static constexpr VAGState create() { - return VAGState{}; + uint32_t voice_id; + size_t bytes_left; + SPU::SRAM_Adr adr; + + static constexpr VAGState create(uint32_t voice_id) { + return VAGState{.voice_id = voice_id, .bytes_left = 0, .adr = 0}; } }; @@ -37,8 +42,10 @@ namespace JabyEngine { 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()); - // TODO: Allocate SPU memory + state.bytes_left = header.get_sample_size(); + state.adr = SPU::voice[state.voice_id].allocate(SPU_IO::SampleRate::from_HZ(header.get_sample_frequency()), state.bytes_left); + + // TODO: Parse samples return Progress::Error; } @@ -46,7 +53,7 @@ namespace JabyEngine { } State create(const uint32_t* data_adr, const VAG& file) { - return State::from(VAGState::create(), data_adr, parse_header); + return State::from(VAGState::create(file.voice_number), data_adr, parse_header); } } }