Support SFX
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "../Auxiliary/bits.hpp"
|
||||
#include "../GPU/gpu_types.hpp"
|
||||
#include "../jabyengine_defines.hpp"
|
||||
#include "../SPU/spu.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
#pragma pack(push, 1)
|
||||
@@ -68,10 +69,11 @@ namespace JabyEngine {
|
||||
};
|
||||
|
||||
struct VAG {
|
||||
uint8_t voice_number;
|
||||
uint8_t voice_number;
|
||||
SPU::SimpleVolume inital_stereo_vol;
|
||||
|
||||
static constexpr VAG create(uint8_t voice_num) {
|
||||
return VAG{.voice_number = voice_num};
|
||||
static constexpr VAG create(uint8_t voice_num, SPU::SimpleVolume volume) {
|
||||
return VAG{.voice_number = voice_num, .inital_stereo_vol = volume};
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -3,31 +3,41 @@
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace SPU {
|
||||
using SRAMAdr = SPU_IO::SRAMAdr;
|
||||
using SPU_IO::operator""_vol;
|
||||
|
||||
using SRAMAdr = SPU_IO::SRAMAdr;
|
||||
using SimpleVolume = SPU_IO::SimpleVolume;
|
||||
using SweepVolume = SPU_IO::SweepVolume;
|
||||
|
||||
// TODO: Rename to sample...?
|
||||
struct Voice {
|
||||
size_t get_id() const {
|
||||
size_t get_id() {
|
||||
return reinterpret_cast<size_t>(this);
|
||||
}
|
||||
|
||||
SRAMAdr allocate(size_t size) const;
|
||||
SRAMAdr allocate(SPU_IO::SampleRate frequency, size_t size) const;
|
||||
void deallocate() const;
|
||||
SRAMAdr allocate(size_t size);
|
||||
SRAMAdr allocate(SPU_IO::SampleRate frequency, size_t size);
|
||||
void deallocate();
|
||||
|
||||
void set_sample_rate(SPU_IO::SampleRate frequency) const {
|
||||
void set_sample_rate(SPU_IO::SampleRate frequency) {
|
||||
SPU_IO::Voice[Voice::get_id()].sampleRate.write(frequency);
|
||||
}
|
||||
|
||||
void play() const {
|
||||
void set_volume(SimpleVolume left, SimpleVolume right) {
|
||||
// TODO: Verify that assembly code is super simple
|
||||
SPU_IO::Voice[Voice::get_id()].volumeLeft.write(SweepVolume::create(left));
|
||||
SPU_IO::Voice[Voice::get_id()].volumeRight.write(SweepVolume::create(right));
|
||||
}
|
||||
|
||||
void play() {
|
||||
SPU_IO::Key::On.write(SPU_IO::KeyOn::for_specific(Voice::get_id()));
|
||||
}
|
||||
|
||||
void stop() const {
|
||||
void stop() {
|
||||
SPU_IO::Key::Off.write(SPU_IO::KeyOff::for_specific(Voice::get_id()));
|
||||
}
|
||||
};
|
||||
|
||||
extern const Voice voice[SPU_IO::VoiceCount];
|
||||
extern Voice voice[SPU_IO::VoiceCount];
|
||||
}
|
||||
}
|
@@ -219,6 +219,10 @@ namespace JabyEngine {
|
||||
static constexpr auto Step = BitRange::from_to(0, 1);
|
||||
};
|
||||
|
||||
static constexpr SweepVolume create(SimpleVolume volume) {
|
||||
return from(VolumeMode::Enable, VolumeMode::Volume.with(volume.raw >> 1));
|
||||
}
|
||||
|
||||
static constexpr SweepVolume mute() {
|
||||
return SweepVolume{0};
|
||||
}
|
||||
|
Reference in New Issue
Block a user