From cc23764e10f5b9afc4c3a1986a0ebc7e7ac7727e Mon Sep 17 00:00:00 2001 From: Mark Kelly <1787606+kel30a@users.noreply.github.com> Date: Tue, 10 Sep 2024 03:46:50 +1000 Subject: [PATCH 01/30] Update cmakelist.txt file to support compiling in ESP IDF --- CMakeLists.txt | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a42c31..0b7878d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,42 @@ cmake_minimum_required(VERSION 3.16) -# set the project name -project(arduino_helix) +if (DEFINED ESP_PLATFORM) + # idf component + idf_component_register( + SRC_DIRS src src/utils src/libhelix-aac src/libhelix-mp3 + INCLUDE_DIRS src src/utils src/libhelix-aac src/libhelix-mp3 + REQUIRES arduino-esp32 + ) -# lots of warnings and all warnings as errors -## add_compile_options(-Wall -Wextra ) -set(CMAKE_CXX_STANDARD 17) + target_compile_options(${COMPONENT_LIB} INTERFACE -Wno-error -Wno-format) + target_compile_options(${COMPONENT_LIB} PRIVATE -DUSE_DEFAULT_STDLIB) + add_compile_definitions(ESP32) +else() -option(MP3_EXAMPLES "build examples" OFF) + # set the project name + project(arduino_helix) -file(GLOB_RECURSE SRC_LIST_C CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.c" ) -file(GLOB_RECURSE SRC_LIST_CPP CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp" ) + # lots of warnings and all warnings as errors + ## add_compile_options(-Wall -Wextra ) + set(CMAKE_CXX_STANDARD 17) -# define libraries -add_library (arduino_helix ${SRC_LIST_C} ${SRC_LIST_CPP}) + option(MP3_EXAMPLES "build examples" OFF) -# prevent compile errors -target_compile_options(arduino_helix PRIVATE -DUSE_DEFAULT_STDLIB) + file(GLOB_RECURSE SRC_LIST_C CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.c" ) + file(GLOB_RECURSE SRC_LIST_CPP CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp" ) -# define location for header files -target_include_directories(arduino_helix PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/libhelix-mp3 ${CMAKE_CURRENT_SOURCE_DIR}/src/libhelix-aac ) + # define libraries + add_library (arduino_helix ${SRC_LIST_C} ${SRC_LIST_CPP}) -# build examples -if(MP3_EXAMPLES) - add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/examples/output_mp3") - add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/examples/output_aac") + # prevent compile errors + target_compile_options(arduino_helix PRIVATE -DUSE_DEFAULT_STDLIB) + + # define location for header files + target_include_directories(arduino_helix PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/libhelix-mp3 ${CMAKE_CURRENT_SOURCE_DIR}/src/libhelix-aac ) + + # build examples + if(MP3_EXAMPLES) + add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/examples/output_mp3") + add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/examples/output_aac") + endif() endif() \ No newline at end of file From 5f5b6e5ae9ee07d6ecc772c2d56136ad96076958 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 4 Oct 2024 10:56:17 +0200 Subject: [PATCH 02/30] 0.8.6 in library.properties --- library.properties | 2 +- src/MP3DecoderHelix.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 8d8f1a3..ef484b5 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=libhelix -version=0.8.5 +version=0.8.6 author=Phil Schatzmann maintainer= sentence=libhelix audio decoder for Arduino diff --git a/src/MP3DecoderHelix.h b/src/MP3DecoderHelix.h index 9ae0ca5..52d3a2b 100644 --- a/src/MP3DecoderHelix.h +++ b/src/MP3DecoderHelix.h @@ -149,7 +149,10 @@ class MP3DecoderHelix : public CommonHelix { } #if defined(ARDUINO) || defined(HELIX_PRINT) int sampleSize = info.bitsPerSample / 8; - out->write((uint8_t *)pcm_buffer.data(), info.outputSamps * sampleSize); + int toWrite = info.outputSamps * sampleSize; + int written = out->write((uint8_t *)pcm_buffer.data(), toWrite); + // assume blocking write + assert(written == toWrite); #endif } mp3FrameInfo = info; From a83886bc3588f862903f0f886ff6e29f48dc6fc2 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Sun, 20 Oct 2024 19:07:37 +0200 Subject: [PATCH 03/30] Support to resize a vector to 0 --- src/utils/Vector.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/Vector.h b/src/utils/Vector.h index 3a8c2eb..547759a 100644 --- a/src/utils/Vector.h +++ b/src/utils/Vector.h @@ -282,7 +282,14 @@ class Vector { Allocator *p_allocator = &DefaultAllocator; void resize_internal(int newSize, bool copy, bool shrink = false) { - if (newSize <= 0) return; + if (newSize <= 0 && p_data==nullptr) return; + // release memory + if (newSize <= 0) { + deleteArray(p_data, size()); // delete [] this->p_data; + p_data = nullptr; + return; + } + // allocate new memory if (newSize > bufferLen || this->p_data == nullptr || shrink) { T *oldData = p_data; int oldBufferLen = this->bufferLen; From d00adcba976aed781ff979fc85cddaa888b40591 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 28 Oct 2024 13:44:37 +0100 Subject: [PATCH 04/30] Correct processed bytes in mp3 --- src/MP3DecoderHelix.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MP3DecoderHelix.h b/src/MP3DecoderHelix.h index 52d3a2b..1d93a39 100644 --- a/src/MP3DecoderHelix.h +++ b/src/MP3DecoderHelix.h @@ -125,7 +125,6 @@ class MP3DecoderHelix : public CommonHelix { provideResult(info); } else { LOG_HELIX(LogLevelHelix::Info, "MP3Decode rc: %d", rc); - processed = rc; } return processed; } From 41b6b0c31e5f773f5d66f8a2147a7087bb595209 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 13 Jan 2025 14:08:47 +0100 Subject: [PATCH 05/30] Prevent NPE if output is not defined --- src/AACDecoderHelix.h | 6 +++++- src/MP3DecoderHelix.h | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/AACDecoderHelix.h b/src/AACDecoderHelix.h index 8fa43e3..5fd78da 100644 --- a/src/AACDecoderHelix.h +++ b/src/AACDecoderHelix.h @@ -139,7 +139,11 @@ class AACDecoderHelix : public CommonHelix { infoCallback(info, p_caller_ref); } #if defined(ARDUINO) || defined(HELIX_PRINT) - out->write((uint8_t *)pcm_buffer.data(), info.outputSamps * sampleSize); + if (out != nullptr){ + size_t to_write = info.outputSamps * sampleSize; + size_t written = out->write((uint8_t *)pcm_buffer.data(), to_write); + assert(written == to_write); + } #endif } aacFrameInfo = info; diff --git a/src/MP3DecoderHelix.h b/src/MP3DecoderHelix.h index 1d93a39..47ade1f 100644 --- a/src/MP3DecoderHelix.h +++ b/src/MP3DecoderHelix.h @@ -147,11 +147,13 @@ class MP3DecoderHelix : public CommonHelix { infoCallback(info, p_caller_ref); } #if defined(ARDUINO) || defined(HELIX_PRINT) - int sampleSize = info.bitsPerSample / 8; - int toWrite = info.outputSamps * sampleSize; - int written = out->write((uint8_t *)pcm_buffer.data(), toWrite); - // assume blocking write - assert(written == toWrite); + if (out != nullptr){ + int sampleSize = info.bitsPerSample / 8; + int toWrite = info.outputSamps * sampleSize; + int written = out->write((uint8_t *)pcm_buffer.data(), toWrite); + // assume blocking write + assert(written == toWrite); + } #endif } mp3FrameInfo = info; From dbda3e0fbee14d6d79bc3f9faf4f6aae0943aede Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 17 Feb 2025 18:11:32 +0100 Subject: [PATCH 06/30] flush: decode only complete segments --- src/AACDecoderHelix.h | 1 + src/CommonHelix.h | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AACDecoderHelix.h b/src/AACDecoderHelix.h index 5fd78da..9a2bf89 100644 --- a/src/AACDecoderHelix.h +++ b/src/AACDecoderHelix.h @@ -104,6 +104,7 @@ class AACDecoderHelix : public CommonHelix { /// decods the data and removes the decoded frame from the buffer int decode() override { + LOG_HELIX(LogLevelHelix::Debug, "decode"); int processed = 0; int available = frame_buffer.available(); int bytes_left = frame_buffer.available(); diff --git a/src/CommonHelix.h b/src/CommonHelix.h index b370c88..2fc6ce3 100644 --- a/src/CommonHelix.h +++ b/src/CommonHelix.h @@ -102,11 +102,14 @@ class CommonHelix { void flush() { int rc = 1; while (rc >= 0) { + // we must start with sych word if (!presync()) break; + // we must end with synch world + if (findSynchWord(3) < 0) break; rc = decode(); if (!resynch(rc)) break; // remove processed data - frame_buffer.clearArray(rc); + if (rc > 0) frame_buffer.clearArray(rc); } } @@ -155,6 +158,7 @@ class CommonHelix { bool rc = true; int pos = findSynchWord(); if (pos > 3) rc = removeInvalidData(pos); + return rc; } From a2b00becd5c2fa12169c824a5fe06fba949bcd10 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 17 Feb 2025 18:29:35 +0100 Subject: [PATCH 07/30] version 0.8.7 --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index ef484b5..0f0ad0e 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name=libhelix -version=0.8.6 +version=0.8.7 author=Phil Schatzmann -maintainer= +maintainer= https://github.com/pschatzmann sentence=libhelix audio decoder for Arduino paragraph=libhelix audio decoder for Arduino category=Signal Input/Output From a3abf4e8878d6bcd499ecbf19faa19505a759a8e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 26 Feb 2025 10:39:11 +0100 Subject: [PATCH 08/30] Readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 48f7b37..70dc482 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ LOGLEVEL_HELIX = LogLevelHelix::Info; ## Documentation - The [Class Documentation can be found here](https://pschatzmann.github.io/arduino-libhelix/html/annotated.html) +- aac [readme.txt](https://github.com/pschatzmann/arduino-libhelix/blob/main/src/libhelix-aac/readme.txt) +- mp3 [readme.txt](https://github.com/pschatzmann/arduino-libhelix/blob/main/src/libhelix-mp3/readme.txt) - I also suggest that you have a look at [my related blogs](https://www.pschatzmann.ch/home/tag/codecs/) I recommend to use this library together with my [Arduino Audio Tools](https://github.com/pschatzmann/arduino-audio-tools). From a5670cc65615cd6886485978df638fefac2c59bf Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 26 Feb 2025 11:52:47 +0100 Subject: [PATCH 09/30] Move HELIX_FEATURE_AUDIO_CODEC_AAC_SBR to ConfigHelix.h --- src/ConfigHelix.h | 5 +++++ src/libhelix-aac/aaccommon.h | 9 +++++---- src/libhelix-aac/aacdec.h | 4 ---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ConfigHelix.h b/src/ConfigHelix.h index 0baa6b4..2800512 100644 --- a/src/ConfigHelix.h +++ b/src/ConfigHelix.h @@ -53,4 +53,9 @@ #ifndef HELIX_LOG_SIZE # define HELIX_LOG_SIZE 256 +#endif + +/// the ESP8266 does not have enough memory +#ifndef ESP8266 +# define HELIX_FEATURE_AUDIO_CODEC_AAC_SBR #endif \ No newline at end of file diff --git a/src/libhelix-aac/aaccommon.h b/src/libhelix-aac/aaccommon.h index 8ca4f70..1ddb97d 100644 --- a/src/libhelix-aac/aaccommon.h +++ b/src/libhelix-aac/aaccommon.h @@ -48,12 +48,13 @@ //#include //#include +#include "ConfigHelix.h" #include "utils/helix_pgm.h" -// Can't fit in ESP8266 RAM -//#ifndef ESP8266 -#define AAC_ENABLE_SBR 0 -//#endif +/* define these to enable decoder features */ +#if defined(HELIX_FEATURE_AUDIO_CODEC_AAC_SBR) +# define AAC_ENABLE_SBR +#endif // HELIX_FEATURE_AUDIO_CODEC_AAC_SBR. #pragma GCC optimize ("O3") diff --git a/src/libhelix-aac/aacdec.h b/src/libhelix-aac/aacdec.h index 0f7d91f..86b6a9a 100644 --- a/src/libhelix-aac/aacdec.h +++ b/src/libhelix-aac/aacdec.h @@ -99,10 +99,6 @@ extern "C" { #define AAC_PROFILE_LC 1 #define AAC_PROFILE_SSR 2 -/* define these to enable decoder features */ -#if defined(HELIX_FEATURE_AUDIO_CODEC_AAC_SBR) -#define AAC_ENABLE_SBR -#endif // HELIX_FEATURE_AUDIO_CODEC_AAC_SBR. #define AAC_ENABLE_MPEG4 enum { From ba5aca4a16f01d886c88ea3605f00b667843c7a1 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 6 Mar 2025 16:58:12 +0100 Subject: [PATCH 10/30] IDF as component --- src/libhelix-aac/noiseless.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libhelix-aac/noiseless.c b/src/libhelix-aac/noiseless.c index 5d3a65d..3fac059 100644 --- a/src/libhelix-aac/noiseless.c +++ b/src/libhelix-aac/noiseless.c @@ -45,6 +45,7 @@ **************************************************************************************/ #include "coder.h" +//#pragma GCC diagnostic ignored "-Wstringop-overflow" //#include "profile.h" From 79b657676a67456836ddcf1abede664906216465 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 6 Mar 2025 16:58:39 +0100 Subject: [PATCH 11/30] IDF as component --- CMakeLists.txt | 2 +- src/CommonHelix.h | 4 ++++ src/MP3DecoderHelix.h | 2 +- src/libhelix-aac/aaccommon.h | 4 +++- src/libhelix-aac/aacdec.h | 2 +- src/libhelix-aac/assembly.h | 2 +- src/libhelix-mp3/assembly.h | 2 +- src/utils/Allocator.h | 17 +++++++++++++---- src/utils/Buffers.h | 7 ++++--- 9 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b7878d..8e024b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ if (DEFINED ESP_PLATFORM) idf_component_register( SRC_DIRS src src/utils src/libhelix-aac src/libhelix-mp3 INCLUDE_DIRS src src/utils src/libhelix-aac src/libhelix-mp3 - REQUIRES arduino-esp32 + # REQUIRES arduino-esp32 ) target_compile_options(${COMPONENT_LIB} INTERFACE -Wno-error -Wno-format) diff --git a/src/CommonHelix.h b/src/CommonHelix.h index 2fc6ce3..8662e05 100644 --- a/src/CommonHelix.h +++ b/src/CommonHelix.h @@ -92,11 +92,13 @@ class CommonHelix { /// returns true if active operator bool() { return active; } +#ifdef ARDUINO /// Provides the timestamp in ms of last write uint64_t timeOfLastWrite() { return time_last_write; } /// Provides the timestamp in ms of last decoded result uint64_t timeOfLastResult() { return time_last_result; } +#endif /// Decode all open packets void flush() { @@ -212,7 +214,9 @@ class CommonHelix { /// Decoding Loop: We decode the procided data until we run out of data virtual size_t writeChunk(const void *in_ptr, size_t in_size) { LOG_HELIX(LogLevelHelix::Info, "writeChunk %zu", in_size); +#ifdef ARDUINO time_last_write = millis(); +#endif size_t result = frame_buffer.writeArray((uint8_t *)in_ptr, in_size); while (frame_buffer.available() >= minFrameBufferSize()) { diff --git a/src/MP3DecoderHelix.h b/src/MP3DecoderHelix.h index 47ade1f..9c188fc 100644 --- a/src/MP3DecoderHelix.h +++ b/src/MP3DecoderHelix.h @@ -113,7 +113,7 @@ class MP3DecoderHelix : public CommonHelix { int processed = 0; int available = frame_buffer.available(); int bytes_left = frame_buffer.available(); - LOG_HELIX(LogLevelHelix::Info, "decode: %d", frame_buffer.available()); + LOG_HELIX(LogLevelHelix::Info, "decode: %d (left:%d)", available, bytes_left); uint8_t *data = frame_buffer.data(); int rc = MP3Decode(decoder, &data, &bytes_left, (short *)pcm_buffer.data(), mp3_type); diff --git a/src/libhelix-aac/aaccommon.h b/src/libhelix-aac/aaccommon.h index 1ddb97d..f841529 100644 --- a/src/libhelix-aac/aaccommon.h +++ b/src/libhelix-aac/aaccommon.h @@ -56,8 +56,10 @@ # define AAC_ENABLE_SBR #endif // HELIX_FEATURE_AUDIO_CODEC_AAC_SBR. +#ifndef ARDUINO #pragma GCC optimize ("O3") - +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif #include "aacdec.h" #include "statname.h" diff --git a/src/libhelix-aac/aacdec.h b/src/libhelix-aac/aacdec.h index 86b6a9a..678454d 100644 --- a/src/libhelix-aac/aacdec.h +++ b/src/libhelix-aac/aacdec.h @@ -68,7 +68,7 @@ # #elif defined(_SOLARIS) && !defined(__GNUC__) # -#elif defined(ARDUINO) +#elif defined(ARDUINO) || defined(ESP32) # #else #error No platform defined. See valid options in aacdec.h diff --git a/src/libhelix-aac/assembly.h b/src/libhelix-aac/assembly.h index 595a8fc..a773cc2 100644 --- a/src/libhelix-aac/assembly.h +++ b/src/libhelix-aac/assembly.h @@ -500,7 +500,7 @@ static __inline Word64 MADD64(Word64 sum64, int x, int y) return sum64; } -#elif defined(ARDUINO) || defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__)) || (defined (_SOLARIS) && !defined (__GNUC__) && !defined (_SOLARISX86)) +#elif defined(ARDUINO) || defined(ESP32) || defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__)) || (defined (_SOLARIS) && !defined (__GNUC__) && !defined (_SOLARISX86)) typedef long long Word64; diff --git a/src/libhelix-mp3/assembly.h b/src/libhelix-mp3/assembly.h index e444885..a38589a 100644 --- a/src/libhelix-mp3/assembly.h +++ b/src/libhelix-mp3/assembly.h @@ -417,7 +417,7 @@ static __inline Word64 SAR64(Word64 x, int n) return (x >> n); } -#elif defined(ARDUINO) || defined(__APPLE__) || defined(__unix__) +#elif defined(ARDUINO) || defined(ESP32) || defined(__APPLE__) || defined(__unix__) static __inline int FASTABS(int x) { diff --git a/src/utils/Allocator.h b/src/utils/Allocator.h index daba3d2..dfc6065 100644 --- a/src/utils/Allocator.h +++ b/src/utils/Allocator.h @@ -2,9 +2,14 @@ #include #include #include "utils/helix_log.h" -#ifdef ESP32 -# include "Arduino.h" +#if defined(ESP32) +# if defined(ARDUINO) +# include "Arduino.h" +# else +# include "esp_heap_caps.h" +# endif #endif + namespace libhelix { /** @@ -93,8 +98,12 @@ class AllocatorExt : public Allocator { void* do_allocate(size_t size) { void* result = nullptr; if (size == 0) size = 1; -#ifdef ESP32 +#if defined(ESP32) +# if defined(ARDUINO) result = ps_malloc(size); +# else + result = heap_caps_malloc(size, MALLOC_CAP_SPIRAM); +# endif #endif if (result == nullptr) result = malloc(size); if (result == nullptr) { @@ -107,7 +116,7 @@ class AllocatorExt : public Allocator { } }; -#ifdef ESP32 +#if defined(ESP32) && defined(ARDUINO) /** * @brief Memory allocateator which uses ps_malloc to allocate the memory in diff --git a/src/utils/Buffers.h b/src/utils/Buffers.h index cb39527..4310ff1 100644 --- a/src/utils/Buffers.h +++ b/src/utils/Buffers.h @@ -6,7 +6,8 @@ #include "utils/Vector.h" #ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) +# define MIN(a,b) (((a)<(b))?(a):(b)) +# define MAX(a,b) (((a)>(b))?(a):(b)) #endif @@ -214,7 +215,7 @@ class SingleBuffer : public BaseBuffer { int available() override { int result = current_write_pos - current_read_pos; - return max(result, 0); + return MAX(result, 0); } int availableForWrite() override { return max_size - current_write_pos; } @@ -258,7 +259,7 @@ class SingleBuffer : public BaseBuffer { /// If we load values directly into the address we need to set the avialeble /// size size_t setAvailable(size_t available_size) { - size_t result = min(available_size, (size_t) max_size); + size_t result = MIN(available_size, (size_t) max_size); current_read_pos = 0; current_write_pos = result; return result; From d979e3d3c22417441a2c5613f0363e4c2f48326e Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 6 Mar 2025 17:03:49 +0100 Subject: [PATCH 12/30] Buffers: compile error for missing MAX --- src/utils/Buffers.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/Buffers.h b/src/utils/Buffers.h index 4310ff1..a0c37c1 100644 --- a/src/utils/Buffers.h +++ b/src/utils/Buffers.h @@ -7,6 +7,9 @@ #ifndef MIN # define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifndef MAX # define MAX(a,b) (((a)>(b))?(a):(b)) #endif From 6a06e1bca5c219613003d58dc66c915e9064c9dc Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 6 Mar 2025 17:20:39 +0100 Subject: [PATCH 13/30] Cleanup Buffers.h --- src/utils/Buffers.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/utils/Buffers.h b/src/utils/Buffers.h index a0c37c1..842491a 100644 --- a/src/utils/Buffers.h +++ b/src/utils/Buffers.h @@ -22,10 +22,6 @@ namespace libhelix { -// forward declaration -template -class NBuffer; - /** * @brief Shared functionality of all buffers * @ingroup buffers @@ -295,4 +291,4 @@ class SingleBuffer : public BaseBuffer { }; -} // namespace audio_tools +} // ns From 026daf01b390cdf427997251e0d75fb3524be518 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 6 Mar 2025 17:25:25 +0100 Subject: [PATCH 14/30] Rev 0.8.8 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 0f0ad0e..d726861 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=libhelix -version=0.8.7 +version=0.8.8 author=Phil Schatzmann maintainer= https://github.com/pschatzmann sentence=libhelix audio decoder for Arduino From af9091a6032aad12226374a34cbb4de7a83a4f8c Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 7 Mar 2025 19:01:13 +0100 Subject: [PATCH 15/30] idf logging support outside of Arduino --- docs/html/_a_a_c_decoder_helix_8h_source.html | 97 +++--- docs/html/_common_helix_8h_source.html | 286 +++++++++--------- docs/html/_config_helix_8h_source.html | 16 +- docs/html/_m_p3_decoder_helix_8h_source.html | 80 ++--- docs/html/index.html | 4 +- src/AACDecoderHelix.h | 6 +- src/CommonHelix.h | 18 +- src/ConfigHelix.h | 7 +- src/MP3DecoderHelix.h | 8 +- src/utils/Allocator.h | 8 +- src/utils/Buffers.h | 10 +- src/utils/helix_log.h | 20 +- src/utils/helix_log_idf.h | 19 ++ src/utils/helix_log_std.h | 27 ++ 14 files changed, 336 insertions(+), 270 deletions(-) create mode 100644 src/utils/helix_log_idf.h create mode 100644 src/utils/helix_log_std.h diff --git a/docs/html/_a_a_c_decoder_helix_8h_source.html b/docs/html/_a_a_c_decoder_helix_8h_source.html index c924cc3..25ed065 100644 --- a/docs/html/_a_a_c_decoder_helix_8h_source.html +++ b/docs/html/_a_a_c_decoder_helix_8h_source.html @@ -111,7 +111,7 @@
48  _AACFrameInfo audioInfo() { return aacFrameInfo; }
49 
51  virtual void end() override {
-
52  LOG_HELIX(LogLevelHelix::Debug, "end");
+
52  LOGD_HELIX( "end");
53  if (decoder != nullptr) {
54  flush();
55  AACFreeDecoder(decoder);
@@ -162,49 +162,54 @@
103  }
104 
106  int decode() override {
-
107  int processed = 0;
-
108  int available = frame_buffer.available();
-
109  int bytes_left = frame_buffer.available();
-
110  uint8_t *data = frame_buffer.data();
-
111  int rc = AACDecode(decoder, &data, &bytes_left, (short *)pcm_buffer.data());
-
112  if (rc == 0) {
-
113  processed = data - frame_buffer.data();
-
114  // return the decoded result
-
115  _AACFrameInfo info;
-
116  AACGetLastFrameInfo(decoder, &info);
-
117  provideResult(info);
-
118  }
-
119  return processed;
-
120  }
-
121 
-
122  // return the result PCM data
-
123  void provideResult(_AACFrameInfo &info) {
-
124  // increase PCM size if this fails
-
125  int sampleSize = info.bitsPerSample / 8;
-
126  assert(info.outputSamps * sampleSize <= maxPCMSize());
-
127 
-
128  LOG_HELIX(LogLevelHelix::Debug, "==> provideResult: %d samples", info.outputSamps);
-
129  if (info.outputSamps > 0) {
-
130  // provide result
-
131  if (pcmCallback != nullptr) {
-
132  // output via callback
-
133  pcmCallback(info, (short *)pcm_buffer.data(), info.outputSamps,
-
134  p_caller_data);
-
135  } else {
-
136  // output to stream
-
137  if (info.sampRateOut != aacFrameInfo.sampRateOut &&
-
138  infoCallback != nullptr) {
-
139  infoCallback(info, p_caller_ref);
-
140  }
-
141 #if defined(ARDUINO) || defined(HELIX_PRINT)
-
142  out->write((uint8_t *)pcm_buffer.data(), info.outputSamps * sampleSize);
-
143 #endif
-
144  }
-
145  aacFrameInfo = info;
-
146  }
-
147  }
-
148 };
-
149 } // namespace libhelix
+
107  LOGD_HELIX( "decode");
+
108  int processed = 0;
+
109  int available = frame_buffer.available();
+
110  int bytes_left = frame_buffer.available();
+
111  uint8_t *data = frame_buffer.data();
+
112  int rc = AACDecode(decoder, &data, &bytes_left, (short *)pcm_buffer.data());
+
113  if (rc == 0) {
+
114  processed = data - frame_buffer.data();
+
115  // return the decoded result
+
116  _AACFrameInfo info;
+
117  AACGetLastFrameInfo(decoder, &info);
+
118  provideResult(info);
+
119  }
+
120  return processed;
+
121  }
+
122 
+
123  // return the result PCM data
+
124  void provideResult(_AACFrameInfo &info) {
+
125  // increase PCM size if this fails
+
126  int sampleSize = info.bitsPerSample / 8;
+
127  assert(info.outputSamps * sampleSize <= maxPCMSize());
+
128 
+
129  LOGD_HELIX( "==> provideResult: %d samples", info.outputSamps);
+
130  if (info.outputSamps > 0) {
+
131  // provide result
+
132  if (pcmCallback != nullptr) {
+
133  // output via callback
+
134  pcmCallback(info, (short *)pcm_buffer.data(), info.outputSamps,
+
135  p_caller_data);
+
136  } else {
+
137  // output to stream
+
138  if (info.sampRateOut != aacFrameInfo.sampRateOut &&
+
139  infoCallback != nullptr) {
+
140  infoCallback(info, p_caller_ref);
+
141  }
+
142 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
143  if (out != nullptr){
+
144  size_t to_write = info.outputSamps * sampleSize;
+
145  size_t written = out->write((uint8_t *)pcm_buffer.data(), to_write);
+
146  assert(written == to_write);
+
147  }
+
148 #endif
+
149  }
+
150  aacFrameInfo = info;
+
151  }
+
152  }
+
153 };
+
154 } // namespace libhelix
A simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() call...
Definition: AACDecoderHelix.h:19
_AACFrameInfo audioInfo()
Provides the last available _AACFrameInfo_t.
Definition: AACDecoderHelix.h:48
size_t maxPCMSize() override
Definition: AACDecoderHelix.h:66
@@ -215,9 +220,9 @@
size_t maxFrameSize() override
Definition: AACDecoderHelix.h:62
int findSynchWord(int offset=0) override
finds the sync word in the buffer
Definition: AACDecoderHelix.h:97
Common Simple Arduino API.
Definition: CommonHelix.h:33
-
void flush()
Decode all open packets.
Definition: CommonHelix.h:102
+
void flush()
Decode all open packets.
Definition: CommonHelix.h:104
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:63
-
virtual void setMinFrameBufferSize(int size)
Defines the minimum frame buffer size which is required before starting the decoding.
Definition: CommonHelix.h:243
+
virtual void setMinFrameBufferSize(int size)
Defines the minimum frame buffer size which is required before starting the decoding.
Definition: CommonHelix.h:251