From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/drivers/bluetooth.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/drivers/bluetooth.cpp') diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 5d1b35fa..40be530e 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -25,7 +25,6 @@ #include "freertos/portmacro.h" #include "freertos/projdefs.h" #include "freertos/timers.h" -#include "sample.hpp" #include "tinyfsm/include/tinyfsm.hpp" #include "bluetooth_types.hpp" -- cgit v1.2.3 From 26eb580043ad176bdc58d996f30d470e1073ef00 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 21:52:59 +1000 Subject: move driver includes into a subdir as well --- src/drivers/bluetooth.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/drivers/bluetooth.cpp') diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 40be530e..4caffae7 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -1,4 +1,4 @@ -#include "bluetooth.hpp" +#include "drivers/bluetooth.hpp" #include @@ -27,9 +27,9 @@ #include "freertos/timers.h" #include "tinyfsm/include/tinyfsm.hpp" -#include "bluetooth_types.hpp" +#include "drivers/bluetooth_types.hpp" +#include "drivers/nvs.hpp" #include "memory_resource.hpp" -#include "nvs.hpp" #include "tasks.hpp" namespace drivers { @@ -47,8 +47,8 @@ auto gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t* param) -> void { bluetooth::events::internal::Gap{.type = event, .param = param}); } -auto avrcp_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t* param) - -> void { +auto avrcp_cb(esp_avrc_ct_cb_event_t event, + esp_avrc_ct_cb_param_t* param) -> void { esp_avrc_ct_cb_param_t copy = *param; sBgWorker->Dispatch([=]() { auto lock = bluetooth::BluetoothState::lock(); -- cgit v1.2.3 From 265049c5192cf0ce862c7db7b4745636afb6c17b Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 8 May 2024 16:03:03 +1000 Subject: Count samples going in and out of the drain buffer This is a more accurate way of knowing which track is playing when, and also simplifies a lot of fragile logic in audio_fsm --- src/drivers/bluetooth.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/drivers/bluetooth.cpp') diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 4caffae7..fcb764f6 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -38,6 +38,7 @@ namespace drivers { DRAM_ATTR static StreamBufferHandle_t sStream = nullptr; DRAM_ATTR static std::atomic sVolumeFactor = 1.f; +DRAM_ATTR static std::atomic sSamplesUsed = 0; static tasks::WorkerPool* sBgWorker; @@ -47,8 +48,8 @@ auto gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t* param) -> void { bluetooth::events::internal::Gap{.type = event, .param = param}); } -auto avrcp_cb(esp_avrc_ct_cb_event_t event, - esp_avrc_ct_cb_param_t* param) -> void { +auto avrcp_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t* param) + -> void { esp_avrc_ct_cb_param_t copy = *param; sBgWorker->Dispatch([=]() { auto lock = bluetooth::BluetoothState::lock(); @@ -73,6 +74,13 @@ IRAM_ATTR auto a2dp_data_cb(uint8_t* buf, int32_t buf_size) -> int32_t { } size_t bytes_received = xStreamBufferReceive(stream, buf, buf_size, 0); + size_t samples_received = bytes_received / 2; + if (UINT32_MAX - sSamplesUsed < samples_received) { + sSamplesUsed = samples_received - (UINT32_MAX - sSamplesUsed); + } else { + sSamplesUsed += samples_received; + } + // Apply software volume scaling. int16_t* samples = reinterpret_cast(buf); float factor = sVolumeFactor.load(); @@ -165,6 +173,10 @@ auto Bluetooth::SetVolumeFactor(float f) -> void { sVolumeFactor = f; } +auto Bluetooth::SamplesUsed() -> uint32_t { + return sSamplesUsed; +} + auto Bluetooth::SetEventHandler(std::function cb) -> void { auto lock = bluetooth::BluetoothState::lock(); -- cgit v1.2.3