summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc')
-rw-r--r--third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc b/third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc
new file mode 100644
index 0000000000..51d8d0fefd
--- /dev/null
+++ b/third_party/libwebrtc/common_audio/vad/vad_filterbank_unittest.cc
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2012 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 <stdlib.h>
+
+#include "common_audio/vad/vad_unittest.h"
+#include "test/gtest.h"
+
+extern "C" {
+#include "common_audio/vad/vad_core.h"
+#include "common_audio/vad/vad_filterbank.h"
+}
+
+namespace webrtc {
+namespace test {
+
+const int kNumValidFrameLengths = 3;
+
+TEST_F(VadTest, vad_filterbank) {
+ VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));
+ static const int16_t kReference[kNumValidFrameLengths] = {48, 11, 11};
+ static const int16_t kFeatures[kNumValidFrameLengths * kNumChannels] = {
+ 1213, 759, 587, 462, 434, 272, 1479, 1385, 1291,
+ 1200, 1103, 1099, 1732, 1692, 1681, 1629, 1436, 1436};
+ static const int16_t kOffsetVector[kNumChannels] = {368, 368, 272,
+ 176, 176, 176};
+ int16_t features[kNumChannels];
+
+ // Construct a speech signal that will trigger the VAD in all modes. It is
+ // known that (i * i) will wrap around, but that doesn't matter in this case.
+ int16_t speech[kMaxFrameLength];
+ for (size_t i = 0; i < kMaxFrameLength; ++i) {
+ speech[i] = static_cast<int16_t>(i * i);
+ }
+
+ int frame_length_index = 0;
+ ASSERT_EQ(0, WebRtcVad_InitCore(self));
+ for (size_t j = 0; j < kFrameLengthsSize; ++j) {
+ if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
+ EXPECT_EQ(kReference[frame_length_index],
+ WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
+ features));
+ for (int k = 0; k < kNumChannels; ++k) {
+ EXPECT_EQ(kFeatures[k + frame_length_index * kNumChannels],
+ features[k]);
+ }
+ frame_length_index++;
+ }
+ }
+ EXPECT_EQ(kNumValidFrameLengths, frame_length_index);
+
+ // Verify that all zeros in gives kOffsetVector out.
+ memset(speech, 0, sizeof(speech));
+ ASSERT_EQ(0, WebRtcVad_InitCore(self));
+ for (size_t j = 0; j < kFrameLengthsSize; ++j) {
+ if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
+ EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
+ features));
+ for (int k = 0; k < kNumChannels; ++k) {
+ EXPECT_EQ(kOffsetVector[k], features[k]);
+ }
+ }
+ }
+
+ // Verify that all ones in gives kOffsetVector out. Any other constant input
+ // will have a small impact in the sub bands.
+ for (size_t i = 0; i < kMaxFrameLength; ++i) {
+ speech[i] = 1;
+ }
+ for (size_t j = 0; j < kFrameLengthsSize; ++j) {
+ if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
+ ASSERT_EQ(0, WebRtcVad_InitCore(self));
+ EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
+ features));
+ for (int k = 0; k < kNumChannels; ++k) {
+ EXPECT_EQ(kOffsetVector[k], features[k]);
+ }
+ }
+ }
+
+ free(self);
+}
+} // namespace test
+} // namespace webrtc