blob: bd10756c99dd4578a0336be32063df3c3433408c [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_
12#define COMMON_AUDIO_VAD_INCLUDE_VAD_H_
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000013
kwiberg91d97562016-02-14 01:10:03 -080014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "common_audio/vad/include/webrtc_vad.h"
17#include "rtc_base/checks.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "typedefs.h" // NOLINT(build/include)
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000019
20namespace webrtc {
21
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000022class Vad {
23 public:
24 enum Aggressiveness {
25 kVadNormal = 0,
26 kVadLowBitrate = 1,
27 kVadAggressive = 2,
28 kVadVeryAggressive = 3
29 };
30
31 enum Activity { kPassive = 0, kActive = 1, kError = -1 };
32
kwiberge9e78962015-09-08 23:04:51 -070033 virtual ~Vad() = default;
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000034
kwiberge9e78962015-09-08 23:04:51 -070035 // Calculates a VAD decision for the given audio frame. Valid sample rates
36 // are 8000, 16000, and 32000 Hz; the number of samples must be such that the
37 // frame is 10, 20, or 30 ms long.
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +000038 virtual Activity VoiceActivity(const int16_t* audio,
39 size_t num_samples,
kwiberge9e78962015-09-08 23:04:51 -070040 int sample_rate_hz) = 0;
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000041
kwiberge9e78962015-09-08 23:04:51 -070042 // Resets VAD state.
43 virtual void Reset() = 0;
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000044};
45
kwiberge9e78962015-09-08 23:04:51 -070046// Returns a Vad instance that's implemented on top of WebRtcVad.
kwiberg91d97562016-02-14 01:10:03 -080047std::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness);
kwiberge9e78962015-09-08 23:04:51 -070048
henrik.lundin@webrtc.org8aa4d2d2014-10-30 13:23:25 +000049} // namespace webrtc
kwiberge9e78962015-09-08 23:04:51 -070050
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#endif // COMMON_AUDIO_VAD_INCLUDE_VAD_H_