diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-04-12 14:36:03 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-04-12 14:36:03 +1000 |
| commit | ade00945951ff49481a161479f7d9798cc4c564f (patch) | |
| tree | 3e244f54c4fa3f5d640d6017cf0f05ad079a90ab /src/audio | |
| parent | b319b3f07f61ce7212f84ea6e7e69d27ef97ef5e (diff) | |
| download | tangara-fw-ade00945951ff49481a161479f7d9798cc4c564f.tar.gz | |
switch to software volume scaling (it's bad tho i need daniel to do maths for me please)
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/bt_audio_output.cpp | 27 | ||||
| -rw-r--r-- | src/audio/include/bt_audio_output.hpp | 3 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/audio/bt_audio_output.cpp b/src/audio/bt_audio_output.cpp index 7d6bade2..1b8866c1 100644 --- a/src/audio/bt_audio_output.cpp +++ b/src/audio/bt_audio_output.cpp @@ -7,9 +7,9 @@ #include "bt_audio_output.hpp" #include <algorithm> +#include <cmath> #include <cstddef> #include <cstdint> -#include <cmath> #include <memory> #include <variant> @@ -32,7 +32,7 @@ namespace audio { BluetoothAudioOutput::BluetoothAudioOutput(StreamBufferHandle_t s, drivers::Bluetooth& bt, tasks::WorkerPool& p) - : IAudioOutput(s), bluetooth_(bt), bg_worker_(p), volume_(10) {} + : IAudioOutput(s), bluetooth_(bt), bg_worker_(p), volume_() {} BluetoothAudioOutput::~BluetoothAudioOutput() {} @@ -44,10 +44,16 @@ auto BluetoothAudioOutput::changeMode(Modes mode) -> void { } } -auto BluetoothAudioOutput::SetVolumeImbalance(int_fast8_t balance) -> void {} +auto BluetoothAudioOutput::SetVolumeImbalance(int_fast8_t balance) -> void { + // FIXME: Support two separate scaling factors in the bluetooth driver. +} auto BluetoothAudioOutput::SetVolume(uint16_t v) -> void { - volume_ = std::clamp<uint16_t>(v, 0, 0x7f); + volume_ = std::clamp<uint16_t>(v, 0, 100); + bg_worker_.Dispatch<void>([&]() { + float factor = volume_ / 100.; + bluetooth_.SetVolumeFactor(factor); + }); } auto BluetoothAudioOutput::GetVolume() -> uint16_t { @@ -55,20 +61,19 @@ auto BluetoothAudioOutput::GetVolume() -> uint16_t { } auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t { - return static_cast<uint_fast8_t>(round(static_cast<int>(volume_) * 100.0 / 0x7f)); + return static_cast<uint_fast8_t>(round(static_cast<int>(volume_))); } auto BluetoothAudioOutput::SetVolumePct(uint_fast8_t val) -> bool { if (val > 100) { return false; } - uint16_t vol = (val * (0x7f))/100; - SetVolume(vol); + SetVolume(val); return true; } auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t { - double pct = GetVolumePct()/100.0; + double pct = GetVolumePct() / 100.0; if (pct <= 0) { pct = 0.01; } @@ -82,11 +87,11 @@ auto BluetoothAudioOutput::SetVolumeDb(int_fast16_t val) -> bool { } auto BluetoothAudioOutput::AdjustVolumeUp() -> bool { - if (volume_ == 0x7f) { + if (volume_ == 100) { return false; } volume_++; - bg_worker_.Dispatch<void>([&]() { bluetooth_.SetVolume(volume_); }); + SetVolume(volume_); return true; } @@ -95,7 +100,7 @@ auto BluetoothAudioOutput::AdjustVolumeDown() -> bool { return false; } volume_--; - bg_worker_.Dispatch<void>([&]() { bluetooth_.SetVolume(volume_); }); + SetVolume(volume_); return true; } diff --git a/src/audio/include/bt_audio_output.hpp b/src/audio/include/bt_audio_output.hpp index 74b0301a..cc3b2462 100644 --- a/src/audio/include/bt_audio_output.hpp +++ b/src/audio/include/bt_audio_output.hpp @@ -54,7 +54,8 @@ class BluetoothAudioOutput : public IAudioOutput { private: drivers::Bluetooth& bluetooth_; tasks::WorkerPool& bg_worker_; - uint8_t volume_; + + uint16_t volume_; }; } // namespace audio |
