From c63bdb8e3aec75d019f294f118a9f7a2651da997 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 31 Aug 2022 17:17:17 +0200 Subject: [PATCH] Support Volume Steps now for easier support of fractions --- include/PSX/SPU/SPU_Ports.hpp | 27 +++++++++++++++++---------- src/Library/src/BootLoader/start.cpp | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/PSX/SPU/SPU_Ports.hpp b/include/PSX/SPU/SPU_Ports.hpp index 4aeea711..471adfbc 100644 --- a/include/PSX/SPU/SPU_Ports.hpp +++ b/include/PSX/SPU/SPU_Ports.hpp @@ -22,9 +22,11 @@ namespace SPU { }; struct __no_align SweepVolume { - static constexpr int16_t VolumeLevelStep100 = (I16_MAX/100); - static constexpr int16_t VolumeLevelStep1000 = (I16_MAX/1000); + typedef int16_t VolumeStep; + static constexpr VolumeStep VolumeMax = 1000; + static constexpr VolumeStep SingleVolumeStep = (I16_MAX >> 1)/VolumeMax; + enum Direction { Increase = 0, Decrease = 1, @@ -39,17 +41,22 @@ namespace SPU { constexpr SweepVolume() = default; - static constexpr int16_t VolumeLevelPercent(double percent) { - return static_cast((I16_MAX/100.0)*percent); - } - - constexpr auto& set_volume(int16_t volume) { - this->raw_value = bit::value::set_normalized(this->raw_value, static_cast(volume >> 1), __start_end_bit2_start_length(0, 14)); + constexpr auto& set_volume_percent(double percent) { + this->raw_value = bit::value::set_normalized(this->raw_value, static_cast((I16_MAX/100.0)*percent), __start_end_bit2_start_length(0, 14)); return *this; } - constexpr int16_t get_volume() const { - return bit::cast(bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(0, 14))); + //A value between 0 and 1000 + constexpr auto& set_volume_step(VolumeStep volume_step) { + volume_step *= SingleVolumeStep; + + this->raw_value = bit::value::set_normalized(this->raw_value, volume_step, __start_end_bit2_start_length(0, 14)); + return *this; + } + + //A value between 0 and 1000 + constexpr VolumeStep get_volume_step() const { + return (bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(0, 14))/SingleVolumeStep); } io_class__2option_map(volume_mode, sweep_mode, 15); diff --git a/src/Library/src/BootLoader/start.cpp b/src/Library/src/BootLoader/start.cpp index 3116a511..0198b4fb 100644 --- a/src/Library/src/BootLoader/start.cpp +++ b/src/Library/src/BootLoader/start.cpp @@ -16,7 +16,7 @@ namespace JabyEngine { } static void setup() { - static constexpr auto StartVol = ::SPU::SweepVolume().set_volume_mode().set_volume(::SPU::SweepVolume::VolumeLevelPercent(50.0)); + static constexpr auto StartVol = ::SPU::SweepVolume().set_volume_mode().set_volume_percent(50.0); io_class__volatile_assign(::SPU::MainVolume::Left, StartVol); io_class__volatile_assign(::SPU::MainVolume::Right, StartVol);