Support Volume Steps now for easier support of fractions
This commit is contained in:
parent
fde4ae9c71
commit
c63bdb8e3a
|
@ -22,8 +22,10 @@ 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,
|
||||
|
@ -39,17 +41,22 @@ namespace SPU {
|
|||
|
||||
constexpr SweepVolume() = default;
|
||||
|
||||
static constexpr int16_t VolumeLevelPercent(double percent) {
|
||||
return static_cast<int16_t>((I16_MAX/100.0)*percent);
|
||||
}
|
||||
|
||||
constexpr auto& set_volume(int16_t volume) {
|
||||
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>(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<int16_t>((I16_MAX/100.0)*percent), __start_end_bit2_start_length(0, 14));
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr int16_t get_volume() const {
|
||||
return bit::cast<int16_t>(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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue