From 50dc9a7be771f0b2ac8190dd437162f380e4b8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Mon, 7 Feb 2022 23:14:16 +0100 Subject: [PATCH] LibAudio: Add an array conversion transitional API to Buffer Of course, Buffer is going to be removed very soon, but much of the WavLoader behavior still depends on it. Therefore, this intermediary API will allow adopting the Loader infrastructure without digging too deep into the WavLoader legacy code. That's for later :^) --- Userland/Libraries/LibAudio/Buffer.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibAudio/Buffer.h b/Userland/Libraries/LibAudio/Buffer.h index d69090940f..536d313998 100644 --- a/Userland/Libraries/LibAudio/Buffer.h +++ b/Userland/Libraries/LibAudio/Buffer.h @@ -7,6 +7,7 @@ #pragma once +#include "AK/TypedTransfer.h" #include #include #include @@ -47,6 +48,14 @@ public: } Sample const* samples() const { return (const Sample*)data(); } + + ErrorOr> to_sample_array() const + { + FixedArray samples = TRY(FixedArray::try_create(m_sample_count)); + AK::TypedTransfer::copy(samples.data(), this->samples(), m_sample_count); + return samples; + } + int sample_count() const { return m_sample_count; } void const* data() const { return m_buffer.data(); } int size_in_bytes() const { return m_sample_count * (int)sizeof(Sample); }