pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_ |
| 13 | |
aluebs | ecf6b81 | 2015-06-25 12:28:48 -0700 | [diff] [blame] | 14 | #include "webrtc/modules/audio_processing/vad/common.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 15 | #include "webrtc/common_audio/vad/include/webrtc_vad.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class AudioFrame; |
| 21 | |
| 22 | class StandaloneVad { |
| 23 | public: |
| 24 | static StandaloneVad* Create(); |
| 25 | ~StandaloneVad(); |
| 26 | |
| 27 | // Outputs |
| 28 | // p: a buffer where probabilities are written to. |
| 29 | // length_p: number of elements of |p|. |
| 30 | // |
| 31 | // return value: |
| 32 | // -1: if no audio is stored or VAD returns error. |
| 33 | // 0: in success. |
| 34 | // In case of error the content of |activity| is unchanged. |
| 35 | // |
| 36 | // Note that due to a high false-positive (VAD decision is active while the |
| 37 | // processed audio is just background noise) rate, stand-alone VAD is used as |
| 38 | // a one-sided indicator. The activity probability is 0.5 if the frame is |
| 39 | // classified as active, and the probability is 0.01 if the audio is |
| 40 | // classified as passive. In this way, when probabilities are combined, the |
| 41 | // effect of the stand-alone VAD is neutral if the input is classified as |
| 42 | // active. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 43 | int GetActivity(double* p, size_t length_p); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 44 | |
| 45 | // Expecting 10 ms of 16 kHz audio to be pushed in. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 46 | int AddAudio(const int16_t* data, size_t length); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 47 | |
| 48 | // Set aggressiveness of VAD, 0 is the least aggressive and 3 is the most |
| 49 | // aggressive mode. Returns -1 if the input is less than 0 or larger than 3, |
| 50 | // otherwise 0 is returned. |
| 51 | int set_mode(int mode); |
| 52 | // Get the agressiveness of the current VAD. |
| 53 | int mode() const { return mode_; } |
| 54 | |
| 55 | private: |
| 56 | explicit StandaloneVad(VadInst* vad); |
| 57 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 58 | static const size_t kMaxNum10msFrames = 3; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 59 | |
| 60 | // TODO(turajs): Is there a way to use scoped-pointer here? |
| 61 | VadInst* vad_; |
| 62 | int16_t buffer_[kMaxNum10msFrames * kLength10Ms]; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 63 | size_t index_; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 64 | int mode_; |
| 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_ |