summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-11-13 17:36:13 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-15 00:21:00 -0700
commit836f28392d9cb5936fa438c2e6305b6c9deeee6a (patch)
treec25e7c10b65a88ba4257826cf442d20b774f0c81 /Userland/Libraries
parent026cc3d4b9876b396e4e656f3752a5c012f0a872 (diff)
downloadserenity-836f28392d9cb5936fa438c2e6305b6c9deeee6a.zip
LibAudio: Make resampling fallible
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibAudio/Resampler.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibAudio/Resampler.h b/Userland/Libraries/LibAudio/Resampler.h
index ed3f49739a..9c4d04db91 100644
--- a/Userland/Libraries/LibAudio/Resampler.h
+++ b/Userland/Libraries/LibAudio/Resampler.h
@@ -52,10 +52,10 @@ public:
}
template<ArrayLike<SampleType> Samples>
- Vector<SampleType> resample(Samples&& to_resample)
+ ErrorOr<Vector<SampleType>> try_resample(Samples&& to_resample)
{
Vector<SampleType> resampled;
- resampled.ensure_capacity(to_resample.size() * ceil_div(m_source, m_target));
+ TRY(resampled.try_ensure_capacity(to_resample.size() * ceil_div(m_source, m_target)));
for (auto sample : to_resample) {
process_sample(sample, sample);
@@ -66,6 +66,12 @@ public:
return resampled;
}
+ template<ArrayLike<SampleType> Samples>
+ Vector<SampleType> resample(Samples&& to_resample)
+ {
+ return MUST(try_resample(forward<Samples>(to_resample)));
+ }
+
void reset()
{
m_current_ratio = 0;