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

LibAudio: Split Buffer.{h, cpp} into three files

The Buffer files had contained both the ResampleHelper and the
sample format utilities. Because the Buffer class (and its file) is
going to be deleted soon, this commit separates those two things into
their own files.
This commit is contained in:
kleines Filmröllchen 2022-01-23 15:21:56 +01:00 committed by Andreas Kling
parent 262488ea33
commit 5d01db3493
7 changed files with 169 additions and 149 deletions

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Resampler.h"
#include "Buffer.h"
#include "Sample.h"
namespace Audio {
ErrorOr<NonnullRefPtr<Buffer>> resample_buffer(ResampleHelper<double>& resampler, Buffer const& to_resample)
{
Vector<Sample> resampled;
resampled.ensure_capacity(to_resample.sample_count() * ceil_div(resampler.source(), resampler.target()));
for (size_t i = 0; i < static_cast<size_t>(to_resample.sample_count()); ++i) {
auto sample = to_resample.samples()[i];
resampler.process_sample(sample.left, sample.right);
while (resampler.read_sample(sample.left, sample.right))
resampled.append(sample);
}
return Buffer::create_with_samples(move(resampled));
}
}