Skip to content

Commit 79b6576

Browse files
committed
IDF as component
1 parent ba5aca4 commit 79b6576

File tree

9 files changed

+29
-13
lines changed

9 files changed

+29
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (DEFINED ESP_PLATFORM)
55
idf_component_register(
66
SRC_DIRS src src/utils src/libhelix-aac src/libhelix-mp3
77
INCLUDE_DIRS src src/utils src/libhelix-aac src/libhelix-mp3
8-
REQUIRES arduino-esp32
8+
# REQUIRES arduino-esp32
99
)
1010

1111
target_compile_options(${COMPONENT_LIB} INTERFACE -Wno-error -Wno-format)

src/CommonHelix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ class CommonHelix {
9292
/// returns true if active
9393
operator bool() { return active; }
9494

95+
#ifdef ARDUINO
9596
/// Provides the timestamp in ms of last write
9697
uint64_t timeOfLastWrite() { return time_last_write; }
9798

9899
/// Provides the timestamp in ms of last decoded result
99100
uint64_t timeOfLastResult() { return time_last_result; }
101+
#endif
100102

101103
/// Decode all open packets
102104
void flush() {
@@ -212,7 +214,9 @@ class CommonHelix {
212214
/// Decoding Loop: We decode the procided data until we run out of data
213215
virtual size_t writeChunk(const void *in_ptr, size_t in_size) {
214216
LOG_HELIX(LogLevelHelix::Info, "writeChunk %zu", in_size);
217+
#ifdef ARDUINO
215218
time_last_write = millis();
219+
#endif
216220
size_t result = frame_buffer.writeArray((uint8_t *)in_ptr, in_size);
217221

218222
while (frame_buffer.available() >= minFrameBufferSize()) {

src/MP3DecoderHelix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class MP3DecoderHelix : public CommonHelix {
113113
int processed = 0;
114114
int available = frame_buffer.available();
115115
int bytes_left = frame_buffer.available();
116-
LOG_HELIX(LogLevelHelix::Info, "decode: %d", frame_buffer.available());
116+
LOG_HELIX(LogLevelHelix::Info, "decode: %d (left:%d)", available, bytes_left);
117117
uint8_t *data = frame_buffer.data();
118118
int rc = MP3Decode(decoder, &data, &bytes_left, (short *)pcm_buffer.data(),
119119
mp3_type);

src/libhelix-aac/aaccommon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
# define AAC_ENABLE_SBR
5757
#endif // HELIX_FEATURE_AUDIO_CODEC_AAC_SBR.
5858

59+
#ifndef ARDUINO
5960
#pragma GCC optimize ("O3")
60-
61+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
62+
#endif
6163
#include "aacdec.h"
6264
#include "statname.h"
6365

src/libhelix-aac/aacdec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#
6969
#elif defined(_SOLARIS) && !defined(__GNUC__)
7070
#
71-
#elif defined(ARDUINO)
71+
#elif defined(ARDUINO) || defined(ESP32)
7272
#
7373
#else
7474
#error No platform defined. See valid options in aacdec.h

src/libhelix-aac/assembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static __inline Word64 MADD64(Word64 sum64, int x, int y)
500500
return sum64;
501501
}
502502

503-
#elif defined(ARDUINO) || defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__)) || (defined (_SOLARIS) && !defined (__GNUC__) && !defined (_SOLARISX86))
503+
#elif defined(ARDUINO) || defined(ESP32) || defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__)) || (defined (_SOLARIS) && !defined (__GNUC__) && !defined (_SOLARISX86))
504504

505505
typedef long long Word64;
506506

src/libhelix-mp3/assembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static __inline Word64 SAR64(Word64 x, int n)
417417
return (x >> n);
418418
}
419419

420-
#elif defined(ARDUINO) || defined(__APPLE__) || defined(__unix__)
420+
#elif defined(ARDUINO) || defined(ESP32) || defined(__APPLE__) || defined(__unix__)
421421

422422
static __inline int FASTABS(int x)
423423
{

src/utils/Allocator.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include "utils/helix_log.h"
5-
#ifdef ESP32
6-
# include "Arduino.h"
5+
#if defined(ESP32)
6+
# if defined(ARDUINO)
7+
# include "Arduino.h"
8+
# else
9+
# include "esp_heap_caps.h"
10+
# endif
711
#endif
12+
813
namespace libhelix {
914

1015
/**
@@ -93,8 +98,12 @@ class AllocatorExt : public Allocator {
9398
void* do_allocate(size_t size) {
9499
void* result = nullptr;
95100
if (size == 0) size = 1;
96-
#ifdef ESP32
101+
#if defined(ESP32)
102+
# if defined(ARDUINO)
97103
result = ps_malloc(size);
104+
# else
105+
result = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
106+
# endif
98107
#endif
99108
if (result == nullptr) result = malloc(size);
100109
if (result == nullptr) {
@@ -107,7 +116,7 @@ class AllocatorExt : public Allocator {
107116
}
108117
};
109118

110-
#ifdef ESP32
119+
#if defined(ESP32) && defined(ARDUINO)
111120

112121
/**
113122
* @brief Memory allocateator which uses ps_malloc to allocate the memory in

src/utils/Buffers.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "utils/Vector.h"
77

88
#ifndef MIN
9-
#define MIN(a,b) ((a) < (b) ? (a) : (b))
9+
# define MIN(a,b) (((a)<(b))?(a):(b))
10+
# define MAX(a,b) (((a)>(b))?(a):(b))
1011
#endif
1112

1213

@@ -214,7 +215,7 @@ class SingleBuffer : public BaseBuffer<T> {
214215

215216
int available() override {
216217
int result = current_write_pos - current_read_pos;
217-
return max(result, 0);
218+
return MAX(result, 0);
218219
}
219220

220221
int availableForWrite() override { return max_size - current_write_pos; }
@@ -258,7 +259,7 @@ class SingleBuffer : public BaseBuffer<T> {
258259
/// If we load values directly into the address we need to set the avialeble
259260
/// size
260261
size_t setAvailable(size_t available_size) {
261-
size_t result = min(available_size, (size_t) max_size);
262+
size_t result = MIN(available_size, (size_t) max_size);
262263
current_read_pos = 0;
263264
current_write_pos = result;
264265
return result;

0 commit comments

Comments
 (0)