Add audio::record helper function

This commit is contained in:
Nikita Lisitsa 2023-01-11 15:23:22 +03:00
parent a279fbfcb8
commit 5e93208fcb
2 changed files with 19 additions and 0 deletions

View file

@ -1,7 +1,9 @@
#pragma once
#include <psemek/audio/stream.hpp>
#include <psemek/audio/track.hpp>
#include <psemek/audio/channel.hpp>
#include <psemek/audio/duration.hpp>
#include <psemek/util/span.hpp>
#include <vector>
@ -25,4 +27,7 @@ namespace psemek::audio
std::shared_ptr<recorder> make_recorder();
std::shared_ptr<recorder> make_recorder(stream_ptr stream);
std::shared_ptr<track> record(stream_ptr stream);
std::shared_ptr<track> record(stream_ptr stream, duration duration);
}

View file

@ -75,4 +75,18 @@ namespace psemek::audio
return recorder;
}
std::shared_ptr<track> record(stream_ptr stream)
{
if (!stream->length())
throw std::runtime_error("cannot record an infinite stream");
return record(stream, *stream->length());
}
std::shared_ptr<track> record(stream_ptr stream, duration duration)
{
auto recorder = make_recorder(std::move(stream));
recorder->request(duration.samples());
return load_raw(recorder->grab_buffer());
}
}