2011-10-28 12:45:58 +00:00
|
|
|
/*
|
2012-01-30 09:39:08 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-10-28 12:45:58 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/vad/vad_unittest.h"
|
2012-01-09 09:54:07 +00:00
|
|
|
|
2011-10-28 12:45:58 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
|
|
|
|
#include "common_audio/vad/include/webrtc_vad.h"
|
|
|
|
|
#include "rtc_base/arraysize.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "test/gtest.h"
|
2011-10-28 12:45:58 +00:00
|
|
|
|
2012-01-09 09:54:07 +00:00
|
|
|
VadTest::VadTest() {}
|
2011-12-20 14:08:34 +00:00
|
|
|
|
2012-01-09 09:54:07 +00:00
|
|
|
void VadTest::SetUp() {}
|
|
|
|
|
|
|
|
|
|
void VadTest::TearDown() {}
|
2011-10-28 12:45:58 +00:00
|
|
|
|
|
|
|
|
// Returns true if the rate and frame length combination is valid.
|
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
|
|
|
bool VadTest::ValidRatesAndFrameLengths(int rate, size_t frame_length) {
|
2011-10-28 12:45:58 +00:00
|
|
|
if (rate == 8000) {
|
|
|
|
|
if (frame_length == 80 || frame_length == 160 || frame_length == 240) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} else if (rate == 16000) {
|
|
|
|
|
if (frame_length == 160 || frame_length == 320 || frame_length == 480) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-10-15 17:46:19 +00:00
|
|
|
} else if (rate == 32000) {
|
2011-10-28 12:45:58 +00:00
|
|
|
if (frame_length == 320 || frame_length == 640 || frame_length == 960) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-10-15 17:46:19 +00:00
|
|
|
} else if (rate == 48000) {
|
|
|
|
|
if (frame_length == 480 || frame_length == 960 || frame_length == 1440) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2011-10-28 12:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 06:25:06 -08:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
2011-10-28 12:45:58 +00:00
|
|
|
|
|
|
|
|
TEST_F(VadTest, ApiTest) {
|
|
|
|
|
// This API test runs through the APIs for all possible valid and invalid
|
|
|
|
|
// combinations.
|
|
|
|
|
|
2015-05-27 07:22:58 +02:00
|
|
|
VadInst* handle = WebRtcVad_Create();
|
2011-10-28 12:45:58 +00:00
|
|
|
int16_t zeros[kMaxFrameLength] = {0};
|
|
|
|
|
|
|
|
|
|
// 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];
|
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 i = 0; i < kMaxFrameLength; i++) {
|
2015-07-22 15:17:22 -07:00
|
|
|
speech[i] = static_cast<int16_t>(i * i);
|
2011-10-28 12:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 07:22:58 +02:00
|
|
|
// nullptr instance tests
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_Init(nullptr));
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_set_mode(nullptr, kModes[0]));
|
|
|
|
|
EXPECT_EQ(-1,
|
|
|
|
|
WebRtcVad_Process(nullptr, kRates[0], speech, kFrameLengths[0]));
|
2011-10-28 12:45:58 +00:00
|
|
|
|
|
|
|
|
// WebRtcVad_Create()
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(handle);
|
2011-10-28 12:45:58 +00:00
|
|
|
|
|
|
|
|
// Not initialized tests
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_Process(handle, kRates[0], speech, kFrameLengths[0]));
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_set_mode(handle, kModes[0]));
|
|
|
|
|
|
|
|
|
|
// WebRtcVad_Init() test
|
|
|
|
|
ASSERT_EQ(0, WebRtcVad_Init(handle));
|
|
|
|
|
|
2012-03-27 11:06:29 +00:00
|
|
|
// WebRtcVad_set_mode() invalid modes tests. Tries smallest supported value
|
|
|
|
|
// minus one and largest supported value plus one.
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_set_mode(
|
|
|
|
|
handle, WebRtcSpl_MinValueW32(kModes, kModesSize) - 1));
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_set_mode(
|
|
|
|
|
handle, WebRtcSpl_MaxValueW32(kModes, kModesSize) + 1));
|
2011-10-28 12:45:58 +00:00
|
|
|
|
|
|
|
|
// WebRtcVad_Process() tests
|
2015-05-27 07:22:58 +02:00
|
|
|
// nullptr as speech pointer
|
|
|
|
|
EXPECT_EQ(-1,
|
|
|
|
|
WebRtcVad_Process(handle, kRates[0], nullptr, kFrameLengths[0]));
|
2011-10-28 12:45:58 +00:00
|
|
|
// Invalid sampling rate
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_Process(handle, 9999, speech, kFrameLengths[0]));
|
|
|
|
|
// All zeros as input should work
|
|
|
|
|
EXPECT_EQ(0, WebRtcVad_Process(handle, kRates[0], zeros, kFrameLengths[0]));
|
|
|
|
|
for (size_t k = 0; k < kModesSize; k++) {
|
|
|
|
|
// Test valid modes
|
|
|
|
|
EXPECT_EQ(0, WebRtcVad_set_mode(handle, kModes[k]));
|
|
|
|
|
// Loop through sampling rate and frame length combinations
|
|
|
|
|
for (size_t i = 0; i < kRatesSize; i++) {
|
|
|
|
|
for (size_t j = 0; j < kFrameLengthsSize; j++) {
|
|
|
|
|
if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) {
|
|
|
|
|
EXPECT_EQ(1, WebRtcVad_Process(handle, kRates[i], speech,
|
|
|
|
|
kFrameLengths[j]));
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_EQ(-1, WebRtcVad_Process(handle, kRates[i], speech,
|
|
|
|
|
kFrameLengths[j]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 04:45:35 +00:00
|
|
|
WebRtcVad_Free(handle);
|
2011-10-28 12:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 08:19:24 +00:00
|
|
|
TEST_F(VadTest, ValidRatesFrameLengths) {
|
|
|
|
|
// This test verifies valid and invalid rate/frame_length combinations. We
|
2012-10-15 17:46:19 +00:00
|
|
|
// loop through some sampling rates and frame lengths from negative values to
|
2012-06-12 08:19:24 +00:00
|
|
|
// values larger than possible.
|
2012-10-15 17:46:19 +00:00
|
|
|
const int kRates[] = {-8000, -4000, 0, 4000, 8000, 8001,
|
|
|
|
|
15999, 16000, 32000, 48000, 48001, 96000};
|
|
|
|
|
|
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 kFrameLengths[] = {0, 80, 81, 159, 160, 240,
|
|
|
|
|
320, 480, 640, 960, 1440, 2000};
|
2012-10-15 17:46:19 +00:00
|
|
|
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
for (size_t i = 0; i < arraysize(kRates); i++) {
|
|
|
|
|
for (size_t j = 0; j < arraysize(kFrameLengths); j++) {
|
2012-10-15 17:46:19 +00:00
|
|
|
if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) {
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
0, WebRtcVad_ValidRateAndFrameLength(kRates[i], kFrameLengths[j]));
|
2012-06-12 08:19:24 +00:00
|
|
|
} else {
|
2012-10-15 17:46:19 +00:00
|
|
|
EXPECT_EQ(
|
|
|
|
|
-1, WebRtcVad_ValidRateAndFrameLength(kRates[i], kFrameLengths[j]));
|
2012-06-12 08:19:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-28 12:45:58 +00:00
|
|
|
// TODO(bjornv): Add a process test, run on file.
|
|
|
|
|
|
2017-03-09 06:25:06 -08:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|