1 /*
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 #ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_
12 #define COMMON_AUDIO_VAD_INCLUDE_VAD_H_
13 
14 #include <memory>
15 
16 #include "common_audio/vad/include/webrtc_vad.h"
17 #include "rtc_base/checks.h"
18 
19 namespace webrtc {
20 
21 class Vad {
22  public:
23   enum Aggressiveness {
24     kVadNormal = 0,
25     kVadLowBitrate = 1,
26     kVadAggressive = 2,
27     kVadVeryAggressive = 3
28   };
29 
30   enum Activity { kPassive = 0, kActive = 1, kError = -1 };
31 
32   virtual ~Vad() = default;
33 
34   // Calculates a VAD decision for the given audio frame. Valid sample rates
35   // are 8000, 16000, and 32000 Hz; the number of samples must be such that the
36   // frame is 10, 20, or 30 ms long.
37   virtual Activity VoiceActivity(const int16_t* audio,
38                                  size_t num_samples,
39                                  int sample_rate_hz) = 0;
40 
41   // Resets VAD state.
42   virtual void Reset() = 0;
43 };
44 
45 // Returns a Vad instance that's implemented on top of WebRtcVad.
46 std::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness);
47 
48 }  // namespace webrtc
49 
50 #endif  // COMMON_AUDIO_VAD_INCLUDE_VAD_H_
51