Creating a C++ wrapper class for VAD
Also adding a mock. This work is part of an ongoing effort to encapsulate encoders in AudioEncoder classes. The CNG encoder will also be implemented as an AudioEncoder class, and will also contain a VAD C++ wrapper. BUG=3926 R=bjornv@webrtc.org Review URL: https://webrtc-codereview.appspot.com/27839004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7570 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
bcfb4d0403
commit
8aa4d2d2cd
@ -71,7 +71,9 @@ source_set("common_audio") {
|
|||||||
"signal_processing/splitting_filter.c",
|
"signal_processing/splitting_filter.c",
|
||||||
"signal_processing/sqrt_of_one_minus_x_squared.c",
|
"signal_processing/sqrt_of_one_minus_x_squared.c",
|
||||||
"signal_processing/vector_scaling_operations.c",
|
"signal_processing/vector_scaling_operations.c",
|
||||||
|
"vad/include/vad.h",
|
||||||
"vad/include/webrtc_vad.h",
|
"vad/include/webrtc_vad.h",
|
||||||
|
"vad/vad.cc",
|
||||||
"vad/webrtc_vad.c",
|
"vad/webrtc_vad.c",
|
||||||
"vad/vad_core.c",
|
"vad/vad_core.c",
|
||||||
"vad/vad_core.h",
|
"vad/vad_core.h",
|
||||||
|
@ -85,7 +85,9 @@
|
|||||||
'signal_processing/splitting_filter.c',
|
'signal_processing/splitting_filter.c',
|
||||||
'signal_processing/sqrt_of_one_minus_x_squared.c',
|
'signal_processing/sqrt_of_one_minus_x_squared.c',
|
||||||
'signal_processing/vector_scaling_operations.c',
|
'signal_processing/vector_scaling_operations.c',
|
||||||
|
'vad/include/vad.h',
|
||||||
'vad/include/webrtc_vad.h',
|
'vad/include/webrtc_vad.h',
|
||||||
|
'vad/vad.cc',
|
||||||
'vad/webrtc_vad.c',
|
'vad/webrtc_vad.c',
|
||||||
'vad/vad_core.c',
|
'vad/vad_core.c',
|
||||||
'vad/vad_core.h',
|
'vad/vad_core.h',
|
||||||
|
45
webrtc/common_audio/vad/include/vad.h
Normal file
45
webrtc/common_audio/vad/include/vad.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_COMMON_AUDIO_VAD_INCLUDE_VAD_H_
|
||||||
|
#define WEBRTC_COMMON_AUDIO_VAD_INCLUDE_VAD_H_
|
||||||
|
|
||||||
|
#include "webrtc/base/checks.h"
|
||||||
|
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
|
||||||
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// This is a C++ wrapper class for WebRtcVad.
|
||||||
|
class Vad {
|
||||||
|
public:
|
||||||
|
enum Aggressiveness {
|
||||||
|
kVadNormal = 0,
|
||||||
|
kVadLowBitrate = 1,
|
||||||
|
kVadAggressive = 2,
|
||||||
|
kVadVeryAggressive = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Activity { kPassive = 0, kActive = 1, kError = -1 };
|
||||||
|
|
||||||
|
explicit Vad(enum Aggressiveness mode);
|
||||||
|
|
||||||
|
virtual ~Vad();
|
||||||
|
|
||||||
|
enum Activity VoiceActivity(const int16_t* audio,
|
||||||
|
size_t num_samples,
|
||||||
|
int sample_rate_hz);
|
||||||
|
|
||||||
|
private:
|
||||||
|
VadInst* handle_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
#endif // WEBRTC_COMMON_AUDIO_VAD_INCLUDE_VAD_H_
|
34
webrtc/common_audio/vad/mock/mock_vad.h
Normal file
34
webrtc/common_audio/vad/mock/mock_vad.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_
|
||||||
|
#define WEBRTC_COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_
|
||||||
|
|
||||||
|
#include "webrtc/common_audio/vad/include/vad.h"
|
||||||
|
|
||||||
|
#include "testing/gmock/include/gmock/gmock.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
class MockVad : public Vad {
|
||||||
|
public:
|
||||||
|
explicit MockVad(enum Aggressiveness mode) {}
|
||||||
|
virtual ~MockVad() { Die(); }
|
||||||
|
MOCK_METHOD0(Die, void());
|
||||||
|
|
||||||
|
MOCK_METHOD3(VoiceActivity,
|
||||||
|
enum Activity(const int16_t* audio,
|
||||||
|
size_t num_samples,
|
||||||
|
int sample_rate_hz));
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_COMMON_AUDIO_VAD_MOCK_MOCK_VAD_H_
|
43
webrtc/common_audio/vad/vad.cc
Normal file
43
webrtc/common_audio/vad/vad.cc
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 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/common_audio/vad/include/vad.h"
|
||||||
|
|
||||||
|
#include "webrtc/base/checks.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
Vad::Vad(enum Aggressiveness mode) {
|
||||||
|
CHECK_EQ(WebRtcVad_Create(&handle_), 0);
|
||||||
|
CHECK_EQ(WebRtcVad_Init(handle_), 0);
|
||||||
|
CHECK_EQ(WebRtcVad_set_mode(handle_, mode), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vad::~Vad() {
|
||||||
|
WebRtcVad_Free(handle_);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Vad::Activity Vad::VoiceActivity(const int16_t* audio,
|
||||||
|
size_t num_samples,
|
||||||
|
int sample_rate_hz) {
|
||||||
|
int ret = WebRtcVad_Process(
|
||||||
|
handle_, sample_rate_hz, audio, static_cast<int>(num_samples));
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
return kPassive;
|
||||||
|
case 1:
|
||||||
|
return kActive;
|
||||||
|
default:
|
||||||
|
DCHECK(false) << "WebRtcVad_Process returned an error.";
|
||||||
|
return kError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
Loading…
x
Reference in New Issue
Block a user