blob: 79650fbe8c6cae1c3aded93acc12ae9ffd03159f [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
2 * Copyright (c) 2012 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_
12#define MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_
pbos@webrtc.org788acd12014-12-15 09:41:24 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "common_audio/vad/include/webrtc_vad.h"
Yves Gerey665174f2018-06-19 15:03:05 +020015#include "modules/audio_processing/vad/common.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000016
17namespace webrtc {
18
19class AudioFrame;
20
21class StandaloneVad {
22 public:
23 static StandaloneVad* Create();
24 ~StandaloneVad();
25
26 // Outputs
27 // p: a buffer where probabilities are written to.
28 // length_p: number of elements of |p|.
29 //
30 // return value:
31 // -1: if no audio is stored or VAD returns error.
32 // 0: in success.
33 // In case of error the content of |activity| is unchanged.
34 //
35 // Note that due to a high false-positive (VAD decision is active while the
36 // processed audio is just background noise) rate, stand-alone VAD is used as
37 // a one-sided indicator. The activity probability is 0.5 if the frame is
38 // classified as active, and the probability is 0.01 if the audio is
39 // classified as passive. In this way, when probabilities are combined, the
40 // effect of the stand-alone VAD is neutral if the input is classified as
41 // active.
Peter Kastingdce40cf2015-08-24 14:52:23 -070042 int GetActivity(double* p, size_t length_p);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000043
44 // Expecting 10 ms of 16 kHz audio to be pushed in.
Peter Kastingdce40cf2015-08-24 14:52:23 -070045 int AddAudio(const int16_t* data, size_t length);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000046
47 // Set aggressiveness of VAD, 0 is the least aggressive and 3 is the most
48 // aggressive mode. Returns -1 if the input is less than 0 or larger than 3,
49 // otherwise 0 is returned.
50 int set_mode(int mode);
51 // Get the agressiveness of the current VAD.
52 int mode() const { return mode_; }
53
54 private:
55 explicit StandaloneVad(VadInst* vad);
56
Peter Kastingdce40cf2015-08-24 14:52:23 -070057 static const size_t kMaxNum10msFrames = 3;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000058
59 // TODO(turajs): Is there a way to use scoped-pointer here?
60 VadInst* vad_;
61 int16_t buffer_[kMaxNum10msFrames * kLength10Ms];
Peter Kastingdce40cf2015-08-24 14:52:23 -070062 size_t index_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000063 int mode_;
64};
65
66} // namespace webrtc
67
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020068#endif // MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_