From ef8d404b15e6d32506617a95aa3161fbe59ecdaf Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 30 Jan 2023 15:52:54 +1100 Subject: Continue ironing out i2s pipeline still at least one heap corruption issue, plus the i2s write method seems to block forever :/ --- src/audio/chunk.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/audio/chunk.cpp') diff --git a/src/audio/chunk.cpp b/src/audio/chunk.cpp index baf2aba5..fb7f1354 100644 --- a/src/audio/chunk.cpp +++ b/src/audio/chunk.cpp @@ -25,6 +25,7 @@ ChunkReader::~ChunkReader() { auto ChunkReader::HandleNewData(cpp::span data) -> cpp::span { + assert(leftover_bytes_ + data.size() <= working_buffer_.size()); // Copy the new data onto the front for anything that was left over from the // last portion. Note: this could be optimised for the '0 leftover bytes' // case, which technically shouldn't need a copy. @@ -40,10 +41,8 @@ auto ChunkReader::HandleLeftovers(std::size_t bytes_used) -> void { leftover_bytes_ = last_data_in_working_buffer_.size() - bytes_used; if (leftover_bytes_ > 0) { auto data_to_keep = last_data_in_working_buffer_.last(leftover_bytes_); - // Copy backwards, since if more than half of the data was unused then the - // source and destination will overlap. - std::copy_backward(data_to_keep.begin(), data_to_keep.end(), - working_buffer_.begin()); + std::copy(data_to_keep.begin(), data_to_keep.end(), + working_buffer_.begin()); } } -- cgit v1.2.3