summaryrefslogtreecommitdiff
path: root/src/audio/fatfs_audio_input.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-01-12 14:28:52 +1100
committerjacqueline <me@jacqueline.id.au>2023-01-12 14:28:52 +1100
commit2056cad0ab7b805f0ed5629b100b50f8ea9e127e (patch)
tree1e8385d48e18551240e9ef9683b8696292f8d760 /src/audio/fatfs_audio_input.cpp
parent01be69eca1fa89c047fc29f5cb0ea8ba0898dad1 (diff)
downloadtangara-fw-2056cad0ab7b805f0ed5629b100b50f8ea9e127e.tar.gz
WIP
Diffstat (limited to 'src/audio/fatfs_audio_input.cpp')
-rw-r--r--src/audio/fatfs_audio_input.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp
index 9e8c5243..bc5be42a 100644
--- a/src/audio/fatfs_audio_input.cpp
+++ b/src/audio/fatfs_audio_input.cpp
@@ -126,25 +126,25 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, AudioProcessingError> {
}
// Now stream data into the output buffer until it's full.
- pending_read_pos_ = file_buffer_read_pos_;
- ChunkWriteResult result = WriteChunksToStream(
- output_buffer_, [&](cpp::span<std::byte> d) { return SendChunk(d); },
- kServiceInterval);
-
- switch (result) {
- case CHUNK_WRITE_TIMEOUT:
- case CHUNK_OUT_OF_DATA:
- // Both of these are fine; SendChunk keeps track of where it's up to
- // internally, so we will pick back up where we left off.
- return {};
- default:
- return cpp::fail(IO_ERROR);
+ while (1) {
+ ChunkWriteResult result = chunk_writer_.WriteChunkToStream(
+ [&](cpp::span<std::byte> d) { return SendChunk(d); }, kServiceInterval);
+
+ switch (result) {
+ case CHUNK_WRITE_OKAY:
+ break;
+ case CHUNK_WRITE_TIMEOUT:
+ case CHUNK_OUT_OF_DATA:
+ // Both of these are fine; we will pick back up where we left off in
+ // the next idle call.
+ return {};
+ default:
+ return cpp::fail(IO_ERROR);
+ }
}
}
auto FatfsAudioInput::SendChunk(cpp::span<std::byte> dest) -> size_t {
- file_buffer_read_pos_ = pending_read_pos_;
-
if (file_buffer_read_pos_ == file_buffer_write_pos_) {
return 0;
}
@@ -159,9 +159,9 @@ auto FatfsAudioInput::SendChunk(cpp::span<std::byte> dest) -> size_t {
cpp::span<std::byte> source(file_buffer_read_pos_, chunk_size);
std::copy(source.begin(), source.end(), dest.begin());
- pending_read_pos_ = file_buffer_read_pos_ + chunk_size;
- if (pending_read_pos_ == file_buffer_.end()) {
- pending_read_pos_ = file_buffer_.begin();
+ file_buffer_read_pos_ = file_buffer_read_pos_ + chunk_size;
+ if (file_buffer_read_pos_ == file_buffer_.end()) {
+ file_buffer_read_pos_ = file_buffer_.begin();
}
return chunk_size;
}