diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-11-17 20:29:38 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-15 00:21:00 -0700 |
commit | 727fb305a82ffada6cb69f3f7cc38407e3256279 (patch) | |
tree | 53c3ce159c283b7964c38005e248934f3ff56a0c /Userland/Libraries | |
parent | cc9192a1e729bd9adf2c3daf93f4b709a582e3a0 (diff) | |
download | serenity-727fb305a82ffada6cb69f3f7cc38407e3256279.zip |
LibAudio: Allow resampling into existing buffer
This alleviates some copying
and we can implement existing APIs in terms of this.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibAudio/Resampler.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibAudio/Resampler.h b/Userland/Libraries/LibAudio/Resampler.h index 9c4d04db91..86799d9197 100644 --- a/Userland/Libraries/LibAudio/Resampler.h +++ b/Userland/Libraries/LibAudio/Resampler.h @@ -55,15 +55,21 @@ public: ErrorOr<Vector<SampleType>> try_resample(Samples&& to_resample) { Vector<SampleType> resampled; - TRY(resampled.try_ensure_capacity(to_resample.size() * ceil_div(m_source, m_target))); + TRY(try_resample_into_end(resampled, forward<Samples>(to_resample))); + return resampled; + } + + template<ArrayLike<SampleType> Samples, size_t vector_inline_capacity = 0> + ErrorOr<void> try_resample_into_end(Vector<SampleType, vector_inline_capacity>& destination, Samples&& to_resample) + { + TRY(destination.try_ensure_capacity(destination.size() + to_resample.size() * ceil_div(m_source, m_target))); for (auto sample : to_resample) { process_sample(sample, sample); while (read_sample(sample, sample)) - resampled.unchecked_append(sample); + destination.unchecked_append(sample); } - - return resampled; + return {}; } template<ArrayLike<SampleType> Samples> |