#pragma once #include "../System/IOPorts/spu_io.hpp" namespace JabyEngine { namespace SPU { 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() { return reinterpret_cast(this); } SRAMAdr allocate(size_t size); SRAMAdr allocate(SPU_IO::SampleRate frequency, size_t size); void deallocate(); void set_sample_rate(SPU_IO::SampleRate frequency) { SPU_IO::Voice[Voice::get_id()].sampleRate.write(frequency); } 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() { SPU_IO::Key::Off.write(SPU_IO::KeyOff::for_specific(Voice::get_id())); } }; extern Voice voice[SPU_IO::VoiceCount]; } }