Skip to content

Commit

Permalink
make equalizer a string + make sure output-i2s is exited
Browse files Browse the repository at this point in the history
- Can't really use BLOB (creates issue with HTTP visualizer)
- Player was stuck after WiFi loss b/c with some race conditions, BT deinit crashes and creates the reboot wanted after 5*5 failures. But when BT does not crash, reboot was not happening and player was stuck with slimproto not exited and player not rebooted
  • Loading branch information
philippe44 committed Jul 1, 2021
1 parent 0db9631 commit 48e8525
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
30 changes: 22 additions & 8 deletions components/squeezelite/equalizer.c
Expand Up @@ -8,7 +8,7 @@
*
*/

#include "nvs_utilities.h"
#include "platform_config.h"
#include "squeezelite.h"
#include "equalizer.h"
#include "esp_equalizer.h"
Expand All @@ -27,13 +27,18 @@ static struct {
* initialize equalizer
*/
void equalizer_init(void) {
s8_t *gain = get_nvs_value_alloc(NVS_TYPE_BLOB, "equalizer");

if (!gain) gain = calloc(EQ_BANDS, sizeof(*gain));
s8_t gain[EQ_BANDS] = { };
char *config = config_alloc_get(NVS_TYPE_STR, "equalizer");
char *p = strtok(config, ", !");

for (int i = 0; p && i < EQ_BANDS; i++) {
gain[i] = atoi(p);
p = strtok(NULL, ", :");
}

free(config);
equalizer_update(gain);
free(gain);


LOG_INFO("initializing equalizer");
}

Expand Down Expand Up @@ -83,9 +88,18 @@ void equalizer_close(void) {
* update equalizer gain
*/
void equalizer_update(s8_t *gain) {
store_nvs_value_len(NVS_TYPE_BLOB, "equalizer", gain, EQ_BANDS * sizeof(*gain));
char config[EQ_BANDS * 4 + 1] = { };
char *p = config;

for (int i = 0; i < EQ_BANDS; i++) {
equalizer.gain[i] = gain[i];
if (gain[i] < 0) *p++ = '-';
*p++ = (gain[i] / 10) + 0x30;
*p++ = (gain[i] % 10) + 0x30;
if (i < EQ_BANDS - 1) *p++ = ',';
}

for (int i = 0; i < EQ_BANDS; i++) equalizer.gain[i] = gain[i];
config_set_value(NVS_TYPE_STR, "equalizer", config);
equalizer.update = true;
}

Expand Down
5 changes: 3 additions & 2 deletions components/squeezelite/output_i2s.c
Expand Up @@ -573,10 +573,11 @@ static void output_thread_i2s(void *arg) {
SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time);

}

vTaskDelete(NULL);

if (spdif.enabled) free(spdif.buf);
ended = true;

vTaskDelete(NULL);
}

/****************************************************************************************
Expand Down
3 changes: 3 additions & 0 deletions main/esp_app_main.c
Expand Up @@ -326,6 +326,9 @@ void register_default_nvs(){
ESP_LOGD(TAG,"Registering default value for key %s, value %s", "bypass_wm", "0");
config_set_default(NVS_TYPE_STR, "bypass_wm", "0", 0);

ESP_LOGD(TAG,"Registering default value for equalizer");
config_set_default(NVS_TYPE_STR, "equalizer", "", 0);

ESP_LOGD(TAG,"Registering default Audio control board type %s, value ","actrls_config");
config_set_default(NVS_TYPE_STR, "actrls_config", "", 0);

Expand Down

0 comments on commit 48e8525

Please sign in to comment.