diff --git a/src/audio/chunk.cpp b/src/audio/chunk.cpp index fb7f1354..abc42bc7 100644 --- a/src/audio/chunk.cpp +++ b/src/audio/chunk.cpp @@ -16,7 +16,7 @@ namespace audio { ChunkReader::ChunkReader(std::size_t chunk_size) : raw_working_buffer_(static_cast( - heap_caps_malloc(chunk_size * 1.5, MALLOC_CAP_SPIRAM))), + heap_caps_malloc(chunk_size * 2, MALLOC_CAP_SPIRAM))), working_buffer_(raw_working_buffer_, chunk_size * 1.5) {} ChunkReader::~ChunkReader() { diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index 14176eae..08f39347 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -20,7 +20,7 @@ static const char* kTag = "SRC"; namespace audio { // 32KiB to match the minimum himen region size. -static const std::size_t kChunkSize = 32 * 1024; +static const std::size_t kChunkSize = 24 * 1024; FatfsAudioInput::FatfsAudioInput(std::shared_ptr storage) : IAudioElement(), @@ -88,7 +88,8 @@ auto FatfsAudioInput::Process() -> cpp::result { dest_event->chunk_data.bytes.first(bytes_read); SendOrBufferEvent(std::move(dest_event)); - if (f_eof(¤t_file_)) { + if (bytes_read < kChunkSize || f_eof(¤t_file_)) { + ESP_LOGI(kTag, "closing file"); f_close(¤t_file_); is_file_open_ = false; }