From ff811ba810eadbed447acdbf6d5291164d75cd9d Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 14 Apr 2025 02:27:40 -0500 Subject: move SampleProcessor buffers to external RAM This increases CPU usage by ~2% for the audio_conv task, which I think is an acceptable tradeoff. The Speex resampler still makes its own allocations in internal RAM. --- src/tangara/audio/processor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tangara/audio/processor.cpp b/src/tangara/audio/processor.cpp index 2fa7f78e..3126f050 100644 --- a/src/tangara/audio/processor.cpp +++ b/src/tangara/audio/processor.cpp @@ -52,7 +52,7 @@ SampleProcessor::SampleProcessor(drivers::PcmBuffer& sink) : commands_(xQueueCreate(2, sizeof(Args))), source_(xStreamBufferCreateWithCaps(kSourceBufferLength + 1, sizeof(sample::Sample), - MALLOC_CAP_DMA)), + MALLOC_CAP_SPIRAM)), sink_(sink), unprocessed_samples_(0) { tasks::StartPersistent([&]() { Main(); }); @@ -354,7 +354,7 @@ Buffer::Buffer() : storage_(reinterpret_cast( heap_caps_calloc(kSampleBufferLength, sizeof(sample::Sample), - MALLOC_CAP_DMA))), + MALLOC_CAP_SPIRAM))), buffer_(storage_, kSampleBufferLength), samples_in_buffer_() {} -- cgit v1.2.3 From 6e13e2ac6ed10bdd275b47853fb6d1b4b63b4549 Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 14 Apr 2025 02:29:19 -0500 Subject: move some task stacks to external RAM To free up some internal RAM space --- src/tasks/tasks.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tasks/tasks.cpp b/src/tasks/tasks.cpp index f0b567f2..c85b492b 100644 --- a/src/tasks/tasks.cpp +++ b/src/tasks/tasks.cpp @@ -40,8 +40,8 @@ auto AllocateStack() -> std::span; template <> auto AllocateStack() -> std::span { constexpr std::size_t size = 20 * 1024; - static StackType_t sStack[size]; - return {sStack, size}; + return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), + size}; } // LVGL requires only a relatively small stack. Lua's stack is allocated // separately. @@ -55,8 +55,8 @@ template <> // PCM conversion and resampling uses a very small amount of stack. auto AllocateStack() -> std::span { constexpr std::size_t size = 4 * 1024; - static StackType_t sStack[size]; - return {sStack, size}; + return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), + size}; } // Background workers receive huge stacks in PSRAM. This is mostly to faciliate // use of LevelDB from any bg worker; Leveldb is designed for non-embedded use -- cgit v1.2.3 From 544f5db6e0abab76fa03f6f35613b752dd6f4100 Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 14 Apr 2025 02:31:11 -0500 Subject: move audio Decoder buffer to external RAM to save internal RAM space --- src/tangara/audio/audio_decoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tangara/audio/audio_decoder.cpp b/src/tangara/audio/audio_decoder.cpp index fca7e6da..2306e994 100644 --- a/src/tangara/audio/audio_decoder.cpp +++ b/src/tangara/audio/audio_decoder.cpp @@ -70,7 +70,7 @@ Decoder::Decoder(std::shared_ptr processor) ESP_LOGI(kTag, "allocating codec buffer, %u KiB", kCodecBufferLength / 1024); codec_buffer_ = { reinterpret_cast(heap_caps_calloc( - kCodecBufferLength, sizeof(sample::Sample), MALLOC_CAP_DMA)), + kCodecBufferLength, sizeof(sample::Sample), MALLOC_CAP_SPIRAM)), kCodecBufferLength}; } -- cgit v1.2.3