From 4c77950e702a329f3136456a932efbea36e03d42 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 19 Apr 2023 16:45:50 +1000 Subject: Pipeline working and outputting correctly, but noisy --- src/audio/stream_info.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/audio/stream_info.cpp (limited to 'src/audio/stream_info.cpp') diff --git a/src/audio/stream_info.cpp b/src/audio/stream_info.cpp new file mode 100644 index 00000000..7d833d25 --- /dev/null +++ b/src/audio/stream_info.cpp @@ -0,0 +1,70 @@ +#include "stream_info.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include "result.hpp" +#include "span.hpp" +#include "types.hpp" + +namespace audio { + +void InputStream::consume(std::size_t bytes) const { + assert(raw_->info->bytes_in_stream >= bytes); + auto new_data = raw_->data.subspan(bytes); + std::move(new_data.begin(), new_data.end(), raw_->data.begin()); + raw_->info->bytes_in_stream = new_data.size_bytes(); +} + +void InputStream::mark_incomplete() const { + raw_->is_incomplete = true; +} + +const StreamInfo& InputStream::info() const { + return *raw_->info; +} + +cpp::span InputStream::data() const { + return raw_->data.first(raw_->info->bytes_in_stream); +} + +void OutputStream::add(std::size_t bytes) const { + assert(raw_->info->bytes_in_stream + bytes <= raw_->data.size_bytes()); + raw_->info->bytes_in_stream += bytes; +} + +bool OutputStream::prepare(const StreamInfo::Format& new_format) { + if (std::holds_alternative(raw_->info->format)) { + raw_->info->format = new_format; + raw_->info->bytes_in_stream = 0; + return true; + } + if (new_format == raw_->info->format) { + return true; + } + if (raw_->is_incomplete) { + raw_->info->format = new_format; + raw_->info->bytes_in_stream = 0; + return true; + } + return false; +} + +const StreamInfo& OutputStream::info() const { + return *raw_->info; +} + +cpp::span OutputStream::data() const { + return raw_->data.subspan(raw_->info->bytes_in_stream); +} + +bool OutputStream::is_incomplete() const { + return raw_->is_incomplete; +} + +} // namespace audio -- cgit v1.2.3