diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-02-07 22:56:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-26 17:57:55 +0100 |
commit | 63d9ec8e94d17faddb9a29288ea68f73aac0c0d7 (patch) | |
tree | dd0832ae490543de6e8e48b05c225ed7922f0c0e /Userland/Libraries/LibAudio | |
parent | 5d01db34937894a938bf42a9d1fcd668417b5298 (diff) | |
download | serenity-63d9ec8e94d17faddb9a29288ea68f73aac0c0d7.zip |
LibAudio: Allow resampling from any array-like type
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r-- | Userland/Libraries/LibAudio/Resampler.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibAudio/Resampler.h b/Userland/Libraries/LibAudio/Resampler.h index 718c9b3ac9..6ff633fb92 100644 --- a/Userland/Libraries/LibAudio/Resampler.h +++ b/Userland/Libraries/LibAudio/Resampler.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/Concepts.h> #include <AK/Types.h> #include <AK/Vector.h> @@ -50,6 +51,21 @@ public: return false; } + template<ArrayLike<SampleType> Samples> + Vector<SampleType> resample(Samples&& to_resample) + { + Vector<SampleType> resampled; + resampled.ensure_capacity(to_resample.size() * ceil_div(m_source, m_target)); + for (auto sample : to_resample) { + process_sample(sample, sample); + + while (read_sample(sample, sample)) + resampled.unchecked_append(sample); + } + + return resampled; + } + void reset() { m_current_ratio = 0; |