Support Volume Steps now for easier support of fractions
This commit is contained in:
parent
41c8c32db8
commit
7243b50fbc
|
@ -22,9 +22,11 @@ namespace SPU {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __no_align SweepVolume {
|
struct __no_align SweepVolume {
|
||||||
static constexpr int16_t VolumeLevelStep100 = (I16_MAX/100);
|
typedef int16_t VolumeStep;
|
||||||
static constexpr int16_t VolumeLevelStep1000 = (I16_MAX/1000);
|
|
||||||
|
|
||||||
|
static constexpr VolumeStep VolumeMax = 1000;
|
||||||
|
static constexpr VolumeStep SingleVolumeStep = (I16_MAX >> 1)/VolumeMax;
|
||||||
|
|
||||||
enum Direction {
|
enum Direction {
|
||||||
Increase = 0,
|
Increase = 0,
|
||||||
Decrease = 1,
|
Decrease = 1,
|
||||||
|
@ -39,17 +41,22 @@ namespace SPU {
|
||||||
|
|
||||||
constexpr SweepVolume() = default;
|
constexpr SweepVolume() = default;
|
||||||
|
|
||||||
static constexpr int16_t VolumeLevelPercent(double percent) {
|
constexpr auto& set_volume_percent(double percent) {
|
||||||
return static_cast<int16_t>((I16_MAX/100.0)*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));
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int16_t get_volume() const {
|
//A value between 0 and 1000
|
||||||
return bit::cast<int16_t>(bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(0, 14)));
|
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);
|
io_class__2option_map(volume_mode, sweep_mode, 15);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup() {
|
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::Left, StartVol);
|
||||||
io_class__volatile_assign(::SPU::MainVolume::Right, StartVol);
|
io_class__volatile_assign(::SPU::MainVolume::Right, StartVol);
|
||||||
|
|
Loading…
Reference in New Issue