diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-02 04:19:50 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-02 04:19:50 +0000 |
| commit | b229f452a6a0c8e047e1e9c0c709953ed822c610 (patch) | |
| tree | 5814aa946a5e260a688831a028031e6613eecc2f /src/audio/bt_audio_output.cpp | |
| parent | 0d0c4b2307cac8436fea7276956f293262b265ed (diff) | |
| parent | 25dca40e5dab82c5a814233813c24180fcf975eb (diff) | |
| download | tangara-fw-b229f452a6a0c8e047e1e9c0c709953ed822c610.tar.gz | |
Merge pull request 'lua-volume' (#60) from lua-volume into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/60
Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
Diffstat (limited to 'src/audio/bt_audio_output.cpp')
| -rw-r--r-- | src/audio/bt_audio_output.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/audio/bt_audio_output.cpp b/src/audio/bt_audio_output.cpp index 04daf71f..7d6bade2 100644 --- a/src/audio/bt_audio_output.cpp +++ b/src/audio/bt_audio_output.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include <cstddef> #include <cstdint> +#include <cmath> #include <memory> #include <variant> @@ -54,11 +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) { + return false; + } + uint16_t vol = (val * (0x7f))/100; + SetVolume(vol); + return true; } auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t { - return 0; + 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 { + double pct = exp(val / 20.0) * 100; + return SetVolumePct(pct); } auto BluetoothAudioOutput::AdjustVolumeUp() -> bool { |
