From ade00945951ff49481a161479f7d9798cc4c564f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 12 Apr 2024 14:36:03 +1000 Subject: switch to software volume scaling (it's bad tho i need daniel to do maths for me please) --- src/audio/bt_audio_output.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/audio/bt_audio_output.cpp') 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 +#include #include #include -#include #include #include @@ -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(v, 0, 0x7f); + volume_ = std::clamp(v, 0, 100); + bg_worker_.Dispatch([&]() { + 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(round(static_cast(volume_) * 100.0 / 0x7f)); + return static_cast(round(static_cast(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([&]() { bluetooth_.SetVolume(volume_); }); + SetVolume(volume_); return true; } @@ -95,7 +100,7 @@ auto BluetoothAudioOutput::AdjustVolumeDown() -> bool { return false; } volume_--; - bg_worker_.Dispatch([&]() { bluetooth_.SetVolume(volume_); }); + SetVolume(volume_); return true; } -- cgit v1.2.3