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:
parent
cc9192a1e7
commit
727fb305a8
1 changed files with 10 additions and 4 deletions
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue