Apply volume correction factor for Bluetooth sink.

This commit is contained in:
Sebastien
2019-10-16 17:08:05 -04:00
parent 0a4a6b16c3
commit cf5ee95adf
3 changed files with 22 additions and 3 deletions

View File

@@ -22,6 +22,7 @@
#include "squeezelite.h" #include "squeezelite.h"
#include "bt_app_sink.h" #include "bt_app_sink.h"
#include "raop_sink.h" #include "raop_sink.h"
#include <math.h>
#define LOCK_O mutex_lock(outputbuf->mutex) #define LOCK_O mutex_lock(outputbuf->mutex)
#define UNLOCK_O mutex_unlock(outputbuf->mutex) #define UNLOCK_O mutex_unlock(outputbuf->mutex)
@@ -90,6 +91,8 @@ static void sink_data_handler(const uint8_t *data, uint32_t len)
/**************************************************************************************** /****************************************************************************************
* BT sink command handler * BT sink command handler
*/ */
extern u16_t get_adjusted_volume(u16_t volume);
static void bt_sink_cmd_handler(bt_sink_cmd_t cmd, ...) static void bt_sink_cmd_handler(bt_sink_cmd_t cmd, ...)
{ {
va_list args; va_list args;
@@ -133,7 +136,7 @@ static void bt_sink_cmd_handler(bt_sink_cmd_t cmd, ...)
break; break;
case BT_SINK_VOLUME: { case BT_SINK_VOLUME: {
u16_t volume = (u16_t) va_arg(args, u32_t); u16_t volume = (u16_t) va_arg(args, u32_t);
volume *= 65536 / 128; volume = get_adjusted_volume(volume);
set_volume(volume, volume); set_volume(volume, volume);
break; break;
} }

View File

@@ -193,7 +193,7 @@ $(document).ready(function(){
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'ERROR');
} },
complete: function(response) { complete: function(response) {
var returnedResponse = JSON.parse(response.responseText); var returnedResponse = JSON.parse(response.responseText);
console.log(response.responseText); console.log(response.responseText);
@@ -210,7 +210,7 @@ $(document).ready(function(){
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'ERROR');
} },
complete: function(response) { complete: function(response) {
console.log('reboot call completed'); console.log('reboot call completed');

View File

@@ -43,6 +43,7 @@
#include "trace.h" #include "trace.h"
#include "wifi_manager.h" #include "wifi_manager.h"
#include "squeezelite-ota.h" #include "squeezelite-ota.h"
#include <math.h>
static EventGroupHandle_t wifi_event_group; static EventGroupHandle_t wifi_event_group;
bool enable_bt_sink=false; bool enable_bt_sink=false;
@@ -153,6 +154,21 @@ char * process_ota_url(){
//CONFIG_A2DP_CONTROL_DELAY_MS=500 //CONFIG_A2DP_CONTROL_DELAY_MS=500
//CONFIG_A2DP_CONNECT_TIMEOUT_MS=1000 //CONFIG_A2DP_CONNECT_TIMEOUT_MS=1000
//CONFIG_WIFI_MANAGER_MAX_RETRY=2 //CONFIG_WIFI_MANAGER_MAX_RETRY=2
u16_t get_adjusted_volume(u16_t volume){
char * str_factor = get_nvs_value_alloc_default(NVS_TYPE_STR, "volumefactor", "3", 0);
if(str_factor != NULL ){
float factor = atof(str_factor);
free(str_factor);
return (u16_t) (65536.0f * powf( (volume/ 128.0f), factor) );
}
else {
ESP_LOGW(TAG,"Error retrieving volume factor. Returning unmodified volume level. ");
return volume;
}
}
void register_default_nvs(){ void register_default_nvs(){
nvs_value_set_default(NVS_TYPE_STR, "bt_sink_name", CONFIG_BT_NAME, 0); nvs_value_set_default(NVS_TYPE_STR, "bt_sink_name", CONFIG_BT_NAME, 0);