webrtc_m130/webrtc/modules/audio_processing/vad/standalone_vad_unittest.cc
Henrik Kjellander ff761fba82 modules: more interface -> include renames
This changes the following module directories:
* webrtc/modules/audio_conference_mixer/interface
* webrtc/modules/interface
* webrtc/modules/media_file/interface
* webrtc/modules/rtp_rtcp/interface
* webrtc/modules/utility/interface

To avoid breaking downstream, I followed this recipe:
1. Copy the interface dir to a new sibling directory: include
2. Update the header guards in the include directory to match the style guide.
3. Update the header guards in the interface directory to match the ones in include. This is required to avoid getting redefinitions in the not-yet-updated downstream code.
4. Add a pragma warning in the header files in the interface dir. Example:
#pragma message("WARNING: webrtc/modules/interface is DEPRECATED; "
                "use webrtc/modules/include")
5. Search for all source references to webrtc/modules/interface and update them to webrtc/modules/include (*.c*,*.h,*.mm,*.S)
6. Update all GYP+GN files. This required manual inspection since many subdirectories of webrtc/modules referenced the interface dir using ../interface etc(*.gyp*,*.gn*)

BUG=5095
TESTED=Passing compile-trybots with --clobber flag:
git cl try --clobber --bot=win_compile_rel --bot=linux_compile_rel --bot=android_compile_rel --bot=mac_compile_rel --bot=ios_rel -m tryserver.webrtc

R=stefan@webrtc.org, tommi@webrtc.org

Review URL: https://codereview.webrtc.org/1417683006 .

Cr-Commit-Position: refs/heads/master@{#10500}
2015-11-04 07:32:04 +00:00

105 lines
3.4 KiB
C++

/*
* 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 "webrtc/modules/audio_processing/vad/standalone_vad.h"
#include <string.h>
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/include/module_common_types.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/gtest_disable.h"
namespace webrtc {
TEST(StandaloneVadTest, Api) {
rtc::scoped_ptr<StandaloneVad> vad(StandaloneVad::Create());
int16_t data[kLength10Ms] = {0};
// Valid frame length (for 32 kHz rate), but not what the VAD is expecting.
EXPECT_EQ(-1, vad->AddAudio(data, 320));
const size_t kMaxNumFrames = 3;
double p[kMaxNumFrames];
for (size_t n = 0; n < kMaxNumFrames; n++)
EXPECT_EQ(0, vad->AddAudio(data, kLength10Ms));
// Pretend |p| is shorter that it should be.
EXPECT_EQ(-1, vad->GetActivity(p, kMaxNumFrames - 1));
EXPECT_EQ(0, vad->GetActivity(p, kMaxNumFrames));
// Ask for activity when buffer is empty.
EXPECT_EQ(-1, vad->GetActivity(p, kMaxNumFrames));
// Should reset and result in one buffer.
for (size_t n = 0; n < kMaxNumFrames + 1; n++)
EXPECT_EQ(0, vad->AddAudio(data, kLength10Ms));
EXPECT_EQ(0, vad->GetActivity(p, 1));
// Wrong modes
EXPECT_EQ(-1, vad->set_mode(-1));
EXPECT_EQ(-1, vad->set_mode(4));
// Valid mode.
const int kMode = 2;
EXPECT_EQ(0, vad->set_mode(kMode));
EXPECT_EQ(kMode, vad->mode());
}
TEST(StandaloneVadTest, DISABLED_ON_IOS(ActivityDetection)) {
rtc::scoped_ptr<StandaloneVad> vad(StandaloneVad::Create());
const size_t kDataLength = kLength10Ms;
int16_t data[kDataLength] = {0};
FILE* pcm_file =
fopen(test::ResourcePath("audio_processing/agc/agc_audio", "pcm").c_str(),
"rb");
ASSERT_TRUE(pcm_file != NULL);
FILE* reference_file = fopen(
test::ResourcePath("audio_processing/agc/agc_vad", "dat").c_str(), "rb");
ASSERT_TRUE(reference_file != NULL);
// Reference activities are prepared with 0 aggressiveness.
ASSERT_EQ(0, vad->set_mode(0));
// Stand-alone VAD can operate on 1, 2 or 3 frames of length 10 ms. The
// reference file is created for 30 ms frame.
const int kNumVadFramesToProcess = 3;
int num_frames = 0;
while (fread(data, sizeof(int16_t), kDataLength, pcm_file) == kDataLength) {
vad->AddAudio(data, kDataLength);
num_frames++;
if (num_frames == kNumVadFramesToProcess) {
num_frames = 0;
int referece_activity;
double p[kNumVadFramesToProcess];
EXPECT_EQ(1u, fread(&referece_activity, sizeof(referece_activity), 1,
reference_file));
int activity = vad->GetActivity(p, kNumVadFramesToProcess);
EXPECT_EQ(referece_activity, activity);
if (activity != 0) {
// When active, probabilities are set to 0.5.
for (int n = 0; n < kNumVadFramesToProcess; n++)
EXPECT_EQ(0.5, p[n]);
} else {
// When inactive, probabilities are set to 0.01.
for (int n = 0; n < kNumVadFramesToProcess; n++)
EXPECT_EQ(0.01, p[n]);
}
}
}
fclose(reference_file);
fclose(pcm_file);
}
} // namespace webrtc