Improve SPU code and support state of voice

This commit is contained in:
Jaby
2024-09-24 22:21:58 +02:00
committed by Jaby
parent fb0be4cc42
commit 6ffd5ff1b7
7 changed files with 59 additions and 67 deletions

View File

@@ -52,11 +52,14 @@ namespace JabyEngine {
static Progress parse_header(State::Configuration& config, VAGState& state) {
if(config.data_bytes >= sizeof(VAGHeader)) {
const auto& header = *reinterpret_cast<const VAGHeader*>(config.data_adr);
const auto bytes = header.get_sample_size();
const auto words = bytes_to_words(header.get_sample_size());
const auto bytes = words_to_bytes(words);
state.words_left = bytes_to_words(bytes);
state.words_left = words;
auto sram_adr = SPU::voice[state.voice_id].allocate(SPU_IO::SampleRate::from_HZ(header.get_sample_frequency()), words_to_bytes(state.words_left));
auto sram_adr = SPU::voice[state.voice_id].allocate(SPU_IO::SampleRate::from_HZ(header.get_sample_frequency()), bytes);
// TODO: Keep this as optional?
printf("SPU: Allocated %i @0x%p to 0x%p (%i bytes)\n", state.voice_id, sram_adr.raw, (sram_adr.raw + bytes), bytes);
SPU::voice[state.voice_id].set_volume(state.inital_vol, state.inital_vol);
config.processed(sizeof(VAGHeader));