blob: 9cc0c19877b00faa55c46fd1117ba4d83c5efefc [file] [log] [blame]
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +00001/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/common_audio/vad/include/vad.h"
12
13#include "webrtc/base/checks.h"
14
15namespace webrtc {
16
17Vad::Vad(enum Aggressiveness mode) {
18 CHECK_EQ(WebRtcVad_Create(&handle_), 0);
19 CHECK_EQ(WebRtcVad_Init(handle_), 0);
20 CHECK_EQ(WebRtcVad_set_mode(handle_, mode), 0);
21}
22
23Vad::~Vad() {
24 WebRtcVad_Free(handle_);
25}
26
27enum Vad::Activity Vad::VoiceActivity(const int16_t* audio,
28 size_t num_samples,
29 int sample_rate_hz) {
30 int ret = WebRtcVad_Process(
31 handle_, sample_rate_hz, audio, static_cast<int>(num_samples));
32 switch (ret) {
33 case 0:
34 return kPassive;
35 case 1:
36 return kActive;
37 default:
38 DCHECK(false) << "WebRtcVad_Process returned an error.";
39 return kError;
40 }
41}
42
43} // namespace webrtc