summaryrefslogtreecommitdiff
path: root/Libraries/LibAudio/ABuffer.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-27 18:17:17 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-27 18:17:17 +0200
commit5e01dde7b1a7ea8723e127c365331f10a9695546 (patch)
tree400e017188a129813ab590e75b43078ebc0a2ca1 /Libraries/LibAudio/ABuffer.h
parentb805f112c21a1e5bae8d66caa1d640ad2d5e6f5f (diff)
downloadserenity-5e01dde7b1a7ea8723e127c365331f10a9695546.zip
Audio: Make ABuffer sit on top of a SharedBuffer.
This allows us to carry the same buffer all the way from the WAV loader to the AudioServer mixer. This alleviates some of the stutter, but there's still a noticeable skip when switching buffers. We're gonna need to do better. :^)
Diffstat (limited to 'Libraries/LibAudio/ABuffer.h')
-rw-r--r--Libraries/LibAudio/ABuffer.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/Libraries/LibAudio/ABuffer.h b/Libraries/LibAudio/ABuffer.h
index 364c84d40a..4aa23520cb 100644
--- a/Libraries/LibAudio/ABuffer.h
+++ b/Libraries/LibAudio/ABuffer.h
@@ -4,6 +4,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Types.h>
#include <AK/Vector.h>
+#include <LibC/SharedBuffer.h>
// A single sample in an audio buffer.
// Values are floating point, and should range from -1.0 to +1.0
@@ -57,17 +58,29 @@ public:
{
return adopt(*new ABuffer(move(samples)));
}
+ static NonnullRefPtr<ABuffer> create_with_shared_buffer(NonnullRefPtr<SharedBuffer>&& buffer)
+ {
+ return adopt(*new ABuffer(move(buffer)));
+ }
- const Vector<ASample>& samples() const { return m_samples; }
- Vector<ASample>& samples() { return m_samples; }
- const void* data() const { return m_samples.data(); }
- int size_in_bytes() const { return m_samples.size() * sizeof(ASample); }
+ const ASample* samples() const { return (const ASample*)data(); }
+ int sample_count() const { return m_buffer->size() / (int)sizeof(ASample); }
+ const void* data() const { return m_buffer->data(); }
+ int size_in_bytes() const { return m_buffer->size(); }
+ int shared_buffer_id() const { return m_buffer->shared_buffer_id(); }
private:
- ABuffer(Vector<ASample>&& samples)
- : m_samples(move(samples))
+ explicit ABuffer(Vector<ASample>&& samples)
+ : m_buffer(*SharedBuffer::create_with_size(samples.size() * sizeof(ASample)))
+ {
+ memcpy(m_buffer->data(), samples.data(), samples.size() * sizeof(ASample));
+ }
+
+ explicit ABuffer(NonnullRefPtr<SharedBuffer>&& buffer)
+ : m_buffer(move(buffer))
{
}
- Vector<ASample> m_samples;
+ NonnullRefPtr<SharedBuffer> m_buffer;
+ int m_sample_count { 0 };
};