summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/api/audio/test
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/api/audio/test')
-rw-r--r--third_party/libwebrtc/api/audio/test/BUILD.gn30
-rw-r--r--third_party/libwebrtc/api/audio/test/audio_frame_unittest.cc136
-rw-r--r--third_party/libwebrtc/api/audio/test/echo_canceller3_config_json_unittest.cc93
-rw-r--r--third_party/libwebrtc/api/audio/test/echo_canceller3_config_unittest.cc46
4 files changed, 305 insertions, 0 deletions
diff --git a/third_party/libwebrtc/api/audio/test/BUILD.gn b/third_party/libwebrtc/api/audio/test/BUILD.gn
new file mode 100644
index 0000000000..dfe8c32f80
--- /dev/null
+++ b/third_party/libwebrtc/api/audio/test/BUILD.gn
@@ -0,0 +1,30 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../../webrtc.gni")
+if (is_android) {
+ import("//build/config/android/config.gni")
+ import("//build/config/android/rules.gni")
+}
+
+if (rtc_include_tests) {
+ rtc_library("audio_api_unittests") {
+ testonly = true
+ sources = [
+ "audio_frame_unittest.cc",
+ "echo_canceller3_config_json_unittest.cc",
+ "echo_canceller3_config_unittest.cc",
+ ]
+ deps = [
+ "..:aec3_config",
+ "..:aec3_config_json",
+ "..:audio_frame_api",
+ "../../../test:test_support",
+ ]
+ }
+}
diff --git a/third_party/libwebrtc/api/audio/test/audio_frame_unittest.cc b/third_party/libwebrtc/api/audio/test/audio_frame_unittest.cc
new file mode 100644
index 0000000000..dbf45ceabc
--- /dev/null
+++ b/third_party/libwebrtc/api/audio/test/audio_frame_unittest.cc
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2018 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "api/audio/audio_frame.h"
+
+#include <stdint.h>
+#include <string.h> // memcmp
+
+#include "test/gtest.h"
+
+namespace webrtc {
+
+namespace {
+
+bool AllSamplesAre(int16_t sample, const AudioFrame& frame) {
+ const int16_t* frame_data = frame.data();
+ for (size_t i = 0; i < frame.max_16bit_samples(); i++) {
+ if (frame_data[i] != sample) {
+ return false;
+ }
+ }
+ return true;
+}
+
+constexpr uint32_t kTimestamp = 27;
+constexpr int kSampleRateHz = 16000;
+constexpr size_t kNumChannelsMono = 1;
+constexpr size_t kNumChannelsStereo = 2;
+constexpr size_t kNumChannels5_1 = 6;
+constexpr size_t kSamplesPerChannel = kSampleRateHz / 100;
+
+} // namespace
+
+TEST(AudioFrameTest, FrameStartsMuted) {
+ AudioFrame frame;
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, UnmutedFrameIsInitiallyZeroed) {
+ AudioFrame frame;
+ frame.mutable_data();
+ EXPECT_FALSE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, MutedFrameBufferIsZeroed) {
+ AudioFrame frame;
+ int16_t* frame_data = frame.mutable_data();
+ for (size_t i = 0; i < frame.max_16bit_samples(); i++) {
+ frame_data[i] = 17;
+ }
+ ASSERT_TRUE(AllSamplesAre(17, frame));
+ frame.Mute();
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, UpdateFrameMono) {
+ AudioFrame frame;
+ int16_t samples[kNumChannelsMono * kSamplesPerChannel] = {17};
+ frame.UpdateFrame(kTimestamp, samples, kSamplesPerChannel, kSampleRateHz,
+ AudioFrame::kPLC, AudioFrame::kVadActive, kNumChannelsMono);
+
+ EXPECT_EQ(kTimestamp, frame.timestamp_);
+ EXPECT_EQ(kSamplesPerChannel, frame.samples_per_channel());
+ EXPECT_EQ(kSampleRateHz, frame.sample_rate_hz());
+ EXPECT_EQ(AudioFrame::kPLC, frame.speech_type_);
+ EXPECT_EQ(AudioFrame::kVadActive, frame.vad_activity_);
+ EXPECT_EQ(kNumChannelsMono, frame.num_channels());
+ EXPECT_EQ(CHANNEL_LAYOUT_MONO, frame.channel_layout());
+
+ EXPECT_FALSE(frame.muted());
+ EXPECT_EQ(0, memcmp(samples, frame.data(), sizeof(samples)));
+
+ frame.UpdateFrame(kTimestamp, nullptr /* data*/, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannelsMono);
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, UpdateFrameMultiChannel) {
+ AudioFrame frame;
+ frame.UpdateFrame(kTimestamp, nullptr /* data */, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannelsStereo);
+ EXPECT_EQ(kSamplesPerChannel, frame.samples_per_channel());
+ EXPECT_EQ(kNumChannelsStereo, frame.num_channels());
+ EXPECT_EQ(CHANNEL_LAYOUT_STEREO, frame.channel_layout());
+
+ frame.UpdateFrame(kTimestamp, nullptr /* data */, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannels5_1);
+ EXPECT_EQ(kSamplesPerChannel, frame.samples_per_channel());
+ EXPECT_EQ(kNumChannels5_1, frame.num_channels());
+ EXPECT_EQ(CHANNEL_LAYOUT_5_1, frame.channel_layout());
+}
+
+TEST(AudioFrameTest, CopyFrom) {
+ AudioFrame frame1;
+ AudioFrame frame2;
+
+ int16_t samples[kNumChannelsMono * kSamplesPerChannel] = {17};
+ frame2.UpdateFrame(kTimestamp, samples, kSamplesPerChannel, kSampleRateHz,
+ AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannelsMono);
+ frame1.CopyFrom(frame2);
+
+ EXPECT_EQ(frame2.timestamp_, frame1.timestamp_);
+ EXPECT_EQ(frame2.samples_per_channel_, frame1.samples_per_channel_);
+ EXPECT_EQ(frame2.sample_rate_hz_, frame1.sample_rate_hz_);
+ EXPECT_EQ(frame2.speech_type_, frame1.speech_type_);
+ EXPECT_EQ(frame2.vad_activity_, frame1.vad_activity_);
+ EXPECT_EQ(frame2.num_channels_, frame1.num_channels_);
+
+ EXPECT_EQ(frame2.muted(), frame1.muted());
+ EXPECT_EQ(0, memcmp(frame2.data(), frame1.data(), sizeof(samples)));
+
+ frame2.UpdateFrame(kTimestamp, nullptr /* data */, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannelsMono);
+ frame1.CopyFrom(frame2);
+
+ EXPECT_EQ(frame2.muted(), frame1.muted());
+ EXPECT_EQ(0, memcmp(frame2.data(), frame1.data(), sizeof(samples)));
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/api/audio/test/echo_canceller3_config_json_unittest.cc b/third_party/libwebrtc/api/audio/test/echo_canceller3_config_json_unittest.cc
new file mode 100644
index 0000000000..4146dda9fe
--- /dev/null
+++ b/third_party/libwebrtc/api/audio/test/echo_canceller3_config_json_unittest.cc
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2018 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "api/audio/echo_canceller3_config_json.h"
+
+#include "api/audio/echo_canceller3_config.h"
+#include "test/gtest.h"
+
+namespace webrtc {
+
+TEST(EchoCanceller3JsonHelpers, ToStringAndParseJson) {
+ EchoCanceller3Config cfg;
+ cfg.delay.down_sampling_factor = 1u;
+ cfg.delay.log_warning_on_delay_changes = true;
+ cfg.filter.refined.error_floor = 2.f;
+ cfg.filter.coarse_initial.length_blocks = 3u;
+ cfg.filter.high_pass_filter_echo_reference =
+ !cfg.filter.high_pass_filter_echo_reference;
+ cfg.comfort_noise.noise_floor_dbfs = 100.f;
+ cfg.echo_model.model_reverb_in_nonlinear_mode = false;
+ cfg.suppressor.normal_tuning.mask_hf.enr_suppress = .5f;
+ cfg.suppressor.subband_nearend_detection.nearend_average_blocks = 3;
+ cfg.suppressor.subband_nearend_detection.subband1 = {1, 3};
+ cfg.suppressor.subband_nearend_detection.subband1 = {4, 5};
+ cfg.suppressor.subband_nearend_detection.nearend_threshold = 2.f;
+ cfg.suppressor.subband_nearend_detection.snr_threshold = 100.f;
+ cfg.multi_channel.detect_stereo_content =
+ !cfg.multi_channel.detect_stereo_content;
+ cfg.multi_channel.stereo_detection_threshold += 1.0f;
+ cfg.multi_channel.stereo_detection_timeout_threshold_seconds += 1;
+ cfg.multi_channel.stereo_detection_hysteresis_seconds += 1;
+ std::string json_string = Aec3ConfigToJsonString(cfg);
+ EchoCanceller3Config cfg_transformed = Aec3ConfigFromJsonString(json_string);
+
+ // Expect unchanged values to remain default.
+ EXPECT_EQ(cfg.ep_strength.default_len,
+ cfg_transformed.ep_strength.default_len);
+ EXPECT_EQ(cfg.ep_strength.nearend_len,
+ cfg_transformed.ep_strength.nearend_len);
+ EXPECT_EQ(cfg.suppressor.normal_tuning.mask_lf.enr_suppress,
+ cfg_transformed.suppressor.normal_tuning.mask_lf.enr_suppress);
+
+ // Expect changed values to carry through the transformation.
+ EXPECT_EQ(cfg.delay.down_sampling_factor,
+ cfg_transformed.delay.down_sampling_factor);
+ EXPECT_EQ(cfg.delay.log_warning_on_delay_changes,
+ cfg_transformed.delay.log_warning_on_delay_changes);
+ EXPECT_EQ(cfg.filter.coarse_initial.length_blocks,
+ cfg_transformed.filter.coarse_initial.length_blocks);
+ EXPECT_EQ(cfg.filter.refined.error_floor,
+ cfg_transformed.filter.refined.error_floor);
+ EXPECT_EQ(cfg.filter.high_pass_filter_echo_reference,
+ cfg_transformed.filter.high_pass_filter_echo_reference);
+ EXPECT_EQ(cfg.comfort_noise.noise_floor_dbfs,
+ cfg_transformed.comfort_noise.noise_floor_dbfs);
+ EXPECT_EQ(cfg.echo_model.model_reverb_in_nonlinear_mode,
+ cfg_transformed.echo_model.model_reverb_in_nonlinear_mode);
+ EXPECT_EQ(cfg.suppressor.normal_tuning.mask_hf.enr_suppress,
+ cfg_transformed.suppressor.normal_tuning.mask_hf.enr_suppress);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.nearend_average_blocks,
+ cfg_transformed.suppressor.subband_nearend_detection
+ .nearend_average_blocks);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband1.low,
+ cfg_transformed.suppressor.subband_nearend_detection.subband1.low);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband1.high,
+ cfg_transformed.suppressor.subband_nearend_detection.subband1.high);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband2.low,
+ cfg_transformed.suppressor.subband_nearend_detection.subband2.low);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband2.high,
+ cfg_transformed.suppressor.subband_nearend_detection.subband2.high);
+ EXPECT_EQ(
+ cfg.suppressor.subband_nearend_detection.nearend_threshold,
+ cfg_transformed.suppressor.subband_nearend_detection.nearend_threshold);
+ EXPECT_EQ(cfg.suppressor.subband_nearend_detection.snr_threshold,
+ cfg_transformed.suppressor.subband_nearend_detection.snr_threshold);
+ EXPECT_EQ(cfg.multi_channel.detect_stereo_content,
+ cfg_transformed.multi_channel.detect_stereo_content);
+ EXPECT_EQ(cfg.multi_channel.stereo_detection_threshold,
+ cfg_transformed.multi_channel.stereo_detection_threshold);
+ EXPECT_EQ(
+ cfg.multi_channel.stereo_detection_timeout_threshold_seconds,
+ cfg_transformed.multi_channel.stereo_detection_timeout_threshold_seconds);
+ EXPECT_EQ(cfg.multi_channel.stereo_detection_hysteresis_seconds,
+ cfg_transformed.multi_channel.stereo_detection_hysteresis_seconds);
+}
+} // namespace webrtc
diff --git a/third_party/libwebrtc/api/audio/test/echo_canceller3_config_unittest.cc b/third_party/libwebrtc/api/audio/test/echo_canceller3_config_unittest.cc
new file mode 100644
index 0000000000..91312a0f40
--- /dev/null
+++ b/third_party/libwebrtc/api/audio/test/echo_canceller3_config_unittest.cc
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "api/audio/echo_canceller3_config.h"
+
+#include "api/audio/echo_canceller3_config_json.h"
+#include "test/gtest.h"
+
+namespace webrtc {
+
+TEST(EchoCanceller3Config, ValidConfigIsNotModified) {
+ EchoCanceller3Config config;
+ EXPECT_TRUE(EchoCanceller3Config::Validate(&config));
+ EchoCanceller3Config default_config;
+ EXPECT_EQ(Aec3ConfigToJsonString(config),
+ Aec3ConfigToJsonString(default_config));
+}
+
+TEST(EchoCanceller3Config, InvalidConfigIsCorrected) {
+ // Change a parameter and validate.
+ EchoCanceller3Config config;
+ config.echo_model.min_noise_floor_power = -1600000.f;
+ EXPECT_FALSE(EchoCanceller3Config::Validate(&config));
+ EXPECT_GE(config.echo_model.min_noise_floor_power, 0.f);
+ // Verify remaining parameters are unchanged.
+ EchoCanceller3Config default_config;
+ config.echo_model.min_noise_floor_power =
+ default_config.echo_model.min_noise_floor_power;
+ EXPECT_EQ(Aec3ConfigToJsonString(config),
+ Aec3ConfigToJsonString(default_config));
+}
+
+TEST(EchoCanceller3Config, ValidatedConfigsAreValid) {
+ EchoCanceller3Config config;
+ config.delay.down_sampling_factor = 983;
+ EXPECT_FALSE(EchoCanceller3Config::Validate(&config));
+ EXPECT_TRUE(EchoCanceller3Config::Validate(&config));
+}
+} // namespace webrtc