diff --git a/components/lightsnapcast/include/player.h b/components/lightsnapcast/include/player.h index 84eac1b..13abfc8 100644 --- a/components/lightsnapcast/include/player.h +++ b/components/lightsnapcast/include/player.h @@ -68,6 +68,7 @@ int8_t free_pcm_chunk(pcm_chunk_message_t *pcmChunk); int32_t player_latency_insert(int64_t newValue); int32_t player_send_snapcast_setting(snapcastSetting_t *setting); +int8_t player_get_snapcast_settings(snapcastSetting_t *setting); int32_t reset_latency_buffer(void); int32_t latency_buffer_full(bool *is_full, TickType_t wait); diff --git a/main/main.c b/main/main.c index 37bf7a8..d9428fe 100644 --- a/main/main.c +++ b/main/main.c @@ -928,7 +928,9 @@ static void http_get_task(void *pvParameters) { size_t typedMsgCurrentPos = 0; uint32_t typedMsgLen = 0; uint32_t offset = 0; + uint32_t payloadOffset = 0; uint32_t tmpData = 0; + int32_t payloadDataShift = 0; int flow_drain_counter = 0; #define BASE_MESSAGE_STATE 0 @@ -1427,122 +1429,60 @@ static void http_get_task(void *pvParameters) { } case PCM: { + size_t _tmp = tmp; + + offset = 0; + if (pcmData == NULL) { if (allocate_pcm_chunk_memory( &pcmData, wire_chnk.size) < 0) { pcmData = NULL; } - offset = 0; + tmpData = 0; remainderSize = 0; + payloadDataShift = 3; + payloadOffset = 0; } - // if (pcmData != NULL) - { - volatile uint32_t *sample; + while (_tmp--) { + tmpData |= ((uint32_t)start[offset++] + << (8 * payloadDataShift)); - int max = 0, begin = 0; - - while (remainderSize) { - tmpData |= ((uint32_t)start[begin++] - << (8 * (remainderSize - 1))); - - remainderSize--; - if (remainderSize < 0) { - ESP_LOGE(TAG, - "shift < 0 this " - "shouldn't " - "happen"); - - return; - } - } - - // check if we need to write - // a remaining sample - if (begin > 0) { - // need to reorder bytes - // in sample for correct - // playback - uint8_t dummy1; - uint32_t dummy2 = 0; - - // TODO: find a more - // clever way to do this, - // best would be to - // actually store it the - // right way in the first - // place - dummy1 = tmpData >> 24; - dummy2 |= (uint32_t)dummy1 << 16; - dummy1 = tmpData >> 16; - dummy2 |= (uint32_t)dummy1 << 24; - dummy1 = tmpData >> 8; - dummy2 |= (uint32_t)dummy1 << 0; - dummy1 = tmpData >> 0; - dummy2 |= (uint32_t)dummy1 << 8; - tmpData = dummy2; + payloadDataShift--; + if (payloadDataShift < 0) { + payloadDataShift = 3; if ((pcmData) && (pcmData->fragment->payload)) { + volatile uint32_t *sample; + uint8_t dummy1; + uint32_t dummy2 = 0; + + // TODO: find a more + // clever way to do this, + // best would be to + // actually store it the + // right way in the first + // place + dummy1 = tmpData >> 24; + dummy2 |= (uint32_t)dummy1 << 16; + dummy1 = tmpData >> 16; + dummy2 |= (uint32_t)dummy1 << 24; + dummy1 = tmpData >> 8; + dummy2 |= (uint32_t)dummy1 << 0; + dummy1 = tmpData >> 0; + dummy2 |= (uint32_t)dummy1 << 8; + tmpData = dummy2; + sample = (volatile uint32_t *)(&( - pcmData->fragment->payload[offset])); + pcmData->fragment + ->payload[payloadOffset])); *sample = (volatile uint32_t)tmpData; + + payloadOffset += 4; } - offset += 4; - } - - remainderSize = (tmp - begin) % 4; - max = (tmp - begin) - remainderSize; - - for (int i = begin; i < max; i += 4) { - // TODO: for now - // fragmented payload is - // not supported and the - // whole chunk is - // expected to be in the - // first fragment - tmpData = ((uint32_t)start[i] << 16) | - ((uint32_t)start[i + 1] << 24) | - ((uint32_t)start[i + 2] << 0) | - ((uint32_t)start[i + 3] << 8); - - // ensure 32bit aligned write - if ((pcmData) && (pcmData->fragment->payload)) { - sample = (volatile uint32_t *)(&( - pcmData->fragment->payload[offset])); - *sample = (volatile uint32_t)tmpData; - } - - offset += 4; - } - - tmpData = 0; - while (remainderSize) { - tmpData |= ((uint32_t)start[max++] - << (8 * (remainderSize - 1))); - - remainderSize--; - - if (remainderSize < 0) { - ESP_LOGE(TAG, - "shift < 0 this " - "shouldn't " - "happen"); - - return; - } - } - - remainderSize = (tmp - begin) % 4; - if (remainderSize) { - remainderSize = - 4 - remainderSize; // these are the still - // needed bytes for next - // round - tmpData <<= - (8 * remainderSize); // shift data to - // correct position + tmpData = 0; } } @@ -1657,6 +1597,12 @@ static void http_get_task(void *pvParameters) { case PCM: { size_t decodedSize = wire_chnk.size; + // ESP_LOGW(TAG, "got + // PCM chunk, + // typedMsgCurrentPos + // %d", + // typedMsgCurrentPos); + if (pcmData) { pcmData->timestamp = wire_chnk.timestamp; } @@ -2735,7 +2681,15 @@ void app_main(void) { ESP_LOGI(TAG, "Start codec chip"); board_handle = audio_board_init(); - ESP_LOGI(TAG, "Audio board_init done"); + if (board_handle) { + ESP_LOGI(TAG, "Audio board_init done"); + } else { + ESP_LOGE(TAG, + "Audio board couldn't be initialized. Check menuconfig if project " + "is configured right or check your wiring!"); + + vTaskDelay(portMAX_DELAY); + } audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START); diff --git a/sdkconfig b/sdkconfig index a914a7a..98ea3ba 100644 --- a/sdkconfig +++ b/sdkconfig @@ -130,8 +130,8 @@ CONFIG_PARTITION_TABLE_MD5=y # # Audio HAL # -CONFIG_AUDIO_BOARD_CUSTOM=y -# CONFIG_ESP_LYRAT_V4_3_BOARD is not set +# CONFIG_AUDIO_BOARD_CUSTOM is not set +CONFIG_ESP_LYRAT_V4_3_BOARD=y # CONFIG_ESP_LYRAT_V4_2_BOARD is not set # CONFIG_ESP_LYRATD_MSC_V2_1_BOARD is not set # CONFIG_ESP_LYRATD_MSC_V2_2_BOARD is not set @@ -140,41 +140,6 @@ CONFIG_AUDIO_BOARD_CUSTOM=y # CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD is not set # end of Audio HAL -# -# Custom Audio Board -# -# CONFIG_DAC_PCM51XX is not set -# CONFIG_DAC_PCM5102A is not set -# CONFIG_DAC_MA120 is not set -# CONFIG_DAC_MA120X0 is not set -CONFIG_DAC_ADAU1961=y - -# -# DAC I2C control interface -# -CONFIG_DAC_I2C_SDA=12 -CONFIG_DAC_I2C_SCL=14 -CONFIG_DAC_I2C_ADDR=0x70 -# end of DAC I2C control interface - -# -# I2S master interface -# -CONFIG_MASTER_I2S_MCLK_PIN=3 -CONFIG_MASTER_I2S_BCK_PIN=15 -CONFIG_MASTER_I2S_LRCK_PIN=13 -CONFIG_MASTER_I2S_DATAOUT_PIN=4 -# end of I2S master interface - -# -# I2S slave interface -# -CONFIG_SLAVE_I2S_BCK_PIN=26 -CONFIG_SLAVE_I2S_LRCK_PIN=12 -CONFIG_SLAVE_I2S_DATAOUT_PIN=5 -# end of I2S slave interface -# end of Custom Audio Board - # # ESP32 DSP processor config # @@ -184,25 +149,13 @@ CONFIG_USE_DSP_PROCESSOR=y # CONFIG_SNAPCLIENT_DSP_FLOW_BIAMP is not set CONFIG_SNAPCLIENT_DSP_FLOW_BASS_TREBLE_EQ=y CONFIG_USE_BIQUAD_ASM=y -# CONFIG_SNAPCLIENT_USE_SOFT_VOL is not set +CONFIG_SNAPCLIENT_USE_SOFT_VOL=y # end of ESP32 DSP processor config # # Snapclient Ethernet Configuration # -CONFIG_SNAPCLIENT_ENABLE_ETHERNET=y -CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET=y -# CONFIG_SNAPCLIENT_USE_DM9051 is not set -# CONFIG_SNAPCLIENT_USE_W5500 is not set -# CONFIG_SNAPCLIENT_ETH_PHY_IP101 is not set -# CONFIG_SNAPCLIENT_ETH_PHY_RTL8201 is not set -CONFIG_SNAPCLIENT_ETH_PHY_LAN8720=y -# CONFIG_SNAPCLIENT_ETH_PHY_DP83848 is not set -# CONFIG_SNAPCLIENT_ETH_PHY_KSZ8041 is not set -CONFIG_SNAPCLIENT_ETH_MDC_GPIO=23 -CONFIG_SNAPCLIENT_ETH_MDIO_GPIO=18 -CONFIG_SNAPCLIENT_ETH_PHY_RST_GPIO=17 -CONFIG_SNAPCLIENT_ETH_PHY_ADDR=0 +# CONFIG_SNAPCLIENT_ENABLE_ETHERNET is not set # end of Snapclient Ethernet Configuration # diff --git a/sdkconfig.old b/sdkconfig.old index 352d80f..e964cea 100644 --- a/sdkconfig.old +++ b/sdkconfig.old @@ -184,7 +184,7 @@ CONFIG_USE_DSP_PROCESSOR=y # CONFIG_SNAPCLIENT_DSP_FLOW_BIAMP is not set CONFIG_SNAPCLIENT_DSP_FLOW_BASS_TREBLE_EQ=y CONFIG_USE_BIQUAD_ASM=y -# CONFIG_SNAPCLIENT_USE_SOFT_VOL is not set +CONFIG_SNAPCLIENT_USE_SOFT_VOL=y # end of ESP32 DSP processor config #