aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_processing/vad/standalone_vad.h
blob: 4017a72c60f4b5d7be2e852019ecb43fddcc5cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *  Copyright (c) 2012 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_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_

#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_processing/vad/common.h"
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
#include "webrtc/typedefs.h"

namespace webrtc {

class AudioFrame;

class StandaloneVad {
 public:
  static StandaloneVad* Create();
  ~StandaloneVad();

  // Outputs
  //   p: a buffer where probabilities are written to.
  //   length_p: number of elements of |p|.
  //
  // return value:
  //    -1: if no audio is stored or VAD returns error.
  //     0: in success.
  // In case of error the content of |activity| is unchanged.
  //
  // Note that due to a high false-positive (VAD decision is active while the
  // processed audio is just background noise) rate, stand-alone VAD is used as
  // a one-sided indicator. The activity probability is 0.5 if the frame is
  // classified as active, and the probability is 0.01 if the audio is
  // classified as passive. In this way, when probabilities are combined, the
  // effect of the stand-alone VAD is neutral if the input is classified as
  // active.
  int GetActivity(double* p, int length_p);

  // Expecting 10 ms of 16 kHz audio to be pushed in.
  int AddAudio(const int16_t* data, int length);

  // Set aggressiveness of VAD, 0 is the least aggressive and 3 is the most
  // aggressive mode. Returns -1 if the input is less than 0 or larger than 3,
  // otherwise 0 is returned.
  int set_mode(int mode);
  // Get the agressiveness of the current VAD.
  int mode() const { return mode_; }

 private:
  explicit StandaloneVad(VadInst* vad);

  static const int kMaxNum10msFrames = 3;

  // TODO(turajs): Is there a way to use scoped-pointer here?
  VadInst* vad_;
  int16_t buffer_[kMaxNum10msFrames * kLength10Ms];
  int index_;
  int mode_;
};

}  // namespace webrtc

#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_STANDALONE_VAD_H_