From 9156885a17dada5aba9debe8640410313715d755 Mon Sep 17 00:00:00 2001 From: David Beck Date: Mon, 20 May 2024 17:05:41 -0700 Subject: [PATCH 01/28] fix(resample): function name changed in dependent package (#22) in v0.9.8 the Resample Package was refactored, this resulted in the `setStream` being renamed `setOutput`. This took a good while to track down because it wasn't clear why the `override` was throwing an error on the `virtual` `void`. This brings the code back into a functional state. --- src/api/SnapOutput.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index e5d87b6..085195c 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -88,7 +88,7 @@ class SnapOutput : public AudioInfoSupport { /// Defines the audio output chain to the final output void setOutput(AudioOutput &output) { this->out = &output; // final output - resample.setStream(output); + resample.setOutput(output); vol_stream.setStream(resample); // adjust volume decoder_stream.setStream(&vol_stream); // decode to pcm } @@ -266,4 +266,4 @@ class SnapOutput : public AudioInfoSupport { } }; -} \ No newline at end of file +} From 69ca93b5784f9d68760f64ae9a438d5be76115b7 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 24 Jun 2024 15:00:28 +0200 Subject: [PATCH 02/28] Compile error in SnapOutput --- src/api/SnapOutput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index e5d87b6..430b6b3 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -88,7 +88,7 @@ class SnapOutput : public AudioInfoSupport { /// Defines the audio output chain to the final output void setOutput(AudioOutput &output) { this->out = &output; // final output - resample.setStream(output); + resample.setOutput(output); vol_stream.setStream(resample); // adjust volume decoder_stream.setStream(&vol_stream); // decode to pcm } From 0003846d6e2ce1acee49d62d414879ca32106318 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 24 Jun 2024 15:20:37 +0200 Subject: [PATCH 03/28] MDNS support for ESP 3.0.1 --- src/SnapClient.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SnapClient.h b/src/SnapClient.h index 080c560..8a877b2 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -177,7 +177,11 @@ class SnapClient { // we just take the first address int nrOfServices = MDNS.queryService("snapcast", "tcp"); if (nrOfServices > 0) { +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) + server_ip = MDNS.address(0); +#else server_ip = MDNS.IP(0); +#endif char str_address[20] = {0}; sprintf(str_address, "%d.%d.%d.%d", server_ip[0], server_ip[1], server_ip[2], server_ip[3]); From 8f8404a321dd5387aac77d6f91eede7df9e671a6 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Tue, 25 Jun 2024 15:47:27 +0200 Subject: [PATCH 04/28] SnapProcessor: print ip on connection error --- src/api/SnapProcessor.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index 83d48b3..ae42ca7 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -222,7 +222,11 @@ class SnapProcessor { if (p_client->connected()) return true; p_client->setTimeout(CONFIG_CLIENT_TIMEOUT_SEC); if (!p_client->connect(server_ip, server_port)) { - ESP_LOGE(TAG, "... socket connect failed errno=%d", errno); + char str_address[50]; + sprintf(str_address, "%d.%d.%d.%d:%d", server_ip[0], server_ip[1], + server_ip[2], server_ip[3], server_port); + + ESP_LOGE(TAG, "Socket connect to %s failed errno=%d", str_address, errno); delay(4000); return false; } From 622c4e64c67a6a28c194233ac112b96ee8c971ce Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Tue, 25 Jun 2024 18:38:02 +0200 Subject: [PATCH 05/28] provide fast loop option --- src/SnapClient.h | 5 ++++ src/api/SnapProcessor.h | 60 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/SnapClient.h b/src/SnapClient.h index 8a877b2..04ff100 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -145,6 +145,11 @@ class SnapClient { p_snapprocessor = &processor; } + /// Provides the actual processor + SnapProcessor& snapProcessor(){ + return *p_snapprocessor; + } + /// Defines the Snap output implementation to be used void setSnapOutput(SnapOutput &out){ p_snapprocessor->setSnapOutput(out); diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index ae42ca7..9c9894a 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -44,6 +44,7 @@ class SnapProcessor { resizeData(); } header_received = false; + loop_status = LoopStart; return result; } @@ -70,7 +71,12 @@ class SnapProcessor { void setStartTask(bool flag) { http_task_start = flag; } /// Call via SnapClient in Arduino Loop! - virtual void doLoop() { processLoopStep(); } + virtual void doLoop() { + if (is_fast_loop) + processLoopStepFast(); + else + processLoopStep(); + } /// Defines the output class void setOutput(AudioOutput &output) { p_snap_output->setOutput(output); } @@ -96,6 +102,11 @@ class SnapProcessor { p_snap_output->setAudioInfo(info); } + // Select loop processing with minimum delays + void setFastLoop(bool flag){ + is_fast_loop = flag; + } + protected: const char *TAG = "SnapProcessor"; // WiFiClient default_client; @@ -124,6 +135,53 @@ class SnapProcessor { bool header_received = false; bool is_time_set = false; SnapTime &snap_time = SnapTime::instance(); + bool is_fast_loop = false; + enum loop_status_enum { LoopStart, LoopStep, LoopEnd }; + loop_status_enum loop_status = LoopStart; + + bool processLoopStepFast() { + switch (loop_status) { + case LoopStart: { + if (connectClient()) { + ESP_LOGI(TAG, "... connected"); + } else { + delay(10); + return true; + } + + now = snap_time.time(); + if (!writeHallo()) { + ESP_LOGI(TAG, "writeHallo"); + return false; + } + loop_status = LoopStep; + return true; + } + + case LoopStep: { + if (!processMessageLoop()) { + loop_status = LoopEnd; + } + // some additional processing while we wait for data + processExt(); + // logHeap(); + checkHeap(); + return true; + } + + case LoopEnd: { + loop_status = LoopStart; + if (id_counter % 100 == 0) { + logHeap(); + } + // For rtos, give audio output some space + delay(1); + return true; + } + } + // we should not get here + return false; + } bool processLoopStep() { if (connectClient()) { From 9970be63e441bd1c86c9cb3834d612507dccaffc Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 18 Jul 2024 08:58:07 +0200 Subject: [PATCH 06/28] connect to server when calling begin() --- .../SnapClientEthernet/SnapClientEthernet.ino | 44 +++++++++++++++++++ src/SnapClient.h | 2 +- src/api/SnapProcessor.h | 21 ++++++--- 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 examples/SnapClientEthernet/SnapClientEthernet.ino diff --git a/examples/SnapClientEthernet/SnapClientEthernet.ino b/examples/SnapClientEthernet/SnapClientEthernet.ino new file mode 100644 index 0000000..84a9753 --- /dev/null +++ b/examples/SnapClientEthernet/SnapClientEthernet.ino @@ -0,0 +1,44 @@ +// We just test the output by providing a hex dump of the received data + +#include +#include +#include "AudioTools.h" +#include "SnapClient.h" + +// Example settings for RP2040 +#define ETH_MISO 0 +#define ETH_MOSI 3 +#define ETH_SCLK 2 + +EthernetClient eth; +HexDumpOutput out; // final output +CopyDecoder codec; +SnapClient client(eth, out, codec); +byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +IPAddress ip(192, 168, 1, 177); + +void setup() { + Serial.begin(115200); + + SPI.setRX(ETH_MISO); + SPI.setTX(ETH_MOSI); + SPI.setSCK(ETH_SCLK); + SPI.begin(); + + // start the Ethernet connection: + if (!eth.begin(mac, ip)) { + Serial.print("Ethernet error"); + while (true); + } + + // Define CONFIG_SNAPCAST_SERVER_HOST in SnapConfig.h or here + client.setServerIP(IPAddress(192, 168, 1, 38)); + + // start snap client + if (!client.begin()) { + Serial.print("Connection error"); + while (true); + } +} + +void loop() { client.doLoop(); } \ No newline at end of file diff --git a/src/SnapClient.h b/src/SnapClient.h index 04ff100..7fd1ee9 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -156,7 +156,7 @@ class SnapClient { } /// Call from Arduino Loop - to receive and process the audio data - void doLoop() { p_snapprocessor->doLoop(); } + bool doLoop() { return p_snapprocessor->doLoop(); } protected: const char *TAG = "SnapClient"; diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index 9c9894a..afa36c8 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -32,12 +32,19 @@ class SnapProcessor { p_snap_output = &snap_output; } + /// Sets up the output and the client virtual bool begin() { - bool result = false; + bool result = true; + // start output chain if (output_start) { result = audioBegin(); } + // connect to snapcast server + if(!connectClient()){ + result = false; + } + if (http_task_start) { last_time_sync = 0; id_counter = 0; @@ -71,11 +78,11 @@ class SnapProcessor { void setStartTask(bool flag) { http_task_start = flag; } /// Call via SnapClient in Arduino Loop! - virtual void doLoop() { + bool doLoop() { if (is_fast_loop) - processLoopStepFast(); + return processLoopStepFast(); else - processLoopStep(); + return processLoopStep(); } /// Defines the output class @@ -146,7 +153,7 @@ class SnapProcessor { ESP_LOGI(TAG, "... connected"); } else { delay(10); - return true; + return false; } now = snap_time.time(); @@ -188,7 +195,7 @@ class SnapProcessor { ESP_LOGI(TAG, "... connected"); } else { delay(10); - return true; + return false; } now = snap_time.time(); @@ -275,9 +282,11 @@ class SnapProcessor { return true; } + /// connects to the server: returns true if we are connected bool connectClient() { ESP_LOGD(TAG, "start"); if (p_client->connected()) return true; + p_client->stop(); // for Ethernet.h p_client->setTimeout(CONFIG_CLIENT_TIMEOUT_SEC); if (!p_client->connect(server_ip, server_port)) { char str_address[50]; From 4fc2875d64c0d32a5c6d929ab7196adb25e9658e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 18 Jul 2024 09:26:21 +0200 Subject: [PATCH 07/28] DRAFT Ethernet Example --- .../SnapClientEthernet/SnapClientEthernet.ino | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/SnapClientEthernet/SnapClientEthernet.ino b/examples/SnapClientEthernet/SnapClientEthernet.ino index 84a9753..72b3a2f 100644 --- a/examples/SnapClientEthernet/SnapClientEthernet.ino +++ b/examples/SnapClientEthernet/SnapClientEthernet.ino @@ -1,17 +1,16 @@ -// We just test the output by providing a hex dump of the received data +// Example for EthernetClient: We just test the output by providing a hex dump of the received data -#include #include +#include #include "AudioTools.h" #include "SnapClient.h" -// Example settings for RP2040 -#define ETH_MISO 0 -#define ETH_MOSI 3 -#define ETH_SCLK 2 +#define ETH_MISO 23 +#define ETH_MOSI 19 +#define ETH_SCLK 18 EthernetClient eth; -HexDumpOutput out; // final output +HexDumpOutput out; // final output CopyDecoder codec; SnapClient client(eth, out, codec); byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; @@ -20,15 +19,17 @@ IPAddress ip(192, 168, 1, 177); void setup() { Serial.begin(115200); - SPI.setRX(ETH_MISO); - SPI.setTX(ETH_MOSI); - SPI.setSCK(ETH_SCLK); - SPI.begin(); + SPI.begin(ETH_SCLK, ETH_MISO, ETH_MOSI); // start the Ethernet connection: - if (!eth.begin(mac, ip)) { - Serial.print("Ethernet error"); - while (true); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + Ethernet.begin(mac, ip); + } + + // wait for link + while(Ethernet.linkStatus()!=LinkON){ + delay(10); } // Define CONFIG_SNAPCAST_SERVER_HOST in SnapConfig.h or here From 9e5255643a40e915c03722f3ac828f5f0f852b93 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 18 Jul 2024 09:41:13 +0200 Subject: [PATCH 08/28] Error message example --- examples/SnapClientEthernet/SnapClientEthernet.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/SnapClientEthernet/SnapClientEthernet.ino b/examples/SnapClientEthernet/SnapClientEthernet.ino index 72b3a2f..006d740 100644 --- a/examples/SnapClientEthernet/SnapClientEthernet.ino +++ b/examples/SnapClientEthernet/SnapClientEthernet.ino @@ -19,6 +19,7 @@ IPAddress ip(192, 168, 1, 177); void setup() { Serial.begin(115200); + // The ESP32 supports a flexible definition of the SPI pins SPI.begin(ETH_SCLK, ETH_MISO, ETH_MOSI); // start the Ethernet connection: @@ -37,7 +38,7 @@ void setup() { // start snap client if (!client.begin()) { - Serial.print("Connection error"); + Serial.print("Could not connect to snap server"); while (true); } } From f71f98209c10e4094b39a665ca64a00cc3bd20b2 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 18 Jul 2024 10:12:31 +0200 Subject: [PATCH 09/28] Ethernet example --- examples/SnapClientEthernet/SnapClientEthernet.ino | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/SnapClientEthernet/SnapClientEthernet.ino b/examples/SnapClientEthernet/SnapClientEthernet.ino index 006d740..96bf0d7 100644 --- a/examples/SnapClientEthernet/SnapClientEthernet.ino +++ b/examples/SnapClientEthernet/SnapClientEthernet.ino @@ -5,9 +5,10 @@ #include "AudioTools.h" #include "SnapClient.h" -#define ETH_MISO 23 -#define ETH_MOSI 19 -#define ETH_SCLK 18 +// #define ETH_MISO 23 +// #define ETH_MOSI 19 +// #define ETH_SCLK 18 +// #define ETH_CS 5 EthernetClient eth; HexDumpOutput out; // final output @@ -20,7 +21,9 @@ void setup() { Serial.begin(115200); // The ESP32 supports a flexible definition of the SPI pins - SPI.begin(ETH_SCLK, ETH_MISO, ETH_MOSI); + //SPI.begin(ETH_SCLK, ETH_MISO, ETH_MOSI, ETH_CS); + + SPI.begin(); // use default pins // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { From 7d6fd0bb3238862eb9a0417a8d7abf5714a51a5a Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 04:38:15 +0200 Subject: [PATCH 10/28] Connect to Wifi only for WiFiClient --- .gitignore | 4 +- CMakeCache.txt | 412 ++++++++++++++++++ .../SnapClientEthernet/SnapClientEthernet.ino | 52 ++- src/SnapClient.h | 60 ++- src/api/SnapLogger.h | 11 +- src/api/SnapProcessor.h | 4 +- 6 files changed, 511 insertions(+), 32 deletions(-) create mode 100644 CMakeCache.txt diff --git a/.gitignore b/.gitignore index 94d345d..de094a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .vscode/ build/ miniaudio.h -arduino-snapclient.code-workspace \ No newline at end of file +arduino-snapclient.code-workspace +_deps/ +CMakeFiles/ \ No newline at end of file diff --git a/CMakeCache.txt b/CMakeCache.txt new file mode 100644 index 0000000..d582c19 --- /dev/null +++ b/CMakeCache.txt @@ -0,0 +1,412 @@ +# This is the CMakeCache file. +# For build in directory: /home/pschatzmann/Development/Arduino/libraries/arduino-snapclient +# It was generated by CMake: /home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//Do not use Portaudio +ADD_PORTAUDIO:BOOL=OFF + +//Build using shared libraries +BUILD_SHARED_LIBS:BOOL=OFF + +//Path to a program. +CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line + +//Path to a program. +CMAKE_AR:FILEPATH=/usr/bin/ar + +//Choose the type of build, options are: None Debug Release RelWithDebInfo +// MinSizeRel ... +CMAKE_BUILD_TYPE:STRING= + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11 + +//Flags used by the CXX compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the CXX compiler during DEBUG builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the CXX compiler during MINSIZEREL builds. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the CXX compiler during RELEASE builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the CXX compiler during RELWITHDEBINFO builds. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11 + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Path to a program. +CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND + +//Flags used by the linker during all build types. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during DEBUG builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during MINSIZEREL builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during RELEASE builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during RELWITHDEBINFO builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL= + +//Value Computed by CMake. +CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient/CMakeFiles/pkgRedirects + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/usr/bin/ld + +//Program used to build from build.ninja files. +CMAKE_MAKE_PROGRAM:FILEPATH=/home/pschatzmann/st/stm32cubeclt_1.16.0/Ninja/bin/ninja + +//Flags used by the linker during the creation of modules during +// all build types. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of modules during +// DEBUG builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of modules during +// MINSIZEREL builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of modules during +// RELEASE builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of modules during +// RELWITHDEBINFO builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=snapclient + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib + +//Path to a program. +CMAKE_READELF:FILEPATH=/usr/bin/readelf + +//Flags used by the linker during the creation of shared libraries +// during all build types. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of shared libraries +// during DEBUG builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of shared libraries +// during MINSIZEREL builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELEASE builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELWITHDEBINFO builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries +// during all build types. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of static libraries +// during DEBUG builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of static libraries +// during MINSIZEREL builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELEASE builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELWITHDEBINFO builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/usr/bin/strip + +//Path to a program. +CMAKE_TAPI:FILEPATH=CMAKE_TAPI-NOTFOUND + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//codec selected by the user +CODEC:STRING=opus + +//Directory under which to collect all populated content +FETCHCONTENT_BASE_DIR:PATH=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient/_deps + +//Disables all attempts to download or update content and assumes +// source dirs already exist +FETCHCONTENT_FULLY_DISCONNECTED:BOOL=OFF + +//Enables QUIET option for all content population +FETCHCONTENT_QUIET:BOOL=ON + +//When not empty, overrides where to find pre-populated content +// for arduino-audio-tools +FETCHCONTENT_SOURCE_DIR_ARDUINO-AUDIO-TOOLS:PATH= + +//Enables UPDATE_DISCONNECTED behavior for all content population +FETCHCONTENT_UPDATES_DISCONNECTED:BOOL=OFF + +//Enables UPDATE_DISCONNECTED behavior just for population of arduino-audio-tools +FETCHCONTENT_UPDATES_DISCONNECTED_ARDUINO-AUDIO-TOOLS:BOOL=OFF + +//Git command line client +GIT_EXECUTABLE:FILEPATH=/usr/bin/git + +//Value Computed by CMake +snapclient_BINARY_DIR:STATIC=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient + +//Value Computed by CMake +snapclient_IS_TOP_LEVEL:STATIC=ON + +//Value Computed by CMake +snapclient_SOURCE_DIR:STATIC=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: CMAKE_ADDR2LINE +CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=28 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/bin/ctest +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR +CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB +CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_DLLTOOL +CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 +//Path to cache edit program executable. +CMAKE_EDIT_COMMAND:INTERNAL=/home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/bin/ccmake +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Ninja +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/pschatzmann/Development/Arduino/libraries/arduino-snapclient +//Install .so files without execute permission. +CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_READELF +CMAKE_READELF-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/home/pschatzmann/st/stm32cubeclt_1.16.0/CMake/share/cmake-3.28 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_TAPI +CMAKE_TAPI-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/usr/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 +//STRINGS property for variable: CODEC +CODEC-STRINGS:INTERNAL=flac;ogg;opus;pcm +//ADVANCED property for variable: GIT_EXECUTABLE +GIT_EXECUTABLE-ADVANCED:INTERNAL=1 +//linker supports push/pop state +_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED:INTERNAL=TRUE + diff --git a/examples/SnapClientEthernet/SnapClientEthernet.ino b/examples/SnapClientEthernet/SnapClientEthernet.ino index 96bf0d7..61edb94 100644 --- a/examples/SnapClientEthernet/SnapClientEthernet.ino +++ b/examples/SnapClientEthernet/SnapClientEthernet.ino @@ -1,49 +1,67 @@ -// Example for EthernetClient: We just test the output by providing a hex dump of the received data +// Example for EthernetClient: We just test the output by reporting the received data bytes #include #include #include "AudioTools.h" #include "SnapClient.h" -// #define ETH_MISO 23 -// #define ETH_MOSI 19 -// #define ETH_SCLK 18 -// #define ETH_CS 5 - EthernetClient eth; -HexDumpOutput out; // final output +MeasuringStream out{10, &Serial}; // log ever 10 writes CopyDecoder codec; SnapClient client(eth, out, codec); byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; -IPAddress ip(192, 168, 1, 177); +//IPAddress ip(192, 168, 1, 177); +//IPAddress gateway(192, 168, 1, 1); +//IPAddress dns(8, 8, 8, 8); + void setup() { Serial.begin(115200); + while(!Serial); + Serial.println("setup"); - // The ESP32 supports a flexible definition of the SPI pins - //SPI.begin(ETH_SCLK, ETH_MISO, ETH_MOSI, ETH_CS); - - SPI.begin(); // use default pins + // example for rp2040 + SPI.setMISO(16); + SPI.setMOSI(19); + SPI.setSCK(18); + SPI.setCS(17); + SPI.begin(17); // use default pins$ // start the Ethernet connection: - if (Ethernet.begin(mac) == 0) { - Serial.println("Failed to configure Ethernet using DHCP"); - Ethernet.begin(mac, ip); - } + Ethernet.init(17); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip, dns, gateway); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true); + } + + // Check link status + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + Serial.print("local IP: "); + Serial.println(Ethernet.localIP()); // wait for link + Serial.println("waiting for link..."); while(Ethernet.linkStatus()!=LinkON){ delay(10); } // Define CONFIG_SNAPCAST_SERVER_HOST in SnapConfig.h or here - client.setServerIP(IPAddress(192, 168, 1, 38)); + client.setServerIP(IPAddress(192, 168, 1, 44)); // start snap client if (!client.begin()) { Serial.print("Could not connect to snap server"); while (true); } + + out.setReportBytes(true); + Serial.println("setup success"); } void loop() { client.doLoop(); } \ No newline at end of file diff --git a/src/SnapClient.h b/src/SnapClient.h index 7fd1ee9..58d5d36 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -8,7 +8,6 @@ #include "SnapConfig.h" #include "api/SnapCommon.h" #include "api/SnapLogger.h" -//#include #include "Client.h" @@ -19,6 +18,10 @@ #include #endif +#ifdef ESP32 +#include +#endif + #include "api/SnapOutput.h" #include "api/SnapProcessor.h" @@ -68,6 +71,46 @@ class SnapClient { p_client = &client; } +// + SnapClient(WiFiClient &client, AudioStream &stream, AudioDecoder &decoder) { + is_wifi = true; + static AdapterAudioStreamToAudioOutput output_adapter; + output_adapter.setStream(stream); + p_decoder = &decoder; + p_output = &output_adapter; + p_client = &client; + server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); + } + + SnapClient(WiFiClient &client, AudioStream &stream, StreamingDecoder &decoder, + int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { + is_wifi = true; + static DecoderFromStreaming decoder_adapter(decoder, bufferSize); + static AdapterAudioStreamToAudioOutput output_adapter; + p_decoder = &decoder_adapter; + output_adapter.setStream(stream); + p_output = &output_adapter; + p_client = &client; + server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); + } + + SnapClient(WiFiClient &client, AudioOutput &output, AudioDecoder &decoder) { + is_wifi = true; + p_decoder = &decoder; + p_output = &output; + p_client = &client; + server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); + } + + SnapClient(WiFiClient &client, AudioOutput &output, StreamingDecoder &decoder, + int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { + is_wifi = true; + p_decoder = new DecoderFromStreaming(decoder, bufferSize); + p_output = &output; + p_client = &client; + } + + /// Destructor ~SnapClient() { end(); @@ -94,13 +137,15 @@ class SnapClient { /// Starts the processing bool begin() { #if defined(ESP32) - if (WiFi.status() != WL_CONNECTED) { - ESP_LOGE(TAG, "WiFi not connected"); - return false; + if (is_wifi){ + if (WiFi.status() != WL_CONNECTED) { + ESP_LOGE(TAG, "WiFi not connected"); + return false; + } + // use maximum speed + WiFi.setSleep(false); + ESP_LOGI(TAG, "Connected to AP"); } - // use maximum speed - WiFi.setSleep(false); - ESP_LOGI(TAG, "Connected to AP"); #endif // Get MAC address for WiFi station @@ -170,6 +215,7 @@ class SnapClient { SnapTimeSync *p_time_sync = &time_sync_default; IPAddress server_ip; int server_port = CONFIG_SNAPCAST_SERVER_PORT; + bool is_wifi = false; void setupMDNS() { #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32) diff --git a/src/api/SnapLogger.h b/src/api/SnapLogger.h index 59a1cb6..840bd8d 100644 --- a/src/api/SnapLogger.h +++ b/src/api/SnapLogger.h @@ -7,9 +7,10 @@ #ifdef ESP32 # include "esp_log.h" #else -# define DEFAULT_LOG(...) fprintf(stderr,"[%s] ", __PRETTY_FUNCTION__);fprintf(stderr, __VA_ARGS__);fputc('\n',stderr) -# define ESP_LOGE(tag, ...) DEFAULT_LOG(__VA_ARGS__) -# define ESP_LOGW(tag, ...) DEFAULT_LOG(__VA_ARGS__) -# define ESP_LOGI(tag, ...) DEFAULT_LOG(__VA_ARGS__) -# define ESP_LOGD(tag, ...) +static char msg[100] = {0}; +# define DEFAULT_LOG(...) { Serial.println(__PRETTY_FUNCTION__); snprintf((char*)msg, 100, __VA_ARGS__); Serial.println(msg); } +# define ESP_LOGE(tag, ...) DEFAULT_LOG(__VA_ARGS__) +# define ESP_LOGW(tag, ...) DEFAULT_LOG(__VA_ARGS__) +# define ESP_LOGI(tag, ...) //DEFAULT_LOG(__VA_ARGS__) +# define ESP_LOGD(tag, ...) //DEFAULT_LOG(__VA_ARGS__) #endif \ No newline at end of file diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index afa36c8..dd0c475 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -288,12 +288,12 @@ class SnapProcessor { if (p_client->connected()) return true; p_client->stop(); // for Ethernet.h p_client->setTimeout(CONFIG_CLIENT_TIMEOUT_SEC); - if (!p_client->connect(server_ip, server_port)) { + if (p_client->connect(server_ip, server_port)<=0) { char str_address[50]; sprintf(str_address, "%d.%d.%d.%d:%d", server_ip[0], server_ip[1], server_ip[2], server_ip[3], server_port); - ESP_LOGE(TAG, "Socket connect to %s failed errno=%d", str_address, errno); + ESP_LOGE(TAG, "Socket connect to %s failed (errno = %d)", str_address, errno); delay(4000); return false; } From 54ef34c29e5fd67df034057b9a7b52ad4bf4f4f5 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 04:50:29 +0200 Subject: [PATCH 11/28] SnapClient: WiFiClient - using delegating constructors --- src/SnapClient.h | 73 +++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/src/SnapClient.h b/src/SnapClient.h index 58d5d36..5bcde67 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -5,11 +5,10 @@ */ #include "AudioTools.h" +#include "Client.h" #include "SnapConfig.h" #include "api/SnapCommon.h" #include "api/SnapLogger.h" -#include "Client.h" - #if CONFIG_NVS_FLASH #include "nvs_flash.h" @@ -35,8 +34,7 @@ namespace snap_arduino { * @copyright Copyright (c) 2023 */ class SnapClient { - -public: + public: SnapClient(Client &client, AudioStream &stream, AudioDecoder &decoder) { static AdapterAudioStreamToAudioOutput output_adapter; output_adapter.setStream(stream); @@ -62,7 +60,7 @@ class SnapClient { p_output = &output; p_client = &client; server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); - } + } SnapClient(Client &client, AudioOutput &output, StreamingDecoder &decoder, int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { @@ -71,62 +69,41 @@ class SnapClient { p_client = &client; } -// - SnapClient(WiFiClient &client, AudioStream &stream, AudioDecoder &decoder) { + // + SnapClient(WiFiClient &client, AudioStream &stream, AudioDecoder &decoder) + : SnapClient((Client &)client, stream, decoder) { is_wifi = true; - static AdapterAudioStreamToAudioOutput output_adapter; - output_adapter.setStream(stream); - p_decoder = &decoder; - p_output = &output_adapter; - p_client = &client; - server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); } SnapClient(WiFiClient &client, AudioStream &stream, StreamingDecoder &decoder, - int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { + int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) + : SnapClient((Client &)client, stream, decoder, bufferSize) { is_wifi = true; - static DecoderFromStreaming decoder_adapter(decoder, bufferSize); - static AdapterAudioStreamToAudioOutput output_adapter; - p_decoder = &decoder_adapter; - output_adapter.setStream(stream); - p_output = &output_adapter; - p_client = &client; - server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); } - SnapClient(WiFiClient &client, AudioOutput &output, AudioDecoder &decoder) { + SnapClient(WiFiClient &client, AudioOutput &output, AudioDecoder &decoder) + : SnapClient((Client &)client, output, decoder) { is_wifi = true; - p_decoder = &decoder; - p_output = &output; - p_client = &client; - server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); - } + } SnapClient(WiFiClient &client, AudioOutput &output, StreamingDecoder &decoder, - int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { + int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) + : SnapClient((Client &)client, output, decoder, bufferSize) { is_wifi = true; - p_decoder = new DecoderFromStreaming(decoder, bufferSize); - p_output = &output; - p_client = &client; } - /// Destructor - ~SnapClient() { - end(); - } + ~SnapClient() { end(); } /// Defines an alternative commnuication client (default is WiFiClient) void setClient(Client &client) { p_client = &client; } /// @brief Defines the Snapcast Server IP address - /// @param address + /// @param address void setServerIP(IPAddress ipAddress) { this->server_ip = ipAddress; } /// Defines the time synchronization logic - void setSnapTimeSync(SnapTimeSync &timeSync){ - p_time_sync = &timeSync; - } + void setSnapTimeSync(SnapTimeSync &timeSync) { p_time_sync = &timeSync; } /// Starts the processing bool begin(SnapTimeSync &timeSync) { @@ -137,7 +114,7 @@ class SnapClient { /// Starts the processing bool begin() { #if defined(ESP32) - if (is_wifi){ + if (is_wifi) { if (WiFi.status() != WL_CONNECTED) { ESP_LOGE(TAG, "WiFi not connected"); return false; @@ -191,19 +168,15 @@ class SnapClient { } /// Provides the actual processor - SnapProcessor& snapProcessor(){ - return *p_snapprocessor; - } + SnapProcessor &snapProcessor() { return *p_snapprocessor; } /// Defines the Snap output implementation to be used - void setSnapOutput(SnapOutput &out){ - p_snapprocessor->setSnapOutput(out); - } + void setSnapOutput(SnapOutput &out) { p_snapprocessor->setSnapOutput(out); } /// Call from Arduino Loop - to receive and process the audio data bool doLoop() { return p_snapprocessor->doLoop(); } -protected: + protected: const char *TAG = "SnapClient"; SnapTime &snap_time = SnapTime::instance(); SnapProcessor default_processor; @@ -238,7 +211,8 @@ class SnapClient { server_ip[2], server_ip[3]); server_port = MDNS.port(0); - ESP_LOGI(TAG, "MDNS: SNAPCAST ip: %s, port: %d", str_address, server_port); + ESP_LOGI(TAG, "MDNS: SNAPCAST ip: %s, port: %d", str_address, + server_port); } else { ESP_LOGE(TAG, "SNAPCAST server not found"); @@ -262,7 +236,6 @@ class SnapClient { #endif } - void setupMACAddress() { #ifdef ESP32 const char *adr = strdup(WiFi.macAddress().c_str()); @@ -273,4 +246,4 @@ class SnapClient { } }; -} \ No newline at end of file +} // namespace snap_arduino \ No newline at end of file From deeab59321c39c76893b444c944fd7d8557f1142 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 05:12:15 +0200 Subject: [PATCH 12/28] setWiFi --- src/SnapClient.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SnapClient.h b/src/SnapClient.h index 5bcde67..bdf5663 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -176,6 +176,12 @@ class SnapClient { /// Call from Arduino Loop - to receive and process the audio data bool doLoop() { return p_snapprocessor->doLoop(); } + /// ESP32: WiFiClient: prevent/activate automatic login to Wifi + void setWiFi(bool flag){ is_wifi = flag;} + + /// check if we use the WiFiClient + bool isWiFi() {return is_wifi;} + protected: const char *TAG = "SnapClient"; SnapTime &snap_time = SnapTime::instance(); From bbb60339320f611209e8cba88ec5288a098d3dc3 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 05:33:12 +0200 Subject: [PATCH 13/28] Remove constructors for WiFiClient --- src/SnapClient.h | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/SnapClient.h b/src/SnapClient.h index bdf5663..fcb0b68 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -69,29 +69,6 @@ class SnapClient { p_client = &client; } - // - SnapClient(WiFiClient &client, AudioStream &stream, AudioDecoder &decoder) - : SnapClient((Client &)client, stream, decoder) { - is_wifi = true; - } - - SnapClient(WiFiClient &client, AudioStream &stream, StreamingDecoder &decoder, - int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) - : SnapClient((Client &)client, stream, decoder, bufferSize) { - is_wifi = true; - } - - SnapClient(WiFiClient &client, AudioOutput &output, AudioDecoder &decoder) - : SnapClient((Client &)client, output, decoder) { - is_wifi = true; - } - - SnapClient(WiFiClient &client, AudioOutput &output, StreamingDecoder &decoder, - int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) - : SnapClient((Client &)client, output, decoder, bufferSize) { - is_wifi = true; - } - /// Destructor ~SnapClient() { end(); } From aa48b51b7f02b6b37d05f358b2b65979a4ed9805 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 06:12:35 +0200 Subject: [PATCH 14/28] set default is_wifi to true for ESP32 --- src/SnapClient.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SnapClient.h b/src/SnapClient.h index fcb0b68..6301f8b 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -171,7 +171,11 @@ class SnapClient { SnapTimeSync *p_time_sync = &time_sync_default; IPAddress server_ip; int server_port = CONFIG_SNAPCAST_SERVER_PORT; +#ifdef ESP32 + bool is_wifi = true; +#else bool is_wifi = false; +#endif void setupMDNS() { #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32) From 26a1aabf4be2e7adef18b926b5a086e9363bc441 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 19 Jul 2024 06:14:58 +0200 Subject: [PATCH 15/28] Comments --- src/SnapClient.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SnapClient.h b/src/SnapClient.h index 6301f8b..9f0f381 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -153,10 +153,10 @@ class SnapClient { /// Call from Arduino Loop - to receive and process the audio data bool doLoop() { return p_snapprocessor->doLoop(); } - /// ESP32: WiFiClient: prevent/activate automatic login to Wifi + /// ESP32: WiFiClient: prevent/activate WiFi link status check void setWiFi(bool flag){ is_wifi = flag;} - /// check if we use the WiFiClient + /// check if we use the ESP32 WiFi for checking the link status bool isWiFi() {return is_wifi;} protected: From c4d2fa4bb4ab4884c5b4284f88dac1d99be9b17e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Sat, 3 Aug 2024 09:44:57 +0200 Subject: [PATCH 16/28] Bump release to 0.1.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index f0911ee..9982841 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=snapclient -version=0.0.1 +version=0.1.1 author=https://github.com/jorgenkraghjakobsen maintainer=Phil Schatzmann sentence=snapclient From cd3b2b63fe992b9fe11faceccad84931a531686e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Tue, 6 Aug 2024 18:39:55 +0200 Subject: [PATCH 17/28] Compile error SnapProcessorRTOS.h --- src/api/SnapProcessorRTOS.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/SnapProcessorRTOS.h b/src/api/SnapProcessorRTOS.h index f9c3881..9a974eb 100644 --- a/src/api/SnapProcessorRTOS.h +++ b/src/api/SnapProcessorRTOS.h @@ -1,6 +1,6 @@ #pragma once #include "SnapOutput.h" -#include "Concurrency/Concurrency.h" +#include "AudioLibs/Concurrency.h" namespace snap_arduino { From 0f282f09da30f2da01e92c95259c7797e29943aa Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Sat, 5 Oct 2024 13:07:58 +0200 Subject: [PATCH 18/28] Support for AudioTools 1.0.0 --- README.md | 2 +- desktop-client/SnapClient.cpp | 10 +++++----- examples/SnapClientAudioKit/SnapClientAudioKit.ino | 4 ++-- examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino | 4 ++-- examples/SnapClientI2S/SnapClientI2S.ino | 2 +- .../SnapClientInternalDAC/SnapClientInternalDAC.ino | 2 +- examples/SnapClientVS1053/SnapClientVS1053.ino | 2 +- examples/Tests/TestGetHttp/TestGetHttp.ino | 2 +- examples/Tests/TestOutput/TestOutput.ino | 2 +- examples/Tests/TestTime/TestTime.ino | 2 +- src/api/SnapProcessorRTOS.h | 6 +++++- src/api/SnapTime.h | 6 +++++- 12 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2c5be75..b249d4b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Here is an example Arduino sketch that uses the Wifi as communication API, the W ```C++ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus +#include "AudioTools/AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus //#include "api/SnapProcessorRTOS.h" // install https://github.com/pschatzmann/arduino-freertos-addons OpusAudioDecoder codec; diff --git a/desktop-client/SnapClient.cpp b/desktop-client/SnapClient.cpp index a7ed91e..b698bbb 100644 --- a/desktop-client/SnapClient.cpp +++ b/desktop-client/SnapClient.cpp @@ -5,11 +5,11 @@ */ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioLibs/MiniAudioStream.h" -//#include "AudioCodecs/CodecOpus.h" -//#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git -#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec -#include "AudioLibs/StdioStream.h" +#include "AudioTools/AudioLibs/MiniAudioStream.h" +//#include "AudioTools/AudioCodecs/CodecOpus.h" +//#include "AudioTools/AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git +#include "AudioTools/AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec +#include "AudioTools/AudioLibs/StdioStream.h" //CsvOutput out; //StdioStream out; diff --git a/examples/SnapClientAudioKit/SnapClientAudioKit.ino b/examples/SnapClientAudioKit/SnapClientAudioKit.ino index 71379d5..ad01e65 100644 --- a/examples/SnapClientAudioKit/SnapClientAudioKit.ino +++ b/examples/SnapClientAudioKit/SnapClientAudioKit.ino @@ -5,8 +5,8 @@ */ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver -#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus +#include "AudioTools/AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver +#include "AudioTools/AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus #define ARDUINO_LOOP_STACK_SIZE (10 * 1024) diff --git a/examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino b/examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino index f36dba0..3db20ee 100644 --- a/examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino +++ b/examples/SnapClientFreeRTOS/SnapClientFreeRTOS.ino @@ -1,8 +1,8 @@ #include "AudioTools.h" #include "SnapClient.h" #include "api/SnapProcessorRTOS.h" // install https://github.com/pschatzmann/arduino-freertos-addons -#include "AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver -#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus +#include "AudioTools/AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver +#include "AudioTools/AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus AudioBoardStream out(AudioKitEs8388V1); // or replace with e.g. I2SStream out; diff --git a/examples/SnapClientI2S/SnapClientI2S.ino b/examples/SnapClientI2S/SnapClientI2S.ino index 99105b8..26f6b88 100644 --- a/examples/SnapClientI2S/SnapClientI2S.ino +++ b/examples/SnapClientI2S/SnapClientI2S.ino @@ -6,7 +6,7 @@ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" #define ARDUINO_LOOP_STACK_SIZE (10 * 1024) diff --git a/examples/SnapClientInternalDAC/SnapClientInternalDAC.ino b/examples/SnapClientInternalDAC/SnapClientInternalDAC.ino index 6914725..b63ac2e 100644 --- a/examples/SnapClientInternalDAC/SnapClientInternalDAC.ino +++ b/examples/SnapClientInternalDAC/SnapClientInternalDAC.ino @@ -6,7 +6,7 @@ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" #define ARDUINO_LOOP_STACK_SIZE (10 * 1024) diff --git a/examples/SnapClientVS1053/SnapClientVS1053.ino b/examples/SnapClientVS1053/SnapClientVS1053.ino index 2434c88..d843f86 100644 --- a/examples/SnapClientVS1053/SnapClientVS1053.ino +++ b/examples/SnapClientVS1053/SnapClientVS1053.ino @@ -8,7 +8,7 @@ */ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioLibs/VS1053Stream.h" +#include "AudioTools/AudioLibs/VS1053Stream.h" VS1053Stream out; // final output diff --git a/examples/Tests/TestGetHttp/TestGetHttp.ino b/examples/Tests/TestGetHttp/TestGetHttp.ino index 2362a7c..65be831 100644 --- a/examples/Tests/TestGetHttp/TestGetHttp.ino +++ b/examples/Tests/TestGetHttp/TestGetHttp.ino @@ -1,7 +1,7 @@ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" OpusAudioDecoder opus; NullStream out; diff --git a/examples/Tests/TestOutput/TestOutput.ino b/examples/Tests/TestOutput/TestOutput.ino index 8665abe..c9b5437 100644 --- a/examples/Tests/TestOutput/TestOutput.ino +++ b/examples/Tests/TestOutput/TestOutput.ino @@ -1,6 +1,6 @@ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" OpusAudioDecoder opus; NullStream out; diff --git a/examples/Tests/TestTime/TestTime.ino b/examples/Tests/TestTime/TestTime.ino index b9f1c85..33da3c2 100644 --- a/examples/Tests/TestTime/TestTime.ino +++ b/examples/Tests/TestTime/TestTime.ino @@ -1,6 +1,6 @@ #include "AudioTools.h" #include "SnapClient.h" -#include "AudioCodecs/CodecOpus.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" OpusAudioDecoder opus; NullStream out; diff --git a/src/api/SnapProcessorRTOS.h b/src/api/SnapProcessorRTOS.h index 9a974eb..06503d3 100644 --- a/src/api/SnapProcessorRTOS.h +++ b/src/api/SnapProcessorRTOS.h @@ -1,6 +1,10 @@ #pragma once #include "SnapOutput.h" -#include "AudioLibs/Concurrency.h" +#if defined(AUDIOTOOLS_MAJOR_VERSION) +# include "AudioTools/AudioLibs/Concurrency.h" +#else +# include "AudioLibs/Concurrency.h" +#endif namespace snap_arduino { diff --git a/src/api/SnapTime.h b/src/api/SnapTime.h index 83ba981..0539672 100644 --- a/src/api/SnapTime.h +++ b/src/api/SnapTime.h @@ -1,6 +1,10 @@ #pragma once -#include "AudioBasic/Collections/Vector.h" #include "AudioConfig.h" +#if defined(AUDIOTOOLS_MAJOR_VERSION) +# include "AudioTools/CoreAudio/AudioBasic/Collections/Vector.h" +#else +# include "AudioBasic/Collections/Vector.h" +#endif #include #include From 738300cc820c1c8d218f15f22bca27bc29afe8c8 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 24 Oct 2024 02:48:04 +0200 Subject: [PATCH 19/28] audioEnd correct logging --- src/api/SnapOutput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index 085195c..fd18c3c 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -228,7 +228,7 @@ class SnapOutput : public AudioInfoSupport { } void audioEnd() { - ESP_LOGD(TAG, "start"); + ESP_LOGD(TAG, "audioEnd"); if (out == nullptr) return; out->end(); } From a5091aa4c8467ce4fbaba7ee2c344bf124f14d41 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 24 Oct 2024 12:04:45 +0200 Subject: [PATCH 20/28] SnapOutput added isActvie() --- src/api/SnapOutput.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index 085195c..d18ea6d 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -123,6 +123,7 @@ class SnapOutput : public AudioInfoSupport { // writes the audio data to the decoder size_t audioWrite(const void *src, size_t size) { ESP_LOGD(TAG, "%zu", size); + time_last_write = millis(); size_t result = decoder_stream.write((const uint8_t *)src, size); return result; @@ -160,6 +161,15 @@ class SnapOutput : public AudioInfoSupport { return result; } + uint64_t getLastWriteTime() { + return time_last_write; + } + + /// checks if the audio is still playing + bool isActive(uint16_t timeout=1000){ + return (time_last_write + timeout) >= millis(); + } + protected: const char *TAG = "SnapOutput"; AudioOutput *out = nullptr; @@ -175,6 +185,7 @@ class SnapOutput : public AudioInfoSupport { SnapTimeSync *p_snap_time_sync = nullptr; bool is_sync_started = false; bool is_audio_begin_called = false; + uint64_t time_last_write = 0; /// setup of all audio objects bool audioBegin() { From 2f79c756509e5e02217c343726749e266f320b1a Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 15 Jan 2025 14:19:02 +0100 Subject: [PATCH 21/28] Allign AudioInfo across the different objects --- src/api/SnapOutput.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/api/SnapOutput.h b/src/api/SnapOutput.h index effea7e..583978c 100644 --- a/src/api/SnapOutput.h +++ b/src/api/SnapOutput.h @@ -91,6 +91,12 @@ class SnapOutput : public AudioInfoSupport { resample.setOutput(output); vol_stream.setStream(resample); // adjust volume decoder_stream.setStream(&vol_stream); // decode to pcm + + // synchronized audio information + AudioInfo info = output.audioInfo(); + resample.begin(info, info); + vol_stream.setAudioInfo(info); + decoder_stream.setAudioInfo(info); } AudioOutput &getOutput() { return *out; } @@ -122,9 +128,12 @@ class SnapOutput : public AudioInfoSupport { // writes the audio data to the decoder size_t audioWrite(const void *src, size_t size) { - ESP_LOGD(TAG, "%zu", size); + ESP_LOGI(TAG, "audioWrite: %zu", size); time_last_write = millis(); size_t result = decoder_stream.write((const uint8_t *)src, size); + if (result != size){ + ESP_LOGW(TAG, "Could not write all data %zu -> %zu", size, result); + } return result; } @@ -198,6 +207,9 @@ class SnapOutput : public AudioInfoSupport { return false; } + // determine default audio info from output + audio_info = out->audioInfo(); + // open volume control: allow amplification auto vol_cfg = vol_stream.defaultConfig(); vol_cfg.copyFrom(audio_info); From 88bbab6e1807c4a914f9aec5f0b9b47959fe4e22 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 15 Jan 2025 18:44:21 +0100 Subject: [PATCH 22/28] cleanup --- desktop-client/CMakeLists.txt | 38 ----------------------------- desktop-client/README.md | 10 -------- desktop-client/SnapClient.cpp | 45 ----------------------------------- src/SnapClient.h | 9 +++++++ 4 files changed, 9 insertions(+), 93 deletions(-) delete mode 100644 desktop-client/CMakeLists.txt delete mode 100644 desktop-client/README.md delete mode 100644 desktop-client/SnapClient.cpp diff --git a/desktop-client/CMakeLists.txt b/desktop-client/CMakeLists.txt deleted file mode 100644 index dda38bf..0000000 --- a/desktop-client/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -cmake_minimum_required(VERSION 2.34) - -# set the project name -project(desktop-client) -set (CMAKE_CXX_STANDARD 17) -set (DCMAKE_CXX_FLAGS "-Werror") -# set (FETCHCONTENT_FULLY_DISCONNECTED ON) - -include(FetchContent) - -# Download miniaudio.h -file(DOWNLOAD https://raw.githubusercontent.com/mackron/miniaudio/master/miniaudio.h - ${CMAKE_CURRENT_SOURCE_DIR}/miniaudio.h) - -# Build with snapclient -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/snapclient ) -endif() - -FetchContent_Declare(arduino_libvorbis GIT_REPOSITORY https://github.com/pschatzmann/arduino-libvorbis-tremor.git GIT_TAG main ) -FetchContent_GetProperties(arduino_libvorbis) -if(NOT arduino_libvorbis_POPULATED) - FetchContent_Populate(arduino_libvorbis) - add_subdirectory(${arduino_libvorbis_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libvorbis) -endif() - - -# build sketch as executable -add_executable (desktop-client SnapClient.cpp) - -# set preprocessor defines -target_compile_definitions(desktop-client PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP -DCONFIG_USE_PSRAM=0 -DCONFIG_SNAPCLIENT_SNTP_ENABLE=0 -DCONFIG_SNAPCLIENT_USE_MDNS=0) - -# specify libraries -target_link_libraries(desktop-client snapclient arduino-audio-tools arduino_emulator arduino_libopus arduino_libvorbis) - -# to find include for miniaudio -target_include_directories(desktop-client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/desktop-client/README.md b/desktop-client/README.md deleted file mode 100644 index cb50cf3..0000000 --- a/desktop-client/README.md +++ /dev/null @@ -1,10 +0,0 @@ - -Snaplient build for the Desktop - -1. goto the desktop-client directory -2. mkdir build -3. cd build -4. cmake .. -5. make - -This builds the desktop-client executable \ No newline at end of file diff --git a/desktop-client/SnapClient.cpp b/desktop-client/SnapClient.cpp deleted file mode 100644 index b698bbb..0000000 --- a/desktop-client/SnapClient.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @brief SnapClient with Opus decoder: Output to PortAudio on the desktop - * @author Phil Schatzmann - * @copyright GPLv3 - */ -#include "AudioTools.h" -#include "SnapClient.h" -#include "AudioTools/AudioLibs/MiniAudioStream.h" -//#include "AudioTools/AudioCodecs/CodecOpus.h" -//#include "AudioTools/AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git -#include "AudioTools/AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec -#include "AudioTools/AudioLibs/StdioStream.h" - -//CsvOutput out; -//StdioStream out; -MiniAudioStream out; -//OpusAudioDecoder opus; -VorbisDecoder ogg; -//FLACDecoder flac; -WiFiClient wifi; -SnapClient client(wifi, out, ogg); - -void setup() { - Serial.begin(115200); - //AudioLogger::instance().begin(Serial, AudioLogger::Info); - // login to wifi - WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD); - Serial.print("Connecting to WiFi .."); - while (WiFi.status() != WL_CONNECTED) { - Serial.print('.'); - delay(1000); - } - - // print ip address - Serial.println(); - Serial.println(WiFi.localIP()); - - - // start snap client - client.begin(); -} - -void loop() { - client.doLoop(); -} \ No newline at end of file diff --git a/src/SnapClient.h b/src/SnapClient.h index 9f0f381..5dc150f 100644 --- a/src/SnapClient.h +++ b/src/SnapClient.h @@ -44,6 +44,15 @@ class SnapClient { server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); } + SnapClient(Client &client, Print &stream, AudioDecoder &decoder) { + static AdapterPrintToAudioOutput output_adapter; + output_adapter.setStream(stream); + p_decoder = &decoder; + p_output = &output_adapter; + p_client = &client; + server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST); + } + SnapClient(Client &client, AudioStream &stream, StreamingDecoder &decoder, int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) { static DecoderFromStreaming decoder_adapter(decoder, bufferSize); From 975a715a7fd2277a5ad17cccc826e7937cdf352e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 16 Jan 2025 18:49:15 +0100 Subject: [PATCH 23/28] RP3040 example --- .../SnapClientRP2040/SnapClientRP2040.ino | 69 ++++++++++ src/api/SnapLogger.h | 4 +- src/api/SnapProcessor.h | 5 + src/api/SnapProcessorRP2040.h | 128 ++++++++++++++++++ 4 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 examples/SnapClientRP2040/SnapClientRP2040.ino create mode 100644 src/api/SnapProcessorRP2040.h diff --git a/examples/SnapClientRP2040/SnapClientRP2040.ino b/examples/SnapClientRP2040/SnapClientRP2040.ino new file mode 100644 index 0000000..76cbf9e --- /dev/null +++ b/examples/SnapClientRP2040/SnapClientRP2040.ino @@ -0,0 +1,69 @@ +/** + * @brief SnapClient with Opus decoder: Wifi processing is on core 0, decoding and + * i2s output is on core 1. + * @author Phil Schatzmann + * @copyright GPLv3 + */ + +#include "AudioTools.h" +#include "AudioTools/AudioCodecs/CodecOpus.h" +#include "SnapClient.h" +#include "api/SnapProcessorRP2040.h" + +//#define ARDUINO_LOOP_STACK_SIZE (10 * 1024) + +I2SStream out; +OpusAudioDecoder opus; +WiFiClient wifi; +//SnapTimeSyncDynamic synch(172, 10); // optional configuratioin +SnapClient client(wifi, out, opus); +SnapProcessorRP2040 processor_rp2040(1024*8); // define OPUS queue with 8 kbytes + +void setup() { + Serial.begin(115200); + AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info); + while(!Serial); + Serial.println("starting..."); + + // login to wifi -> Define values in SnapConfig.h or replace them here + WiFi.begin("ssid", "password"); + Serial.print("Connecting to WiFi .."); + while (WiFi.status() != WL_CONNECTED) { + Serial.print('.'); + delay(1000); + } + + // print ip address + Serial.println(); + Serial.println(WiFi.localIP()); + + // Define CONFIG_SNAPCAST_SERVER_HOST in SnapConfig.h or here + client.setServerIP(IPAddress(192,168,1,44)); + client.setSnapProcessor(processor_rp2040); + + // start snap client + client.begin(); + Serial.println("started"); +} + +void loop() { + // fill queue + client.doLoop(); +} + +void setup1(){ + // setup I2S to define custom pins + auto cfg = out.defaultConfig(); + //cfg.pin_bck = 14; + //cfg.pin_ws = 15; + //cfg.pin_data = 22; + cfg.sample_rate = 48000; + cfg.buffer_size = 1024; + cfg.buffer_count = 4; + out.begin(cfg); +} + +void loop1(){ + // trigger output from queue + processor_rp2040.doLoop1(); +} \ No newline at end of file diff --git a/src/api/SnapLogger.h b/src/api/SnapLogger.h index 840bd8d..f83a2b1 100644 --- a/src/api/SnapLogger.h +++ b/src/api/SnapLogger.h @@ -7,8 +7,8 @@ #ifdef ESP32 # include "esp_log.h" #else -static char msg[100] = {0}; -# define DEFAULT_LOG(...) { Serial.println(__PRETTY_FUNCTION__); snprintf((char*)msg, 100, __VA_ARGS__); Serial.println(msg); } +static char msg[100] = ": "; +# define DEFAULT_LOG(...) { Serial.print(__PRETTY_FUNCTION__); snprintf((char*)msg+2, 100, __VA_ARGS__); Serial.println(msg); } # define ESP_LOGE(tag, ...) DEFAULT_LOG(__VA_ARGS__) # define ESP_LOGW(tag, ...) DEFAULT_LOG(__VA_ARGS__) # define ESP_LOGI(tag, ...) //DEFAULT_LOG(__VA_ARGS__) diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index dd0c475..d426897 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -85,6 +85,11 @@ class SnapProcessor { return processLoopStep(); } + /// Usually not used! + virtual bool doLoop1() { + return false; + } + /// Defines the output class void setOutput(AudioOutput &output) { p_snap_output->setOutput(output); } diff --git a/src/api/SnapProcessorRP2040.h b/src/api/SnapProcessorRP2040.h new file mode 100644 index 0000000..0be8271 --- /dev/null +++ b/src/api/SnapProcessorRP2040.h @@ -0,0 +1,128 @@ +#pragma once +#include "AudioTools/Concurrency/RP2040.h" +#include "SnapOutput.h" + +namespace snap_arduino { + +/** + * @brief Processor for which the encoded output is buffered in a queue. The decoding and + * audio output can be done on the second core by calling loop1(); + * + * @author Phil Schatzmann + * @version 0.1 + * @date 2024-02-26 + * @copyright Copyright (c) 2023 + */ +class SnapProcessorRP2040 : public SnapProcessor { + public: + /// Default constructor + SnapProcessorRP2040(SnapOutput &output, int bufferSizeBytes, int activationAtPercent = 75) + : SnapProcessor(output) { + active_percent = activationAtPercent; + initQueues(bufferSizeBytes); + } + /// Default constructor + SnapProcessorRP2040(int bufferSizeBytes, int activationAtPercent = 75) + : SnapProcessor() { + active_percent = activationAtPercent; + initQueues(bufferSizeBytes); + } + + bool begin() override { + ESP_LOGW(TAG, "begin: %d", buffer_count * 1024); + // regular begin logic + bool result = SnapProcessor::begin(); + // allocate buffer, so that we could use psram + size_queue.resize(RTOS_MAX_QUEUE_ENTRY_COUNT); + buffer.resize(buffer_count * 1024); + is_active = false; + return result; + } + + void end(void) override { + size_queue.clear(); + buffer.reset(); + SnapProcessor::end(); + } + + bool doLoop1() override { + ESP_LOGD(TAG, "doLoop1 %d / %d", size_queue.available(), buffer.available()); + if (!isBufferActive()) return true; + + size_t size = 0; + if (size_queue.readArray(&size, 1)) { + uint8_t data[size]; + int read = buffer.readArray(data, size); + if (read != size){ + ESP_LOGE(TAG, "readArray failed %d -> %d", size, read); + } + int written = p_snap_output->audioWrite(data, size); + if (written != size) { + ESP_LOGE(TAG, "write error: %d of %d", written, size); + } + } + return true; + } + + protected: + const char *TAG = "SnapProcessorRP2040"; + audio_tools::BufferRP2040T size_queue{1, 0}; + audio_tools::BufferRP2040T buffer{1024, 0}; // size defined in begin + int buffer_count = 0; + bool is_active = false; + int active_percent = 0; + + bool isBufferActive() { + if (!is_active && buffer.available()>0) { + + int limit = buffer.size() * active_percent / 100; + if (buffer.available() >= limit) { + LOGI("Setting buffer active"); + is_active = true; + } + delay(10); + } + return is_active; + } + + /// store parameters provided by constructor + void initQueues(int bufferSizeBytes) { + buffer_count = bufferSizeBytes / 1024; + if (buffer_count <= 2){ + buffer_count = 2; + } + } + + /// Writes the encoded audio data to a queue + size_t writeAudio(const uint8_t *data, size_t size) override { + + if (size > buffer.size()) { + ESP_LOGE(TAG, "The buffer is too small with %d. Use a multiple of %d", buffer.size(), size); + stop(); + } + + ESP_LOGI(TAG, "size: %zu / buffer %d", size, buffer.available()); + if (!p_snap_output->isStarted() || size == 0) { + ESP_LOGW(TAG, "not started"); + return 0; + } + + // if (!p_snap_output->synchronizePlayback()) { + // return size; + // } + + if (!size_queue.writeArray(&size, 1)) { + ESP_LOGW(TAG, "size_queue full"); + return 0; + } + + size_t size_written = buffer.writeArray(data, size); + if (size_written != size) { + ESP_LOGE(TAG, "buffer-overflow"); + } + + return size; + } +}; + +} // namespace snap_arduino From 88b7abe3aaaabbc8f1cb5ad7a6f4beeddf87e940 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 16 Jan 2025 19:02:47 +0100 Subject: [PATCH 24/28] SnapProcessorRP2040 blocking read --- src/api/SnapProcessorRP2040.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api/SnapProcessorRP2040.h b/src/api/SnapProcessorRP2040.h index 0be8271..978bf95 100644 --- a/src/api/SnapProcessorRP2040.h +++ b/src/api/SnapProcessorRP2040.h @@ -32,9 +32,15 @@ class SnapProcessorRP2040 : public SnapProcessor { ESP_LOGW(TAG, "begin: %d", buffer_count * 1024); // regular begin logic bool result = SnapProcessor::begin(); - // allocate buffer, so that we could use psram - size_queue.resize(RTOS_MAX_QUEUE_ENTRY_COUNT); + + // allocate buffer + buffer.setBlockingRead(true); + buffer.setBlockingWrite(true); buffer.resize(buffer_count * 1024); + + // we need to read back the buffer with the written sizes + size_queue.resize(RTOS_MAX_QUEUE_ENTRY_COUNT); + is_active = false; return result; } From 565fae26ccc2f9e5f1d1aa3276c803a8c91c45e6 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 17 Jan 2025 09:26:30 +0100 Subject: [PATCH 25/28] RP2040 --- examples/SnapClientRP2040/SnapClientRP2040.ino | 2 -- src/api/SnapProcessorRP2040.h | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/SnapClientRP2040/SnapClientRP2040.ino b/examples/SnapClientRP2040/SnapClientRP2040.ino index 76cbf9e..fd57b04 100644 --- a/examples/SnapClientRP2040/SnapClientRP2040.ino +++ b/examples/SnapClientRP2040/SnapClientRP2040.ino @@ -10,8 +10,6 @@ #include "SnapClient.h" #include "api/SnapProcessorRP2040.h" -//#define ARDUINO_LOOP_STACK_SIZE (10 * 1024) - I2SStream out; OpusAudioDecoder opus; WiFiClient wifi; diff --git a/src/api/SnapProcessorRP2040.h b/src/api/SnapProcessorRP2040.h index 978bf95..b02c614 100644 --- a/src/api/SnapProcessorRP2040.h +++ b/src/api/SnapProcessorRP2040.h @@ -32,7 +32,7 @@ class SnapProcessorRP2040 : public SnapProcessor { ESP_LOGW(TAG, "begin: %d", buffer_count * 1024); // regular begin logic bool result = SnapProcessor::begin(); - + // allocate buffer buffer.setBlockingRead(true); buffer.setBlockingWrite(true); @@ -113,9 +113,9 @@ class SnapProcessorRP2040 : public SnapProcessor { return 0; } - // if (!p_snap_output->synchronizePlayback()) { - // return size; - // } + if (!p_snap_output->synchronizePlayback()) { + return size; + } if (!size_queue.writeArray(&size, 1)) { ESP_LOGW(TAG, "size_queue full"); From 567bc0badb4deced269c23fb64bac07b258a5452 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 19 Feb 2025 12:59:19 +0100 Subject: [PATCH 26/28] SnapProcessor setter for host name and client name --- src/api/SnapProcessor.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api/SnapProcessor.h b/src/api/SnapProcessor.h index d426897..7b0eede 100644 --- a/src/api/SnapProcessor.h +++ b/src/api/SnapProcessor.h @@ -119,6 +119,24 @@ class SnapProcessor { is_fast_loop = flag; } + /// Defines the host name (default CONFIG_SNAPCAST_CLIENT_NAME) + void setHostName(const char* name){ + hostname = name; + } + + const char* hostName(){ + return hostname; + } + + /// Defines the client name (default "libsnapcast") + void setClientName(const char* name){ + client_name = name; + } + + const char* clientName(){ + return client_name; + } + protected: const char *TAG = "SnapProcessor"; // WiFiClient default_client; @@ -150,6 +168,8 @@ class SnapProcessor { bool is_fast_loop = false; enum loop_status_enum { LoopStart, LoopStep, LoopEnd }; loop_status_enum loop_status = LoopStart; + const char* hostname = CONFIG_SNAPCAST_CLIENT_NAME; + const char* client_name = "libsnapcast"; bool processLoopStepFast() { switch (loop_status) { @@ -318,9 +338,9 @@ class SnapProcessor { // setup hello_message SnapMessageHallo hello_message; hello_message.mac = mac_address; - hello_message.hostname = CONFIG_SNAPCAST_CLIENT_NAME; + hello_message.hostname = hostname; hello_message.version = "0.0.2"; - hello_message.client_name = "libsnapcast"; + hello_message.client_name = client_name; hello_message.os = "arduino"; hello_message.arch = "xtensa"; hello_message.instance = 1; From aef3e4e6101bc19523e808dd99c825111f52d1ca Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 19 Feb 2025 13:01:35 +0100 Subject: [PATCH 27/28] doxygen --- docs/html/_snap_client_8h_source.html | 452 ++++--- docs/html/_snap_common_8h_source.html | 80 +- docs/html/_snap_config_8h_source.html | 97 +- docs/html/_snap_logger_8h_source.html | 13 +- docs/html/_snap_output_8h_source.html | 525 ++++---- docs/html/_snap_processor_8h_source.html | 1177 +++++++++-------- .../_snap_processor_buffered_8h_source.html | 163 +++ .../_snap_processor_r_p2040_8h_source.html | 211 +++ .../_snap_processor_r_t_o_s_8h_source.html | 235 ++-- docs/html/_snap_protocol_8h_source.html | 873 ++++++------ docs/html/_snap_time_8h_source.html | 213 +-- docs/html/_snap_time_sync_8h_source.html | 313 ++--- docs/html/annotated.html | 45 +- docs/html/classes.html | 4 +- ...snap__arduino_1_1_snap_client-members.html | 118 ++ .../classsnap__arduino_1_1_snap_client.html | 269 ++++ ...snap__arduino_1_1_snap_output-members.html | 126 ++ .../classsnap__arduino_1_1_snap_output.html | 313 +++++ .../classsnap__arduino_1_1_snap_output.png | Bin 0 -> 504 bytes ...p__arduino_1_1_snap_processor-members.html | 165 +++ ...classsnap__arduino_1_1_snap_processor.html | 377 ++++++ .../classsnap__arduino_1_1_snap_processor.png | Bin 0 -> 1107 bytes ...o_1_1_snap_processor_buffered-members.html | 172 +++ ...__arduino_1_1_snap_processor_buffered.html | 396 ++++++ ...p__arduino_1_1_snap_processor_buffered.png | Bin 0 -> 636 bytes ...no_1_1_snap_processor_r_p2040-members.html | 174 +++ ...p__arduino_1_1_snap_processor_r_p2040.html | 403 ++++++ ...ap__arduino_1_1_snap_processor_r_p2040.png | Bin 0 -> 617 bytes ...no_1_1_snap_processor_r_t_o_s-members.html | 178 +++ ...p__arduino_1_1_snap_processor_r_t_o_s.html | 426 ++++++ ...ap__arduino_1_1_snap_processor_r_t_o_s.png | Bin 0 -> 582 bytes ...sssnap__arduino_1_1_snap_time-members.html | 101 ++ .../classsnap__arduino_1_1_snap_time.html | 171 +++ ...p__arduino_1_1_snap_time_sync-members.html | 97 ++ ...classsnap__arduino_1_1_snap_time_sync.html | 272 ++++ .../classsnap__arduino_1_1_snap_time_sync.png | Bin 0 -> 1281 bytes ...no_1_1_snap_time_sync_dynamic-members.html | 99 ++ ...p__arduino_1_1_snap_time_sync_dynamic.html | 273 ++++ ...ap__arduino_1_1_snap_time_sync_dynamic.png | Bin 0 -> 645 bytes ...time_sync_dynamic_since_start-members.html | 100 ++ ..._1_snap_time_sync_dynamic_since_start.html | 276 ++++ ...1_1_snap_time_sync_dynamic_since_start.png | Bin 0 -> 737 bytes ...uino_1_1_snap_time_sync_fixed-members.html | 99 ++ ...nap__arduino_1_1_snap_time_sync_fixed.html | 273 ++++ ...snap__arduino_1_1_snap_time_sync_fixed.png | Bin 0 -> 595 bytes docs/html/files.html | 10 +- docs/html/functions.html | 172 ++- docs/html/functions_func.html | 172 ++- docs/html/hierarchy.html | 42 +- docs/html/index.html | 20 +- docs/html/menudata.js | 2 + docs/html/namespaces.html | 101 ++ docs/html/namespacesnap__arduino.html | 195 +++ docs/html/search/all_0.js | 2 +- docs/html/search/all_1.js | 4 +- docs/html/search/all_2.js | 3 +- docs/html/search/all_3.js | 3 +- docs/html/search/all_4.js | 2 +- docs/html/search/all_5.js | 6 +- docs/html/search/all_6.js | 8 +- docs/html/search/all_7.js | 3 +- docs/html/search/all_8.js | 87 +- docs/html/search/all_9.js | 8 +- docs/html/search/all_a.js | 4 +- docs/html/search/all_b.js | 2 +- docs/html/search/all_c.js | 6 +- docs/html/search/all_d.js | 2 +- docs/html/search/classes_0.js | 40 +- docs/html/search/classes_1.js | 2 +- docs/html/search/functions_0.js | 2 +- docs/html/search/functions_1.js | 4 +- docs/html/search/functions_2.js | 3 +- docs/html/search/functions_3.js | 3 +- docs/html/search/functions_4.js | 2 +- docs/html/search/functions_5.js | 6 +- docs/html/search/functions_6.js | 8 +- docs/html/search/functions_7.js | 3 +- docs/html/search/functions_8.js | 48 +- docs/html/search/functions_9.js | 6 +- docs/html/search/functions_a.js | 4 +- docs/html/search/functions_b.js | 2 +- docs/html/search/functions_c.js | 6 +- docs/html/search/functions_d.js | 2 +- docs/html/search/namespaces_0.html | 37 + docs/html/search/namespaces_0.js | 4 + docs/html/search/pages_0.js | 2 +- docs/html/search/searchdata.js | 15 +- ...arduino_1_1_snap_audio_header-members.html | 86 ++ ...ctsnap__arduino_1_1_snap_audio_header.html | 118 ++ ...arduino_1_1_snap_message_base-members.html | 89 ++ ...ctsnap__arduino_1_1_snap_message_base.html | 123 ++ ...1_1_snap_message_codec_header-members.html | 87 ++ ...arduino_1_1_snap_message_codec_header.html | 117 ++ ...rduino_1_1_snap_message_hallo-members.html | 95 ++ ...tsnap__arduino_1_1_snap_message_hallo.html | 149 +++ ..._snap_message_server_settings-members.html | 86 ++ ...uino_1_1_snap_message_server_settings.html | 114 ++ ...arduino_1_1_snap_message_time-members.html | 84 ++ ...ctsnap__arduino_1_1_snap_message_time.html | 108 ++ ...o_1_1_snap_message_wire_chunk-members.html | 85 ++ ...__arduino_1_1_snap_message_wire_chunk.html | 111 ++ ..._arduino_1_1_snap_read_buffer-members.html | 92 ++ ...uctsnap__arduino_1_1_snap_read_buffer.html | 132 ++ ..._arduino_1_1_snap_time_points-members.html | 85 ++ ...uctsnap__arduino_1_1_snap_time_points.html | 108 ++ ...arduino_1_1_snap_write_buffer-members.html | 92 ++ ...ctsnap__arduino_1_1_snap_write_buffer.html | 132 ++ .../structsnap__arduino_1_1tv__t-members.html | 83 ++ docs/html/structsnap__arduino_1_1tv__t.html | 101 ++ 109 files changed, 10420 insertions(+), 2189 deletions(-) create mode 100644 docs/html/_snap_processor_buffered_8h_source.html create mode 100644 docs/html/_snap_processor_r_p2040_8h_source.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_client-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_client.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_output-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_output.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_output.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_buffered-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_buffered.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_buffered.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_p2040-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_p2040.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_p2040.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_t_o_s-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_t_o_s.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_processor_r_t_o_s.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_time-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic_since_start-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic_since_start.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_dynamic_since_start.png create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_fixed-members.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_fixed.html create mode 100644 docs/html/classsnap__arduino_1_1_snap_time_sync_fixed.png create mode 100644 docs/html/namespaces.html create mode 100644 docs/html/namespacesnap__arduino.html create mode 100644 docs/html/search/namespaces_0.html create mode 100644 docs/html/search/namespaces_0.js create mode 100644 docs/html/structsnap__arduino_1_1_snap_audio_header-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_audio_header.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_base-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_base.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_codec_header-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_codec_header.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_hallo-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_hallo.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_server_settings-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_server_settings.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_time-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_time.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_wire_chunk-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_message_wire_chunk.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_read_buffer-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_read_buffer.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_time_points-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_time_points.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_write_buffer-members.html create mode 100644 docs/html/structsnap__arduino_1_1_snap_write_buffer.html create mode 100644 docs/html/structsnap__arduino_1_1tv__t-members.html create mode 100644 docs/html/structsnap__arduino_1_1tv__t.html diff --git a/docs/html/_snap_client_8h_source.html b/docs/html/_snap_client_8h_source.html index f8e9898..d1eedde 100644 --- a/docs/html/_snap_client_8h_source.html +++ b/docs/html/_snap_client_8h_source.html @@ -71,230 +71,252 @@
1 #pragma once
7 #include "AudioTools.h"
-
8 #include "SnapConfig.h"
-
9 #include "api/SnapCommon.h"
-
10 #include "api/SnapLogger.h"
-
11 //#include <WiFi.h>
-
12 #include "Client.h"
-
13 
-
14 
-
15 #if CONFIG_NVS_FLASH
-
16 #include "nvs_flash.h"
-
17 #endif
-
18 #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32)
-
19 #include <ESPmDNS.h>
-
20 #endif
-
21 
-
22 #include "api/SnapOutput.h"
-
23 #include "api/SnapProcessor.h"
-
24 
-
32 class SnapClient {
-
33 
-
34 public:
-
35  SnapClient(Client &client, AudioStream &stream, AudioDecoder &decoder) {
-
36  static AdapterAudioStreamToAudioOutput output_adapter;
-
37  output_adapter.setStream(stream);
-
38  p_decoder = &decoder;
-
39  p_output = &output_adapter;
-
40  p_client = &client;
-
41  }
-
42 
-
43  SnapClient(Client &client, AudioStream &stream, StreamingDecoder &decoder,
-
44  int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
-
45  static DecoderFromStreaming decoder_adapter(decoder, bufferSize);
-
46  static AdapterAudioStreamToAudioOutput output_adapter;
-
47  p_decoder = &decoder_adapter;
-
48  output_adapter.setStream(stream);
-
49  p_output = &output_adapter;
-
50  p_client = &client;
-
51  }
-
52 
-
53  SnapClient(Client &client, AudioOutput &output, AudioDecoder &decoder) {
-
54  p_decoder = &decoder;
-
55  p_output = &output;
-
56  p_client = &client;
-
57  }
-
58 
-
59  SnapClient(Client &client, AudioOutput &output, StreamingDecoder &decoder,
-
60  int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
-
61  p_decoder = new DecoderFromStreaming(decoder, bufferSize);
-
62  p_output = &output;
+
8 #include "Client.h"
+
9 #include "SnapConfig.h"
+
10 #include "api/SnapCommon.h"
+
11 #include "api/SnapLogger.h"
+
12 
+
13 #if CONFIG_NVS_FLASH
+
14 #include "nvs_flash.h"
+
15 #endif
+
16 #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32)
+
17 #include <ESPmDNS.h>
+
18 #endif
+
19 
+
20 #ifdef ESP32
+
21 #include <WiFi.h>
+
22 #endif
+
23 
+
24 #include "api/SnapOutput.h"
+
25 #include "api/SnapProcessor.h"
+
26 
+
27 namespace snap_arduino {
+
28 
+
36 class SnapClient {
+
37  public:
+
38  SnapClient(Client &client, AudioStream &stream, AudioDecoder &decoder) {
+
39  static AdapterAudioStreamToAudioOutput output_adapter;
+
40  output_adapter.setStream(stream);
+
41  p_decoder = &decoder;
+
42  p_output = &output_adapter;
+
43  p_client = &client;
+
44  server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST);
+
45  }
+
46 
+
47  SnapClient(Client &client, Print &stream, AudioDecoder &decoder) {
+
48  static AdapterPrintToAudioOutput output_adapter;
+
49  output_adapter.setStream(stream);
+
50  p_decoder = &decoder;
+
51  p_output = &output_adapter;
+
52  p_client = &client;
+
53  server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST);
+
54  }
+
55 
+
56  SnapClient(Client &client, AudioStream &stream, StreamingDecoder &decoder,
+
57  int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
+
58  static DecoderFromStreaming decoder_adapter(decoder, bufferSize);
+
59  static AdapterAudioStreamToAudioOutput output_adapter;
+
60  p_decoder = &decoder_adapter;
+
61  output_adapter.setStream(stream);
+
62  p_output = &output_adapter;
63  p_client = &client;
-
64  }
-
65 
- -
68  end();
-
69  }
-
70 
-
72  void setClient(Client &client) { p_client = &client; }
+
64  server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST);
+
65  }
+
66 
+
67  SnapClient(Client &client, AudioOutput &output, AudioDecoder &decoder) {
+
68  p_decoder = &decoder;
+
69  p_output = &output;
+
70  p_client = &client;
+
71  server_ip.fromString(CONFIG_SNAPCAST_SERVER_HOST);
+
72  }
73 
-
76  void setServerIP(IPAddress ipAddress) { this->address = ipAddress; }
-
77 
-
79  void setSnapTimeSync(SnapTimeSync &timeSync){
-
80  p_time_sync = &timeSync;
-
81  }
-
82 
-
84  bool begin(SnapTimeSync &timeSync) {
-
85  setSnapTimeSync(timeSync);
-
86  return begin();
-
87  }
-
88 
-
90  bool begin() {
-
91 #if defined(ESP32)
-
92  if (WiFi.status() != WL_CONNECTED) {
-
93  ESP_LOGE(TAG, "WiFi not connected");
-
94  return false;
-
95  }
-
96  // use maximum speed
-
97  WiFi.setSleep(false);
-
98  ESP_LOGI(TAG, "Connected to AP");
-
99 #endif
-
100 
-
101  // Get MAC address for WiFi station
-
102  setupMACAddress();
-
103 
-
104  setupNVS();
-
105 
-
106  setupMDNS();
-
107 
-
108  setupPSRAM();
-
109 
-
110 #if CONFIG_SNAPCLIENT_SNTP_ENABLE
-
111  SnapTime::instance().setupSNTPTime();
+
74  SnapClient(Client &client, AudioOutput &output, StreamingDecoder &decoder,
+
75  int bufferSize = CONFIG_STREAMIN_DECODER_BUFFER) {
+
76  p_decoder = new DecoderFromStreaming(decoder, bufferSize);
+
77  p_output = &output;
+
78  p_client = &client;
+
79  }
+
80 
+
82  ~SnapClient() { end(); }
+
83 
+
85  void setClient(Client &client) { p_client = &client; }
+
86 
+
89  void setServerIP(IPAddress ipAddress) { this->server_ip = ipAddress; }
+
90 
+
92  void setSnapTimeSync(SnapTimeSync &timeSync) { p_time_sync = &timeSync; }
+
93 
+
95  bool begin(SnapTimeSync &timeSync) {
+
96  setSnapTimeSync(timeSync);
+
97  return begin();
+
98  }
+
99 
+
101  bool begin() {
+
102 #if defined(ESP32)
+
103  if (is_wifi) {
+
104  if (WiFi.status() != WL_CONNECTED) {
+
105  ESP_LOGE(TAG, "WiFi not connected");
+
106  return false;
+
107  }
+
108  // use maximum speed
+
109  WiFi.setSleep(false);
+
110  ESP_LOGI(TAG, "Connected to AP");
+
111  }
112 #endif
113 
-
114  p_snapprocessor->setServerIP(address);
-
115  p_snapprocessor->setOutput(*p_output);
-
116  p_snapprocessor->snapOutput().setSnapTimeSync(*p_time_sync);
-
117  p_snapprocessor->setDecoder(*p_decoder);
-
118  p_snapprocessor->setClient(*p_client);
-
119 
-
120  // start tasks
-
121  return p_snapprocessor->begin();
-
122  }
-
123 
-
125  void end(void) { p_snapprocessor->end(); }
-
126 
-
128  float volume(void) { return p_snapprocessor->volume(); }
-
129 
-
131  void setVolumeFactor(float fact) { p_snapprocessor->setVolumeFactor(fact); }
-
132 
-
134  void setStartTask(bool flag) { p_snapprocessor->setStartTask(flag); }
+
114  // Get MAC address for WiFi station
+
115  setupMACAddress();
+
116 
+
117  setupNVS();
+
118 
+
119  setupMDNS();
+
120 
+
121 #if CONFIG_SNAPCLIENT_SNTP_ENABLE
+
122  SnapTime::instance().setupSNTPTime();
+
123 #endif
+
124 
+
125  p_snapprocessor->setServerIP(server_ip);
+
126  p_snapprocessor->setServerPort(server_port);
+
127  p_snapprocessor->setOutput(*p_output);
+
128  p_snapprocessor->snapOutput().setSnapTimeSync(*p_time_sync);
+
129  p_snapprocessor->setDecoder(*p_decoder);
+
130  p_snapprocessor->setClient(*p_client);
+
131 
+
132  // start tasks
+
133  return p_snapprocessor->begin();
+
134  }
135 
-
137  void setStartOutput(bool start) { p_snapprocessor->setStartOutput(start); }
+
137  void end(void) { p_snapprocessor->end(); }
138 
-
140  void setSnapProcessor(SnapProcessor &processor) {
-
141  p_snapprocessor = &processor;
-
142  }
-
143 
- -
146  p_snapprocessor->setSnapOutput(out);
-
147  }
-
148 
-
150  void doLoop() { p_snapprocessor->doLoop(); }
-
151 
-
152 protected:
-
153  const char *TAG = "SnapClient";
-
154  SnapTime &snap_time = SnapTime::instance();
-
155  SnapProcessor default_processor;
-
156  SnapProcessor *p_snapprocessor = &default_processor;
-
157  AudioOutput *p_output = nullptr;
-
158  AudioDecoder *p_decoder = nullptr;
-
159  Client *p_client = nullptr;
-
160  SnapTimeSync *p_time_sync = nullptr;
-
161  IPAddress address;
-
162 
-
163  void setupMDNS() {
-
164 #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32)
-
165  ESP_LOGD(TAG, "start");
-
166  if (!MDNS.begin(CONFIG_SNAPCAST_CLIENT_NAME)) {
-
167  LOGE(TAG, "Error starting mDNS");
-
168  return;
-
169  }
+
140  float volume(void) { return p_snapprocessor->volume(); }
+
141 
+
143  void setVolumeFactor(float fact) { p_snapprocessor->setVolumeFactor(fact); }
+
144 
+
146  void setStartTask(bool flag) { p_snapprocessor->setStartTask(flag); }
+
147 
+
149  void setStartOutput(bool start) { p_snapprocessor->setStartOutput(start); }
+
150 
+
152  void setSnapProcessor(SnapProcessor &processor) {
+
153  p_snapprocessor = &processor;
+
154  }
+
155 
+
157  SnapProcessor &snapProcessor() { return *p_snapprocessor; }
+
158 
+
160  void setSnapOutput(SnapOutput &out) { p_snapprocessor->setSnapOutput(out); }
+
161 
+
163  bool doLoop() { return p_snapprocessor->doLoop(); }
+
164 
+
166  void setWiFi(bool flag){ is_wifi = flag;}
+
167 
+
169  bool isWiFi() {return is_wifi;}
170 
-
171  // we just take the first address
-
172  int nrOfServices = MDNS.queryService("snapcast", "tcp");
-
173  if (nrOfServices > 0) {
-
174  IPAddress server_ip = MDNS.IP(0);
-
175  char str_address[20] = {0};
-
176  sprintf(str_address, "%d.%d.%d.%d", server_ip[0], server_ip[1],
-
177  server_ip[2], server_ip[3]);
-
178  int server_port = MDNS.port(0);
-
179 
-
180  // update addres information
-
181  p_snapprocessor->setServerIP(server_ip);
-
182  p_snapprocessor->setServerPort(server_port);
-
183  ESP_LOGI(TAG, "SNAPCAST ip: %s, port: %d", str_address, server_port);
-
184 
-
185  } else {
-
186  ESP_LOGE(TAG, "SNAPCAST server not found");
-
187  }
+
171  protected:
+
172  const char *TAG = "SnapClient";
+
173  SnapTime &snap_time = SnapTime::instance();
+
174  SnapProcessor default_processor;
+
175  SnapProcessor *p_snapprocessor = &default_processor;
+
176  AudioOutput *p_output = nullptr;
+
177  AudioDecoder *p_decoder = nullptr;
+
178  Client *p_client = nullptr;
+
179  SnapTimeSyncDynamic time_sync_default;
+
180  SnapTimeSync *p_time_sync = &time_sync_default;
+
181  IPAddress server_ip;
+
182  int server_port = CONFIG_SNAPCAST_SERVER_PORT;
+
183 #ifdef ESP32
+
184  bool is_wifi = true;
+
185 #else
+
186  bool is_wifi = false;
+
187 #endif
188 
-
189  MDNS.end();
-
190  checkHeap();
-
191 #endif
-
192  }
-
193 
-
194  void setupNVS() {
-
195 #if CONFIG_NVS_FLASH && defined(ESP32)
-
196  esp_err_t ret = nvs_flash_init();
-
197  if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
-
198  ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
-
199  ESP_ERROR_CHECK(nvs_flash_erase());
-
200  ret = nvs_flash_init();
-
201  }
-
202  checkHeap();
-
203  ESP_ERROR_CHECK(ret);
+
189  void setupMDNS() {
+
190 #if CONFIG_SNAPCLIENT_USE_MDNS && defined(ESP32)
+
191  ESP_LOGD(TAG, "start");
+
192  if (!MDNS.begin(CONFIG_SNAPCAST_CLIENT_NAME)) {
+
193  LOGE(TAG, "Error starting mDNS");
+
194  return;
+
195  }
+
196 
+
197  // we just take the first address
+
198  int nrOfServices = MDNS.queryService("snapcast", "tcp");
+
199  if (nrOfServices > 0) {
+
200 #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
+
201  server_ip = MDNS.address(0);
+
202 #else
+
203  server_ip = MDNS.IP(0);
204 #endif
-
205  }
-
206 
-
207  void setupPSRAM() {
-
208 #if CONFIG_USE_PSRAM && defined(ESP32)
-
209  if (ESP.getPsramSize() > 0) {
-
210  heap_caps_malloc_extmem_enable(CONFIG_PSRAM_LIMIT);
-
211  ESP_LOGD(TAG, "PSRAM for allocations > %d bytes", CONFIG_PSRAM_LIMIT);
-
212  } else {
-
213  ESP_LOGW(TAG, "No PSRAM available or PSRAM not activated");
-
214  }
-
215 #endif
-
216  }
-
217 
-
218  void setupMACAddress() {
-
219 #ifdef ESP32
-
220  const char *adr = strdup(WiFi.macAddress().c_str());
-
221  p_snapprocessor->setMacAddress(adr);
-
222  ESP_LOGI(TAG, "mac: %s", adr);
-
223  checkHeap();
-
224 #endif
-
225  }
-
226 };
-
Snap Client for ESP32 Arduino.
Definition: SnapClient.h:32
-
void end(void)
ends the processing and releases the resources
Definition: SnapClient.h:125
-
void setServerIP(IPAddress ipAddress)
Defines the Snapcast Server IP address.
Definition: SnapClient.h:76
-
void setStartTask(bool flag)
For testing to deactivate the starting of the http task.
Definition: SnapClient.h:134
-
~SnapClient()
Destructor.
Definition: SnapClient.h:67
-
void doLoop()
Call from Arduino Loop - to receive and process the audio data.
Definition: SnapClient.h:150
-
void setSnapOutput(SnapOutput &out)
Defines the Snap output implementation to be used.
Definition: SnapClient.h:145
-
bool begin()
Starts the processing.
Definition: SnapClient.h:90
-
void setVolumeFactor(float fact)
Adjust volume by factor e.g. 1.5.
Definition: SnapClient.h:131
-
float volume(void)
Provides the actual volume (in the range of 0.0 to 1.0)
Definition: SnapClient.h:128
-
void setClient(Client &client)
Defines an alternative commnuication client (default is WiFiClient)
Definition: SnapClient.h:72
-
void setSnapProcessor(SnapProcessor &processor)
Defines an alternative Processor.
Definition: SnapClient.h:140
-
bool begin(SnapTimeSync &timeSync)
Starts the processing.
Definition: SnapClient.h:84
-
void setSnapTimeSync(SnapTimeSync &timeSync)
Defines the time synchronization logic.
Definition: SnapClient.h:79
-
void setStartOutput(bool start)
For Testing: Used to prevent the starting of the output task.
Definition: SnapClient.h:137
-
Simple Output Class which uses the AudioTools to build an output chain with volume control and a resa...
Definition: SnapOutput.h:26
-
void setSnapTimeSync(SnapTimeSync &timeSync)
Defines the time synchronization logic.
Definition: SnapOutput.h:120
-
Snap Processor implementation which does not rely on FreeRTOS.
Definition: SnapProcessor.h:19
-
void setSnapOutput(SnapOutput &out)
Defines the SnapOutput implementation.
Definition: SnapProcessor.h:85
-
void setDecoder(AudioDecoder &dec)
Defines the decoder class.
Definition: SnapProcessor.h:76
-
void setVolumeFactor(float fact)
Adjust volume by factor e.g. 1.5.
Definition: SnapProcessor.h:82
-
float volume(void)
Provides the volume (in the range of 0.0 to 1.0)
Definition: SnapProcessor.h:79
-
void setOutput(AudioOutput &output)
Defines the output class.
Definition: SnapProcessor.h:73
-
void setClient(Client &client)
Defines an alternative client to the WiFiClient.
Definition: SnapProcessor.h:90
-
virtual void doLoop()
Call via SnapClient in Arduino Loop!
Definition: SnapProcessor.h:70
-
The the sys/time functions are used to represent the server time. The local time will be measured wit...
Definition: SnapTime.h:16
-
Abstract (Common) Time Synchronization Logic which consists of the startup synchronization and the lo...
Definition: SnapTimeSync.h:15
+
205  char str_address[20] = {0};
+
206  sprintf(str_address, "%d.%d.%d.%d", server_ip[0], server_ip[1],
+
207  server_ip[2], server_ip[3]);
+
208  server_port = MDNS.port(0);
+
209 
+
210  ESP_LOGI(TAG, "MDNS: SNAPCAST ip: %s, port: %d", str_address,
+
211  server_port);
+
212 
+
213  } else {
+
214  ESP_LOGE(TAG, "SNAPCAST server not found");
+
215  }
+
216 
+
217  MDNS.end();
+
218  checkHeap();
+
219 #endif
+
220  }
+
221 
+
222  void setupNVS() {
+
223 #if CONFIG_NVS_FLASH && defined(ESP32)
+
224  esp_err_t ret = nvs_flash_init();
+
225  if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
+
226  ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
+
227  ESP_ERROR_CHECK(nvs_flash_erase());
+
228  ret = nvs_flash_init();
+
229  }
+
230  checkHeap();
+
231  ESP_ERROR_CHECK(ret);
+
232 #endif
+
233  }
+
234 
+
235  void setupMACAddress() {
+
236 #ifdef ESP32
+
237  const char *adr = strdup(WiFi.macAddress().c_str());
+
238  p_snapprocessor->setMacAddress(adr);
+
239  ESP_LOGI(TAG, "mac: %s", adr);
+
240  checkHeap();
+
241 #endif
+
242  }
+
243 };
+
244 
+
245 } // namespace snap_arduino
+
Snap Client for ESP32 Arduino.
Definition: SnapClient.h:36
+
void end(void)
ends the processing and releases the resources
Definition: SnapClient.h:137
+
void setServerIP(IPAddress ipAddress)
Defines the Snapcast Server IP address.
Definition: SnapClient.h:89
+
void setStartTask(bool flag)
For testing to deactivate the starting of the http task.
Definition: SnapClient.h:146
+
bool isWiFi()
check if we use the ESP32 WiFi for checking the link status
Definition: SnapClient.h:169
+
~SnapClient()
Destructor.
Definition: SnapClient.h:82
+
void setSnapOutput(SnapOutput &out)
Defines the Snap output implementation to be used.
Definition: SnapClient.h:160
+
bool begin()
Starts the processing.
Definition: SnapClient.h:101
+
void setVolumeFactor(float fact)
Adjust volume by factor e.g. 1.5.
Definition: SnapClient.h:143
+
float volume(void)
Provides the actual volume (in the range of 0.0 to 1.0)
Definition: SnapClient.h:140
+
void setClient(Client &client)
Defines an alternative commnuication client (default is WiFiClient)
Definition: SnapClient.h:85
+
void setWiFi(bool flag)
ESP32: WiFiClient: prevent/activate WiFi link status check.
Definition: SnapClient.h:166
+
void setSnapProcessor(SnapProcessor &processor)
Defines an alternative Processor.
Definition: SnapClient.h:152
+
bool begin(SnapTimeSync &timeSync)
Starts the processing.
Definition: SnapClient.h:95
+
bool doLoop()
Call from Arduino Loop - to receive and process the audio data.
Definition: SnapClient.h:163
+
void setSnapTimeSync(SnapTimeSync &timeSync)
Defines the time synchronization logic.
Definition: SnapClient.h:92
+
void setStartOutput(bool start)
For Testing: Used to prevent the starting of the output task.
Definition: SnapClient.h:149
+
SnapProcessor & snapProcessor()
Provides the actual processor.
Definition: SnapClient.h:157
+
Simple Output Class which uses the AudioTools to build an output chain with volume control and a resa...
Definition: SnapOutput.h:27
+
void setSnapTimeSync(SnapTimeSync &timeSync)
Defines the time synchronization logic.
Definition: SnapOutput.h:123
+
Snap Processor implementation which does not rely on FreeRTOS.
Definition: SnapProcessor.h:21
+
virtual bool begin()
Sets up the output and the client.
Definition: SnapProcessor.h:36
+
void setSnapOutput(SnapOutput &out)
Defines the SnapOutput implementation.
Definition: SnapProcessor.h:106
+
void setDecoder(AudioDecoder &dec)
Defines the decoder class.
Definition: SnapProcessor.h:97
+
void setVolumeFactor(float fact)
Adjust volume by factor e.g. 1.5.
Definition: SnapProcessor.h:103
+
float volume(void)
Provides the volume (in the range of 0.0 to 1.0)
Definition: SnapProcessor.h:100
+
void setOutput(AudioOutput &output)
Defines the output class.
Definition: SnapProcessor.h:94
+
void setClient(Client &client)
Defines an alternative client to the WiFiClient.
Definition: SnapProcessor.h:111
+
bool doLoop()
Call via SnapClient in Arduino Loop!
Definition: SnapProcessor.h:81
+
The the sys/time functions are used to represent the server time. The local time will be measured wit...
Definition: SnapTime.h:22
+
Dynamically adjusts the effective playback sample rate based on the differences of the local and serv...
Definition: SnapTimeSync.h:91
+
Abstract (Common) Time Synchronization Logic which consists of the startup synchronization and the lo...
Definition: SnapTimeSync.h:17
+
Definition: SnapCommon.h:10