1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 11:24:59 +00:00
serenity/Userland/Libraries/LibAudio/Resampler.cpp
kleines Filmröllchen 5d01db3493 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.
2022-02-26 17:57:55 +01:00

28 lines
828 B
C++

/*
* 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));
}
}