Changed volume to go in 5pct steps

custom
Ondřej Hruška 7 days ago
parent 71ac67bad3
commit 2ab4e9d8a6
  1. 13
      src/tangara/audio/bt_audio_output.cpp
  2. 19
      src/tangara/audio/i2s_audio_output.cpp

@ -32,6 +32,7 @@
namespace audio { namespace audio {
static constexpr uint16_t kVolumeRange = 60; static constexpr uint16_t kVolumeRange = 60;
static constexpr uint16_t kVolumeStep = 5; // CUSTOM - added
using ConnectionState = drivers::Bluetooth::ConnectionState; using ConnectionState = drivers::Bluetooth::ConnectionState;
@ -101,7 +102,11 @@ auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
if (volume_ == 100) { if (volume_ == 100) {
return false; return false;
} }
volume_++; if (volume_ > 100 - kVolumeStep) {
volume_ = 100;
} else {
volume_ += kVolumeStep;
}
SetVolume(volume_); SetVolume(volume_);
return true; return true;
} }
@ -110,7 +115,11 @@ auto BluetoothAudioOutput::AdjustVolumeDown() -> bool {
if (volume_ == 0) { if (volume_ == 0) {
return false; return false;
} }
volume_--; if (volume_ < kVolumeStep) {
volume_ = 0;
} else {
volume_ -= kVolumeStep;
}
SetVolume(volume_); SetVolume(volume_);
return true; return true;
} }

@ -40,6 +40,7 @@ static constexpr uint16_t kMinVolume = 0b0;
static constexpr uint16_t kMaxVolumeBeforeClipping = 0x185; static constexpr uint16_t kMaxVolumeBeforeClipping = 0x185;
static constexpr uint16_t kLineLevelVolume = 0x13d; static constexpr uint16_t kLineLevelVolume = 0x13d;
static constexpr uint16_t kDefaultVolume = 0x100; static constexpr uint16_t kDefaultVolume = 0x100;
static constexpr uint16_t kVolumeStep = 5; // CUSTOM - added
I2SAudioOutput::I2SAudioOutput(drivers::IGpios& expander, I2SAudioOutput::I2SAudioOutput(drivers::IGpios& expander,
drivers::OutputBuffers& buffers) drivers::OutputBuffers& buffers)
@ -140,21 +141,29 @@ auto I2SAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
} }
auto I2SAudioOutput::AdjustVolumeUp() -> bool { auto I2SAudioOutput::AdjustVolumeUp() -> bool {
if (GetVolume() >= max_volume_) { uint16_t vol = GetVolume();
if (vol >= max_volume_) {
return false; return false;
} }
SetVolume(GetVolume() + 1);
if (vol > max_volume_ - kVolumeStep) {
SetVolume(max_volume_);
} else {
SetVolume(vol + kVolumeStep);
}
return true; return true;
} }
auto I2SAudioOutput::AdjustVolumeDown() -> bool { auto I2SAudioOutput::AdjustVolumeDown() -> bool {
if (GetVolume() == kMinVolume) { uint16_t vol = GetVolume();
if (vol == kMinVolume) {
return false; return false;
} }
if (GetVolume() <= kMinVolume + 1) { if (vol <= kMinVolume + kVolumeStep) {
SetVolume(0); SetVolume(0);
} else { } else {
SetVolume(GetVolume() - 1); SetVolume(vol - kVolumeStep);
} }
return true; return true;
} }

Loading…
Cancel
Save