mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:47:45 +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:
parent
262488ea33
commit
5d01db3493
7 changed files with 169 additions and 149 deletions
28
Userland/Libraries/LibAudio/Resampler.cpp
Normal file
28
Userland/Libraries/LibAudio/Resampler.cpp
Normal 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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue