2014-12-15 09:41:24 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-06-25 12:28:48 -07:00
|
|
|
#include "webrtc/modules/audio_processing/vad/standalone_vad.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-06-25 12:28:48 -07:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2015-02-26 14:34:55 +00:00
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
2015-06-10 13:24:48 +02:00
|
|
|
#include "webrtc/test/testsupport/gtest_disable.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
TEST(StandaloneVadTest, Api) {
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<StandaloneVad> vad(StandaloneVad::Create());
|
2015-06-25 12:28:48 -07:00
|
|
|
int16_t data[kLength10Ms] = {0};
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
// Valid frame length (for 32 kHz rate), but not what the VAD is expecting.
|
|
|
|
|
EXPECT_EQ(-1, vad->AddAudio(data, 320));
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t kMaxNumFrames = 3;
|
2014-12-15 09:41:24 +00:00
|
|
|
double p[kMaxNumFrames];
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t n = 0; n < kMaxNumFrames; n++)
|
2014-12-15 09:41:24 +00:00
|
|
|
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.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t n = 0; n < kMaxNumFrames + 1; n++)
|
2014-12-15 09:41:24 +00:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 13:24:48 +02:00
|
|
|
TEST(StandaloneVadTest, DISABLED_ON_IOS(ActivityDetection)) {
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<StandaloneVad> vad(StandaloneVad::Create());
|
2014-12-15 09:41:24 +00:00
|
|
|
const size_t kDataLength = kLength10Ms;
|
2015-06-25 12:28:48 -07:00
|
|
|
int16_t data[kDataLength] = {0};
|
2014-12-15 09:41:24 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2015-06-25 12:28:48 -07:00
|
|
|
} // namespace webrtc
|