Support Volume Steps now for easier support of fractions
This commit is contained in:
@@ -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<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);
|
||||
|
Reference in New Issue
Block a user