standalone_vad.h 2.3 KB

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