Support new SPU voice approach

This commit is contained in:
jaby 2024-08-24 14:25:05 +02:00
parent 12de2340cc
commit 92b19ecabc
3 changed files with 48 additions and 2 deletions

View File

@ -1,7 +1,32 @@
#pragma once #pragma once
#include "../jabyengine.hpp" #include "../System/IOPorts/spu_io.hpp"
namespace JabyEngine { namespace JabyEngine {
namespace SPU { namespace SPU {
using SRAM_Adr = uint16_t;
struct Voice {
size_t get_id() const {
return reinterpret_cast<size_t>(this);
}
SRAM_Adr allocate(size_t size) const;
SRAM_Adr allocate(SPU_IO::SampleRate frequency, size_t size) const;
void deallocate() const;
void set_sample_rate(SPU_IO::SampleRate frequency) const {
SPU_IO::Voice[Voice::get_id()].sampleRate.write(frequency);
}
void play() const {
SPU_IO::Key::On.write(1 << Voice::get_id());
}
void stop() const {
SPU_IO::Key::Off.write(1 << Voice::get_id());
}
};
extern const Voice voice[SPU_IO::VoiceCount];
} }
} }

View File

@ -55,7 +55,7 @@ __stack_start = ORIGIN(ram) + LENGTH(ram);
SECTIONS { SECTIONS {
.zero (NOLOAD) : { .zero (NOLOAD) : {
_ZN10JabyEngine2CD4zeroE = .; _ZN10JabyEngine3SPU5voiceE = .;
} > zero } > zero
.bios (NOLOAD) : { .bios (NOLOAD) : {

View File

@ -4,7 +4,28 @@
#include <PSX/SPU/spu.hpp> #include <PSX/SPU/spu.hpp>
#include <stddef.hpp> #include <stddef.hpp>
#include <stdio.hpp>
namespace JabyEngine { namespace JabyEngine {
namespace SPU { namespace SPU {
SRAM_Adr Voice :: allocate(size_t size) const {
Voice::stop();
const auto voice_id = Voice::get_id();
const auto adr = static_cast<SRAM_Adr>(reinterpret_cast<uintptr_t>(SPU_MMU::allocate(voice_id, size)));
SPU_IO::Voice[voice_id].adr.write({adr});
return adr;
}
SRAM_Adr Voice :: allocate(SPU_IO::SampleRate frequency, size_t size) const {
const auto result = Voice::allocate(size);
Voice::set_sample_rate(frequency);
return result;
}
void Voice :: deallocate() const {
Voice::stop();
SPU_MMU::deallocate(Voice::get_id());
}
} }
} }