diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-04-02 15:03:49 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-04-02 15:03:49 +1100 |
| commit | 25dca40e5dab82c5a814233813c24180fcf975eb (patch) | |
| tree | 5814aa946a5e260a688831a028031e6613eecc2f /src | |
| parent | e20ebe7574db5aedc73f07b7bb3a0a01eae93c84 (diff) | |
| download | tangara-fw-25dca40e5dab82c5a814233813c24180fcf975eb.tar.gz | |
Fix volume getters/setters for bluetooth
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/bt_audio_output.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/audio/bt_audio_output.cpp b/src/audio/bt_audio_output.cpp index 20ed7bb3..7d6bade2 100644 --- a/src/audio/bt_audio_output.cpp +++ b/src/audio/bt_audio_output.cpp @@ -55,26 +55,30 @@ auto BluetoothAudioOutput::GetVolume() -> uint16_t { } auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t { - return static_cast<uint_fast8_t>(static_cast<int>(volume_) * 100 / 0x7f); + return static_cast<uint_fast8_t>(round(static_cast<int>(volume_) * 100.0 / 0x7f)); } auto BluetoothAudioOutput::SetVolumePct(uint_fast8_t val) -> bool { - if (val < 100) { + if (val > 100) { return false; } - SetVolume(val / 100 * 0x7f); + uint16_t vol = (val * (0x7f))/100; + SetVolume(vol); return true; } auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t { - return log(GetVolumePct()/100) * 20; + double pct = GetVolumePct()/100.0; + if (pct <= 0) { + pct = 0.01; + } + int_fast16_t db = log(pct) * 20; + return db; } auto BluetoothAudioOutput::SetVolumeDb(int_fast16_t val) -> bool { - auto pct = pow(2, val / 20.0) * 100; - ESP_LOGI("Audio", "Bluetooth audio pct: %d", (int)pct); - SetVolumePct(pct); - return true; + double pct = exp(val / 20.0) * 100; + return SetVolumePct(pct); } auto BluetoothAudioOutput::AdjustVolumeUp() -> bool { |
