Support new SPU voice approach
This commit is contained in:
parent
0a78020aec
commit
f41df3eb51
|
@ -1,7 +1,32 @@
|
|||
#pragma once
|
||||
#include "../jabyengine.hpp"
|
||||
#include "../System/IOPorts/spu_io.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
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];
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ __stack_start = ORIGIN(ram) + LENGTH(ram);
|
|||
|
||||
SECTIONS {
|
||||
.zero (NOLOAD) : {
|
||||
_ZN10JabyEngine2CD4zeroE = .;
|
||||
_ZN10JabyEngine3SPU5voiceE = .;
|
||||
} > zero
|
||||
|
||||
.bios (NOLOAD) : {
|
||||
|
|
|
@ -4,7 +4,28 @@
|
|||
#include <PSX/SPU/spu.hpp>
|
||||
#include <stddef.hpp>
|
||||
|
||||
#include <stdio.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue