fixing reading past eof

custom
jacqueline 2 years ago
parent aae1871999
commit 9eecf78e08
  1. 2
      src/audio/chunk.cpp
  2. 5
      src/audio/fatfs_audio_input.cpp

@ -16,7 +16,7 @@ namespace audio {
ChunkReader::ChunkReader(std::size_t chunk_size) ChunkReader::ChunkReader(std::size_t chunk_size)
: raw_working_buffer_(static_cast<std::byte*>( : raw_working_buffer_(static_cast<std::byte*>(
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) {} working_buffer_(raw_working_buffer_, chunk_size * 1.5) {}
ChunkReader::~ChunkReader() { ChunkReader::~ChunkReader() {

@ -20,7 +20,7 @@ static const char* kTag = "SRC";
namespace audio { namespace audio {
// 32KiB to match the minimum himen region size. // 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<drivers::SdStorage> storage) FatfsAudioInput::FatfsAudioInput(std::shared_ptr<drivers::SdStorage> storage)
: IAudioElement(), : IAudioElement(),
@ -88,7 +88,8 @@ auto FatfsAudioInput::Process() -> cpp::result<void, AudioProcessingError> {
dest_event->chunk_data.bytes.first(bytes_read); dest_event->chunk_data.bytes.first(bytes_read);
SendOrBufferEvent(std::move(dest_event)); SendOrBufferEvent(std::move(dest_event));
if (f_eof(&current_file_)) { if (bytes_read < kChunkSize || f_eof(&current_file_)) {
ESP_LOGI(kTag, "closing file");
f_close(&current_file_); f_close(&current_file_);
is_file_open_ = false; is_file_open_ = false;
} }

Loading…
Cancel
Save