summaryrefslogtreecommitdiffstats
path: root/dom/media/gtest/TestAudioBuffers.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/media/gtest/TestAudioBuffers.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/gtest/TestAudioBuffers.cpp')
-rw-r--r--dom/media/gtest/TestAudioBuffers.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/dom/media/gtest/TestAudioBuffers.cpp b/dom/media/gtest/TestAudioBuffers.cpp
new file mode 100644
index 000000000..b03886cec
--- /dev/null
+++ b/dom/media/gtest/TestAudioBuffers.cpp
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdint.h>
+#include "AudioBufferUtils.h"
+#include "gtest/gtest.h"
+
+const uint32_t FRAMES = 256;
+const uint32_t CHANNELS = 2;
+const uint32_t SAMPLES = CHANNELS * FRAMES;
+
+TEST(AudioBuffers, Test)
+{
+ mozilla::AudioCallbackBufferWrapper<float, CHANNELS> mBuffer;
+ mozilla::SpillBuffer<float, 128, CHANNELS> b;
+ float fromCallback[SAMPLES];
+ float other[SAMPLES];
+
+ for (uint32_t i = 0; i < SAMPLES; i++) {
+ other[i] = 1.0;
+ fromCallback[i] = 0.0;
+ }
+
+ // Set the buffer in the wrapper from the callback
+ mBuffer.SetBuffer(fromCallback, FRAMES);
+
+ // Fill the SpillBuffer with data.
+ ASSERT_TRUE(b.Fill(other, 15) == 15);
+ ASSERT_TRUE(b.Fill(other, 17) == 17);
+ for (uint32_t i = 0; i < 32 * CHANNELS; i++) {
+ other[i] = 0.0;
+ }
+
+ // Empty it in the AudioCallbackBufferWrapper
+ ASSERT_TRUE(b.Empty(mBuffer) == 32);
+
+ // Check available return something reasonnable
+ ASSERT_TRUE(mBuffer.Available() == FRAMES - 32);
+
+ // Fill the buffer with the rest of the data
+ mBuffer.WriteFrames(other + 32 * CHANNELS, FRAMES - 32);
+
+ // Check the buffer is now full
+ ASSERT_TRUE(mBuffer.Available() == 0);
+
+ for (uint32_t i = 0 ; i < SAMPLES; i++) {
+ ASSERT_TRUE(fromCallback[i] == 1.0) <<
+ "Difference at " << i << " (" << fromCallback[i] << " != " << 1.0 <<
+ ")\n";
+ }
+
+ ASSERT_TRUE(b.Fill(other, FRAMES) == 128);
+ ASSERT_TRUE(b.Fill(other, FRAMES) == 0);
+ ASSERT_TRUE(b.Empty(mBuffer) == 0);
+}