diff --git a/libs/audio/include/psemek/audio/recorder.hpp b/libs/audio/include/psemek/audio/recorder.hpp index 10cf9d80..dd9f9a43 100644 --- a/libs/audio/include/psemek/audio/recorder.hpp +++ b/libs/audio/include/psemek/audio/recorder.hpp @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include #include #include @@ -25,4 +27,7 @@ namespace psemek::audio std::shared_ptr make_recorder(); std::shared_ptr make_recorder(stream_ptr stream); + std::shared_ptr record(stream_ptr stream); + std::shared_ptr record(stream_ptr stream, duration duration); + } diff --git a/libs/audio/source/recorder.cpp b/libs/audio/source/recorder.cpp index 87a260a9..90fda08b 100644 --- a/libs/audio/source/recorder.cpp +++ b/libs/audio/source/recorder.cpp @@ -75,4 +75,18 @@ namespace psemek::audio return recorder; } + std::shared_ptr record(stream_ptr stream) + { + if (!stream->length()) + throw std::runtime_error("cannot record an infinite stream"); + return record(stream, *stream->length()); + } + + std::shared_ptr record(stream_ptr stream, duration duration) + { + auto recorder = make_recorder(std::move(stream)); + recorder->request(duration.samples()); + return load_raw(recorder->grab_buffer()); + } + }