1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

LibAudio: Allow resampling into existing buffer

This alleviates some copying
and we can implement existing APIs in terms of this.
This commit is contained in:
kleines Filmröllchen 2022-11-17 20:29:38 +01:00 committed by Andrew Kaster
parent cc9192a1e7
commit 727fb305a8

View file

@ -55,15 +55,21 @@ public:
ErrorOr<Vector<SampleType>> try_resample(Samples&& to_resample) ErrorOr<Vector<SampleType>> try_resample(Samples&& to_resample)
{ {
Vector<SampleType> resampled; 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) { for (auto sample : to_resample) {
process_sample(sample, sample); process_sample(sample, sample);
while (read_sample(sample, sample)) while (read_sample(sample, sample))
resampled.unchecked_append(sample); destination.unchecked_append(sample);
} }
return {};
return resampled;
} }
template<ArrayLike<SampleType> Samples> template<ArrayLike<SampleType> Samples>