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 :^)
This commit is contained in:
kleines Filmröllchen 2022-02-07 23:14:16 +01:00 committed by Andreas Kling
parent 63d9ec8e94
commit 50dc9a7be7
Notes: sideshowbarker 2024-07-17 18:12:52 +09:00

View file

@ -7,6 +7,7 @@
#pragma once
#include "AK/TypedTransfer.h"
#include <AK/ByteBuffer.h>
#include <AK/Error.h>
#include <AK/FixedArray.h>
@ -47,6 +48,14 @@ public:
}
Sample const* samples() const { return (const Sample*)data(); }
ErrorOr<FixedArray<Sample>> to_sample_array() const
{
FixedArray<Sample> samples = TRY(FixedArray<Sample>::try_create(m_sample_count));
AK::TypedTransfer<Sample>::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<void>(); }
int size_in_bytes() const { return m_sample_count * (int)sizeof(Sample); }